diff --git a/.changeset/lemon-kings-type.md b/.changeset/lemon-kings-type.md new file mode 100644 index 00000000000..3e92f301d02 --- /dev/null +++ b/.changeset/lemon-kings-type.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': minor +--- + +Replaced dependency on `tslib` with `@swc/helpers`. This is used mainly by the CommonJS build. diff --git a/.changeset/strange-spiders-count.md b/.changeset/strange-spiders-count.md new file mode 100644 index 00000000000..f54f77e3f77 --- /dev/null +++ b/.changeset/strange-spiders-count.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +The build output is now (again) formatted using `prettier` for easier debugging. diff --git a/.changeset/witty-ties-protect.md b/.changeset/witty-ties-protect.md new file mode 100644 index 00000000000..5fb56a14ac9 --- /dev/null +++ b/.changeset/witty-ties-protect.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +Removed all code comments from the build output. diff --git a/packages/itwinui-react/package.json b/packages/itwinui-react/package.json index 19f4d880f24..d22df89035b 100644 --- a/packages/itwinui-react/package.json +++ b/packages/itwinui-react/package.json @@ -62,9 +62,10 @@ "ux" ], "scripts": { - "build": "pnpm clean:build && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json && pnpm build:styles && pnpm build:post", + "build": "pnpm clean:build && pnpm build:js && pnpm build:styles && pnpm build:types && pnpm build:post", + "build:js": "node ./scripts/build.mjs", + "build:types": "tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && tsc -p tsconfig.react-table.json", "build:styles": "vite build src/styles.js", - "build:watch": "concurrently \"tsc -p tsconfig.cjs.json --watch\" \"tsc -p tsconfig.esm.json --watch\"", "build:post": "node ./scripts/postBuild.mjs", "clean:build": "rimraf esm && rimraf cjs && rimraf react-table.d.ts", "clean:coverage": "rimraf coverage", @@ -85,11 +86,11 @@ "dependencies": { "@floating-ui/react": "^0.26.10", "@itwin/itwinui-illustrations-react": "^2.1.0", + "@swc/helpers": "^0.5.11", "classnames": "^2.3.2", "jotai": "^2.8.0", "react-table": "^7.8.0", - "react-transition-group": "^4.4.5", - "tslib": "^2.6.0" + "react-transition-group": "^4.4.5" }, "devDependencies": { "@swc/cli": "^0.3.12", diff --git a/packages/itwinui-react/scripts/build.mjs b/packages/itwinui-react/scripts/build.mjs new file mode 100644 index 00000000000..23675282950 --- /dev/null +++ b/packages/itwinui-react/scripts/build.mjs @@ -0,0 +1,41 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Bentley Systems, Incorporated. All rights reserved. + * See LICENSE.md in the project root for license terms and full copyright notice. + *--------------------------------------------------------------------------------------------*/ +import { execSync } from 'node:child_process'; + +// https://swc.rs/docs/usage/cli +const swcOptions = { + shared: [ + '--strip-leading-paths', + '--no-swcrc', + '--ignore **/*.test.*,**/styles.js/*,**/styles*', + ].join(' '), + + // https://swc.rs/docs/configuration/compilation + compilerOptions: [ + '', + 'jsc.parser.syntax=typescript', + 'jsc.parser.tsx=true', + 'jsc.transform.react.useBuiltins=true', + 'jsc.target=es2020', + 'jsc.minify.format.comments=false', + 'jsc.externalHelpers=true', + ].join(' -C '), + + get esm() { + return [this.shared, this.compilerOptions, '-C module.type=es6'].join(' '); + }, + + get cjs() { + return [this.shared, this.compilerOptions, '-C module.type=commonjs'].join( + ' ', + ); + }, +}; + +execSync(`pnpm swc src -d esm ${swcOptions.esm}`); +console.log('✓ Built esm.'); + +execSync(`pnpm swc src -d cjs ${swcOptions.cjs}`); +console.log('✓ Built cjs.'); diff --git a/packages/itwinui-react/scripts/postBuild.mjs b/packages/itwinui-react/scripts/postBuild.mjs index cf3c4d2b93b..adc2a09caca 100644 --- a/packages/itwinui-react/scripts/postBuild.mjs +++ b/packages/itwinui-react/scripts/postBuild.mjs @@ -3,7 +3,7 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import fs from 'node:fs'; -import { exec } from 'node:child_process'; +import { execSync } from 'node:child_process'; // This creates a dummy package.json file in the cjs folder. // Without this, all cjs files would need the .cjs extension @@ -15,10 +15,12 @@ try { } // Run prettier on all compiled output because it gets jumbled by tsc. -exec('pnpm exec prettier --write "{esm,cjs}/**/*.js"', (error) => { - if (error) { - console.error('Error when running prettier', error); - } else { - console.log('✓ Finished compiling @itwin/itwinui-react'); - } -}); +try { + execSync( + 'npx prettier --write --ignore-path="../../.gitignore" "{esm,cjs}/**/*.js"', + ); +} catch (error) { + console.error('Error when running prettier', error); +} + +console.log('\x1b[32m✓ Finished building @itwin/itwinui-react'); diff --git a/packages/itwinui-react/tsconfig.build.json b/packages/itwinui-react/tsconfig.build.json index 8037e438341..72afa1080f4 100644 --- a/packages/itwinui-react/tsconfig.build.json +++ b/packages/itwinui-react/tsconfig.build.json @@ -3,6 +3,6 @@ "files": ["src/index.ts"], "compilerOptions": { "noUnusedLocals": false, - "importHelpers": true + "emitDeclarationOnly": true } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fcef170bc98..97ad7f6b863 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -126,7 +126,7 @@ importers: version: link:../../packages/itwinui-variables '@ladle/react': specifier: ^4.0.2 - version: 4.0.2(@swc/helpers@0.5.5)(@types/node@18.17.19)(@types/react@18.2.14)(lightningcss@1.25.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.72.0)(typescript@5.1.6) + version: 4.0.2(@swc/helpers@0.5.11)(@types/node@18.17.19)(@types/react@18.2.14)(lightningcss@1.25.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.72.0)(typescript@5.1.6) '@types/node': specifier: '*' version: 18.17.19 @@ -339,6 +339,9 @@ importers: '@itwin/itwinui-illustrations-react': specifier: ^2.1.0 version: 2.1.0(react-dom@18.2.0(react@18.2.0))(react@18.2.0) + '@swc/helpers': + specifier: ^0.5.11 + version: 0.5.11 classnames: specifier: ^2.3.2 version: 2.3.2 @@ -351,16 +354,13 @@ importers: react-transition-group: specifier: ^4.4.5 version: 4.4.5(react-dom@18.2.0(react@18.2.0))(react@18.2.0) - tslib: - specifier: ^2.6.0 - version: 2.6.1 devDependencies: '@swc/cli': specifier: ^0.3.12 - version: 0.3.12(@swc/core@1.5.28(@swc/helpers@0.5.5))(chokidar@3.6.0) + version: 0.3.12(@swc/core@1.5.28(@swc/helpers@0.5.11))(chokidar@3.6.0) '@swc/core': specifier: ^1.5.28 - version: 1.5.28(@swc/helpers@0.5.5) + version: 1.5.28(@swc/helpers@0.5.11) '@testing-library/jest-dom': specifier: ^6.3.0 version: 6.3.0(vitest@1.2.1(@types/node@18.17.19)(jsdom@24.0.0)(lightningcss@1.25.0)(sass@1.72.0)) @@ -3185,6 +3185,12 @@ packages: integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==, } + '@swc/helpers@0.5.11': + resolution: + { + integrity: sha512-YNlnKRWF2sVojTpIyzwou9XoTNbzbzONwRhOoniEioF1AtaitTvVZblaQRrAzChWQ1bLYyYSWzM18y4WwgzJ+A==, + } + '@swc/helpers@0.5.5': resolution: { @@ -15161,7 +15167,7 @@ snapshots: react: 18.2.0 react-dom: 18.2.0(react@18.2.0) - '@ladle/react@4.0.2(@swc/helpers@0.5.5)(@types/node@18.17.19)(@types/react@18.2.14)(lightningcss@1.25.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.72.0)(typescript@5.1.6)': + '@ladle/react@4.0.2(@swc/helpers@0.5.11)(@types/node@18.17.19)(@types/react@18.2.14)(lightningcss@1.25.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(sass@1.72.0)(typescript@5.1.6)': dependencies: '@babel/code-frame': 7.23.5 '@babel/core': 7.23.6 @@ -15174,7 +15180,7 @@ snapshots: '@mdx-js/mdx': 3.0.0 '@mdx-js/react': 3.0.0(@types/react@18.2.14)(react@18.2.0) '@vitejs/plugin-react': 4.2.1(vite@5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0)) - '@vitejs/plugin-react-swc': 3.5.0(@swc/helpers@0.5.5)(vite@5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0)) + '@vitejs/plugin-react-swc': 3.5.0(@swc/helpers@0.5.11)(vite@5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0)) axe-core: 4.8.2 boxen: 7.1.1 chokidar: 3.5.3 @@ -15870,10 +15876,10 @@ snapshots: '@sindresorhus/merge-streams@1.0.0': {} - '@swc/cli@0.3.12(@swc/core@1.5.28(@swc/helpers@0.5.5))(chokidar@3.6.0)': + '@swc/cli@0.3.12(@swc/core@1.5.28(@swc/helpers@0.5.11))(chokidar@3.6.0)': dependencies: '@mole-inc/bin-wrapper': 8.0.1 - '@swc/core': 1.5.28(@swc/helpers@0.5.5) + '@swc/core': 1.5.28(@swc/helpers@0.5.11) '@swc/counter': 0.1.3 commander: 8.3.0 fast-glob: 3.3.2 @@ -15915,7 +15921,7 @@ snapshots: '@swc/core-win32-x64-msvc@1.5.28': optional: true - '@swc/core@1.5.28(@swc/helpers@0.5.5)': + '@swc/core@1.5.28(@swc/helpers@0.5.11)': dependencies: '@swc/counter': 0.1.3 '@swc/types': 0.1.8 @@ -15930,10 +15936,14 @@ snapshots: '@swc/core-win32-arm64-msvc': 1.5.28 '@swc/core-win32-ia32-msvc': 1.5.28 '@swc/core-win32-x64-msvc': 1.5.28 - '@swc/helpers': 0.5.5 + '@swc/helpers': 0.5.11 '@swc/counter@0.1.3': {} + '@swc/helpers@0.5.11': + dependencies: + tslib: 2.6.1 + '@swc/helpers@0.5.5': dependencies: '@swc/counter': 0.1.3 @@ -16314,9 +16324,9 @@ snapshots: '@vanilla-extract/private@1.0.3': {} - '@vitejs/plugin-react-swc@3.5.0(@swc/helpers@0.5.5)(vite@5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0))': + '@vitejs/plugin-react-swc@3.5.0(@swc/helpers@0.5.11)(vite@5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0))': dependencies: - '@swc/core': 1.5.28(@swc/helpers@0.5.5) + '@swc/core': 1.5.28(@swc/helpers@0.5.11) vite: 5.1.7(@types/node@18.17.19)(lightningcss@1.25.0)(sass@1.72.0) transitivePeerDependencies: - '@swc/helpers'