Skip to content

Commit 9822957

Browse files
committed
Fix commonjs build
1 parent 8451c43 commit 9822957

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

design-tokens/src/build-style-dictionary.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ StyleDictionary.extend({
408408
}).buildAllPlatforms();
409409

410410
// create CommonJS index.js
411-
const collections = {};
411+
const collections = [];
412412
fs.readdirSync(CJS_DIR)
413413
.filter(file => file !== 'index.cjs')
414414
.forEach(file => {
@@ -418,10 +418,18 @@ fs.readdirSync(CJS_DIR)
418418
let mode = parts[1];
419419
// special case for base.js and components
420420
if (mode === 'default' || !mode) [mode] = parts;
421-
collections[mode] = `require(./${file})`;
421+
fs.appendFileSync(
422+
`${CJS_DIR}index.cjs`,
423+
`const ${mode} = require('./${file}');\n`,
424+
);
425+
collections.push(mode);
422426
}
423427
});
424-
const output = `module.exports = ${JSON.stringify(collections, null, 2)}`;
425-
fs.writeFileSync(`${CJS_DIR}index.cjs`, output);
428+
429+
const output = `\nmodule.exports = { ${collections.map(
430+
collection => collection,
431+
)} };\n`;
432+
fs.appendFileSync(`${CJS_DIR}index.cjs`, output);
433+
// fs.writeFileSync(`${CJS_DIR}index.cjs`, output);
426434

427435
console.log('✅ CSS, Javascript, and JSON files have been generated.');

0 commit comments

Comments
 (0)