Skip to content

Commit

Permalink
add missing "type": "commonjs" to DEV-cjs output (#2194)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank99 authored Aug 20, 2024
1 parent 867dc52 commit 8f739ed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-teachers-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

The development build output is now also formatted using `prettier` for easier debugging.
5 changes: 5 additions & 0 deletions .changeset/yellow-glasses-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

Fixed an issue where CommonJS files in the development build output (`DEV-cjs/` directory) were being treated as ESM, inadvertently causing runtime errors during development.
9 changes: 5 additions & 4 deletions packages/itwinui-react/scripts/postBuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
import fs from 'node:fs';
import { execSync } from 'node:child_process';

// This creates a dummy package.json file in the cjs folder.
// This creates a dummy package.json file in the cjs and DEV-cjs folders.
// Without this, all cjs files would need the .cjs extension
// because .js files are treated as ESM according to the main package.json's "type".
try {
fs.writeFileSync('cjs/package.json', '{ "type": "commonjs" }');
fs.writeFileSync('DEV-cjs/package.json', '{ "type": "commonjs" }');
} catch (e) {
console.error('Cannot create cjs/package.json', e);
console.error('Cannot create package.json', e);
}

// Run prettier on all compiled output because it gets jumbled by tsc.
// Run prettier on all compiled output because it gets jumbled by SWC.
try {
execSync(
'npx prettier --write --ignore-path="../../.gitignore" "{esm,cjs}/**/*.js"',
'npx prettier --write --ignore-path="../../.gitignore" "{esm,cjs,DEV-esm,DEV-cjs}/**/*.js"',
);
} catch (error) {
console.error('Error when running prettier', error);
Expand Down

0 comments on commit 8f739ed

Please sign in to comment.