From 8f739ed23f8da66a2610bde602f5a7d0ce3e5505 Mon Sep 17 00:00:00 2001 From: Mayank <9084735+mayank99@users.noreply.github.com> Date: Tue, 20 Aug 2024 16:06:45 -0400 Subject: [PATCH] add missing `"type": "commonjs"` to `DEV-cjs` output (#2194) --- .changeset/early-teachers-bathe.md | 5 +++++ .changeset/yellow-glasses-cover.md | 5 +++++ packages/itwinui-react/scripts/postBuild.mjs | 9 +++++---- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/early-teachers-bathe.md create mode 100644 .changeset/yellow-glasses-cover.md diff --git a/.changeset/early-teachers-bathe.md b/.changeset/early-teachers-bathe.md new file mode 100644 index 00000000000..970a5c50f56 --- /dev/null +++ b/.changeset/early-teachers-bathe.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +The development build output is now also formatted using `prettier` for easier debugging. diff --git a/.changeset/yellow-glasses-cover.md b/.changeset/yellow-glasses-cover.md new file mode 100644 index 00000000000..2256ef0e038 --- /dev/null +++ b/.changeset/yellow-glasses-cover.md @@ -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. diff --git a/packages/itwinui-react/scripts/postBuild.mjs b/packages/itwinui-react/scripts/postBuild.mjs index adc2a09caca..485c51db3dc 100644 --- a/packages/itwinui-react/scripts/postBuild.mjs +++ b/packages/itwinui-react/scripts/postBuild.mjs @@ -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);