From 772c1f7e6a437f58d06ac7fb3e6152ebd1d03915 Mon Sep 17 00:00:00 2001 From: Robbert Broersma Date: Sun, 24 Nov 2024 17:15:58 +0100 Subject: [PATCH] build: align `component-library-react` rollup config with `build-utils-react` --- packages/component-library-react/package.json | 13 ++++- .../rollup-components.config.mjs | 5 +- .../component-library-react/rollup.config.mjs | 55 ++++++++----------- .../tsconfig.build-css-module.json | 8 +++ .../component-library-react/tsconfig.json | 4 +- pnpm-lock.yaml | 43 +++++---------- 6 files changed, 62 insertions(+), 66 deletions(-) create mode 100644 packages/component-library-react/tsconfig.build-css-module.json diff --git a/packages/component-library-react/package.json b/packages/component-library-react/package.json index 8a128a414db..baf56b33685 100644 --- a/packages/component-library-react/package.json +++ b/packages/component-library-react/package.json @@ -20,7 +20,14 @@ "sideEffects": false, "type": "module", "exports": { - ".": "./dist/index.mjs", + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs" + }, + "./css": { + "types": "./dist/css.d.ts", + "import": "./dist/css.mjs" + }, "./dist": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs" @@ -123,6 +130,7 @@ "@rollup/plugin-commonjs": "26.0.1", "@rollup/plugin-json": "6.1.0", "@rollup/plugin-node-resolve": "15.2.3", + "@rollup/plugin-typescript": "12.1.0", "@testing-library/dom": "8.20.1", "@testing-library/jest-dom": "5.17.0", "@testing-library/react": "13.4.0", @@ -222,7 +230,7 @@ "react-dom": "18.3.1", "react-vega": "7.6.0", "rimraf": "5.0.7", - "rollup": "4.18.0", + "rollup": "4.23.0", "rollup-plugin-delete": "2.0.0", "rollup-plugin-filesize": "10.0.0", "rollup-plugin-node-externals": "7.1.2", @@ -231,6 +239,7 @@ "rollup-plugin-postcss": "4.0.2", "rollup-plugin-typescript2": "0.36.0", "sass": "1.69.5", + "sort-package-json": "2.11.0", "tslib": "2.6.2", "typescript": "5.6.2", "vega": "5.26.1", diff --git a/packages/component-library-react/rollup-components.config.mjs b/packages/component-library-react/rollup-components.config.mjs index 636e54cc709..b0b00e9b5a7 100644 --- a/packages/component-library-react/rollup-components.config.mjs +++ b/packages/component-library-react/rollup-components.config.mjs @@ -10,6 +10,7 @@ import nodePolyfills from 'rollup-plugin-node-polyfills'; import peerDepsExternal from 'rollup-plugin-peer-deps-external'; import postcss from 'rollup-plugin-postcss'; import typescript from 'rollup-plugin-typescript2'; + // `assert` is not yet supported by ESLint // import packageJson from './package.json' assert { type: 'json' }; @@ -50,7 +51,9 @@ const createComponentConfig = (name, { css }) => ({ extensions: ['.css', '.scss'], minimize: true, }), - typescript({ includeDependencies: false }), + typescript({ + tsconfig: css ? './tsconfig.build-css-module.json' : './tsconfig.build.json', + }), babel({ presets: ['@babel/preset-react'], babelHelpers: 'runtime', diff --git a/packages/component-library-react/rollup.config.mjs b/packages/component-library-react/rollup.config.mjs index 9734f5867c8..91e4752e4d7 100644 --- a/packages/component-library-react/rollup.config.mjs +++ b/packages/component-library-react/rollup.config.mjs @@ -1,21 +1,11 @@ import babel from '@rollup/plugin-babel'; import commonjs from '@rollup/plugin-commonjs'; -import json from '@rollup/plugin-json'; import resolve from '@rollup/plugin-node-resolve'; -// import del from 'rollup-plugin-delete'; -import { readFileSync } from 'fs'; +import typescript from 'rollup-plugin-typescript2'; import filesize from 'rollup-plugin-filesize'; import nodeExternal from 'rollup-plugin-node-externals'; -import nodePolyfills from 'rollup-plugin-node-polyfills'; import peerDepsExternal from 'rollup-plugin-peer-deps-external'; -import postcss from 'rollup-plugin-postcss'; -import typescript from 'rollup-plugin-typescript2'; -// `assert` is not yet supported by ESLint -// import packageJson from './package.json' assert { type: 'json' }; - -const packageJson = JSON.parse(readFileSync('./package.json', 'utf8')); -// rollup.config.js /** * @type {import('rollup').RollupOptions} */ @@ -27,7 +17,7 @@ export const outputGlobals = { export default [ { - input: 'src/index.ts', + input: './src/index.ts', output: [ { file: './dist/index.mjs', @@ -38,28 +28,30 @@ export default [ ], plugins: [ peerDepsExternal(), - nodeExternal(), - resolve({ browser: true }), + + // Convert CommonJS modules to ES Modules commonjs({ include: /node_modules/, }), - nodePolyfills(), - // del({ targets: ['dist/*', 'pages/*'] }), - typescript({ includeDependencies: false }), - json(), + // Inline imports from `devDependencies` + // Leave `dependencies` and `devDependencies` imports as is. + // See: https://www.npmjs.com/package/rollup-plugin-node-externals + nodeExternal(), + resolve(), + typescript({ tsconfig: './tsconfig.build.json' }), babel({ presets: ['@babel/preset-react'], babelHelpers: 'runtime', exclude: ['node_modules/**', 'dist/**'], extensions: ['.ts', '.tsx'], - inputSourceMap: true, + // inputSourceMap: true, plugins: ['@babel/plugin-transform-runtime'], }), filesize(), ], }, { - input: 'src/css-module/index.ts', + input: './src/css-module/index.ts', output: [ { file: './dist/css-module/index.mjs', @@ -68,28 +60,25 @@ export default [ globals: outputGlobals, }, ], - external: [/@babel\/runtime/, 'react-dom', 'react'], plugins: [ - peerDepsExternal({ includeDependencies: true }), - nodeExternal(), - resolve({ browser: true }), + peerDepsExternal(), + + // Convert CommonJS modules to ES Modules commonjs({ include: /node_modules/, }), - nodePolyfills(), - // del({ targets: ['dist/*', 'pages/*'] }), - postcss({ - extensions: ['.css', '.scss'], - minimize: true, - }), - typescript({ includeDependencies: false }), - json(), + // Inline imports from `devDependencies` + // Leave `dependencies` and `devDependencies` imports as is. + // See: https://www.npmjs.com/package/rollup-plugin-node-externals + nodeExternal(), + resolve(), + typescript({ tsconfig: './tsconfig.build-css-module.json' }), babel({ presets: ['@babel/preset-react'], babelHelpers: 'runtime', exclude: ['node_modules/**', 'dist/**'], extensions: ['.ts', '.tsx'], - inputSourceMap: true, + // inputSourceMap: true, plugins: ['@babel/plugin-transform-runtime'], }), filesize(), diff --git a/packages/component-library-react/tsconfig.build-css-module.json b/packages/component-library-react/tsconfig.build-css-module.json new file mode 100644 index 00000000000..59059681951 --- /dev/null +++ b/packages/component-library-react/tsconfig.build-css-module.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist/css-module/", + "rootDir": "./src/" + } +} diff --git a/packages/component-library-react/tsconfig.json b/packages/component-library-react/tsconfig.json index ea004041acd..bdbe83e3f1a 100644 --- a/packages/component-library-react/tsconfig.json +++ b/packages/component-library-react/tsconfig.json @@ -9,7 +9,7 @@ { "path": "../components-react/calendar-react/tsconfig.build.json" } ], "compilerOptions": { - "outDir": "dist", - "rootDir": "src" + "outDir": "./dist/", + "rootDir": "./src/" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c4a975089b..02ed118d1bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1676,16 +1676,19 @@ importers: version: 7.24.7 '@rollup/plugin-babel': specifier: 6.0.4 - version: 6.0.4(@babel/core@7.24.7)(@types/babel__core@7.20.5)(rollup@4.18.0) + version: 6.0.4(@babel/core@7.24.7)(@types/babel__core@7.20.5)(rollup@4.23.0) '@rollup/plugin-commonjs': specifier: 26.0.1 - version: 26.0.1(rollup@4.18.0) + version: 26.0.1(rollup@4.23.0) '@rollup/plugin-json': specifier: 6.1.0 - version: 6.1.0(rollup@4.18.0) + version: 6.1.0(rollup@4.23.0) '@rollup/plugin-node-resolve': specifier: 15.2.3 - version: 15.2.3(rollup@4.18.0) + version: 15.2.3(rollup@4.23.0) + '@rollup/plugin-typescript': + specifier: 12.1.0 + version: 12.1.0(rollup@4.23.0)(tslib@2.6.2)(typescript@5.6.2) '@testing-library/dom': specifier: 8.20.1 version: 8.20.1 @@ -1984,8 +1987,8 @@ importers: specifier: 5.0.7 version: 5.0.7 rollup: - specifier: 4.18.0 - version: 4.18.0 + specifier: 4.23.0 + version: 4.23.0 rollup-plugin-delete: specifier: 2.0.0 version: 2.0.0 @@ -1994,22 +1997,25 @@ importers: version: 10.0.0 rollup-plugin-node-externals: specifier: 7.1.2 - version: 7.1.2(rollup@4.18.0) + version: 7.1.2(rollup@4.23.0) rollup-plugin-node-polyfills: specifier: 0.2.1 version: 0.2.1 rollup-plugin-peer-deps-external: specifier: 2.2.4 - version: 2.2.4(rollup@4.18.0) + version: 2.2.4(rollup@4.23.0) rollup-plugin-postcss: specifier: 4.0.2 version: 4.0.2(postcss@8.4.38)(ts-node@10.9.1(@swc/core@1.3.100(@swc/helpers@0.5.5))(@types/node@22.7.4)(typescript@5.6.2)) rollup-plugin-typescript2: specifier: 0.36.0 - version: 0.36.0(rollup@4.18.0)(typescript@5.6.2) + version: 0.36.0(rollup@4.23.0)(typescript@5.6.2) sass: specifier: 1.69.5 version: 1.69.5 + sort-package-json: + specifier: 2.11.0 + version: 2.11.0 tslib: specifier: 2.6.2 version: 2.6.2 @@ -3520,9 +3526,6 @@ importers: packages/components-react/select-combobox-react: dependencies: - '@babel/runtime': - specifier: ^7.23.6 - version: 7.24.7 '@utrecht/button-react': specifier: workspace:* version: link:../button-react @@ -31468,12 +31471,6 @@ snapshots: optionalDependencies: rollup: 3.29.4 - '@rollup/plugin-json@6.1.0(rollup@4.18.0)': - dependencies: - '@rollup/pluginutils': 5.1.0(rollup@4.18.0) - optionalDependencies: - rollup: 4.18.0 - '@rollup/plugin-json@6.1.0(rollup@4.23.0)': dependencies: '@rollup/pluginutils': 5.1.0(rollup@4.23.0) @@ -47516,16 +47513,6 @@ snapshots: tslib: 2.6.2 typescript: 4.9.5 - rollup-plugin-typescript2@0.36.0(rollup@4.18.0)(typescript@5.6.2): - dependencies: - '@rollup/pluginutils': 4.2.1 - find-cache-dir: 3.3.2 - fs-extra: 10.1.0 - rollup: 4.18.0 - semver: 7.6.2 - tslib: 2.6.2 - typescript: 5.6.2 - rollup-plugin-typescript2@0.36.0(rollup@4.23.0)(typescript@5.6.2): dependencies: '@rollup/pluginutils': 4.2.1