Skip to content

Commit c43c98d

Browse files
felixtrzmeta-codesync[bot]
authored andcommitted
fix(starter-assets): truncate CAS filenames to satisfy jsDelivr path limit
Summary: jsDelivr rejects path components >= 100 chars. Truncate the preferred name portion while preserving the file extension so the hash-prefixed filename stays under the limit. Reviewed By: zjm-meta Differential Revision: D96133482 fbshipit-source-id: 3fd0fdcafa7c7349dac80a1ce8d8166af6bd0e6b
1 parent 30f1f14 commit c43c98d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/starter-assets/scripts/build-assets.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@ const casIndex = new Map(); // hash -> relPath
8585
async function writeCasObject(casRoot, bytes, preferredName) {
8686
const hash = sha256(bytes);
8787
if (casIndex.has(hash)) return casIndex.get(hash);
88-
const safeBase = (preferredName || 'asset').replace(/[^A-Za-z0-9._-]/g, '_');
88+
let safeBase = (preferredName || 'asset').replace(/[^A-Za-z0-9._-]/g, '_');
89+
// jsDelivr rejects path components >= 100 chars; hash is 64 + dash = 65
90+
const maxSuffix = 99 - hash.length - 1;
91+
if (safeBase.length > maxSuffix) {
92+
const ext = path.extname(safeBase);
93+
safeBase = safeBase.slice(0, maxSuffix - ext.length) + ext;
94+
}
8995
const relPath = `${hash}-${safeBase}`;
9096
const absPath = path.join(casRoot, relPath);
9197
await ensureDir(path.dirname(absPath));

0 commit comments

Comments
 (0)