From 21441c5cbc2dbd6ec06c50cb0989a7741e7783ec Mon Sep 17 00:00:00 2001 From: Joonas Kaski Date: Wed, 29 Jan 2025 11:33:50 +0200 Subject: [PATCH 1/3] replace rollup-plugin-ts with rollup/plugin-typescript and rollup-plugin-dts --- package.json | 6 +++--- rollup.config.mjs | 50 ++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index cdff63d80..2d19f8afb 100644 --- a/package.json +++ b/package.json @@ -57,11 +57,9 @@ "prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"", "prettier:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"", "validate": "run-p test lint prettier:check", - "build": "npm-run-all build:clean build:rollup build:copytypes build:cleantmp", + "build": "npm-run-all build:clean build:rollup", "build:clean": "rimraf ./dist", "build:rollup": "rollup -c", - "build:copytypes": "copyfiles -f ./dist/tmp/index.d.ts ./dist/types", - "build:cleantmp": "rimraf ./dist/tmp", "bundle-analyzer": "size-limit --why", "styleguide": "styleguidist server", "styleguide:build": "cross-env BASE_PATH=/suomifi-ui-components styleguidist build", @@ -78,6 +76,7 @@ "@rollup/plugin-babel": "6.0.4", "@rollup/plugin-commonjs": "28.0.0", "@rollup/plugin-node-resolve": "15.3.0", + "@rollup/plugin-typescript": "12.1.2", "@testing-library/dom": "10.4.0", "@testing-library/jest-dom": "6.5.0", "@testing-library/react": "16.0.1", @@ -132,6 +131,7 @@ "react-styleguidist": "13.1.3", "rimraf": "5.0.1", "rollup": "4.24.0", + "rollup-plugin-dts": "6.1.1", "rollup-plugin-postcss": "4.0.2", "rollup-plugin-progress": "1.1.2", "rollup-plugin-ts": "3.4.5", diff --git a/rollup.config.mjs b/rollup.config.mjs index 25ec8290f..b6553d7b8 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,13 +1,15 @@ import progress from 'rollup-plugin-progress'; import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; -import ts from 'rollup-plugin-ts'; +import typescript from '@rollup/plugin-typescript'; import postcss from 'rollup-plugin-postcss'; import cssImport from 'postcss-import'; import autoprefixer from 'autoprefixer'; import cssnano from 'cssnano'; +import dts from 'rollup-plugin-dts'; +import { babel } from '@rollup/plugin-babel'; -import pkg from './package.json' assert { type: 'json' }; +import pkg from './package.json' with { type: 'json' }; const typesTsConfig = { declaration: true, @@ -22,6 +24,7 @@ const output = { preserveModules: true, sourcemap: true, interop: 'auto', + importAttributesKey: 'with', }, { dir: 'dist/esm', @@ -30,37 +33,36 @@ const output = { exports: 'named', sourcemap: true, interop: 'auto', + importAttributesKey: 'with', }, ], types: [ { - file: 'dist/tmp/index.js', + file: 'dist/types/index.d.ts', format: 'cjs', - interop: 'auto', }, ], css: [{}], }; +const babelConfig = { + presets: ['@babel/preset-env', '@babel/preset-react'], + plugins: [ + '@babel/plugin-transform-runtime', + ['babel-plugin-styled-components', { ssr: true, displayName: false }], + ], +}; + const plugins = (tsConfig, extractCSS) => [ progress(), nodeResolve(), commonjs(), - ts({ - transpiler: 'babel', - babelConfig: { - presets: ['@babel/preset-env', '@babel/preset-react'], - plugins: [ - '@babel/plugin-transform-runtime', - ['babel-plugin-styled-components', { ssr: true, displayName: false }], - ], - }, - include: ['**/*.ts', '**/*.tsx'], - transpileOnly: false, - tsconfig: (resolvedConfig) => ({ - ...resolvedConfig, - ...tsConfig, - }), + typescript(tsConfig), + babel({ + babelHelpers: 'runtime', + ...babelConfig, + extensions: ['.js', '.jsx', '.ts', '.tsx'], + include: ['src/**/*'], }), postcss({ extensions: ['.css', '.scss'], @@ -76,10 +78,10 @@ const plugins = (tsConfig, extractCSS) => [ }), ]; -const bundle = (output, tsConfig, exctractCSS) => ({ +const bundle = (output, tsConfig, extractCSS) => ({ input: 'src/index.tsx', output: output, - plugins: plugins(tsConfig, exctractCSS), + plugins: plugins(tsConfig, extractCSS), external: [ /@babel\/runtime/, ...(!!pkg.dependencies ? Object.keys(pkg.dependencies) : []), @@ -90,5 +92,9 @@ const bundle = (output, tsConfig, exctractCSS) => ({ export default [ bundle(output['js'], {}, false), - bundle(output['types'], typesTsConfig, true), + { + input: 'src/index.tsx', // Updated the path to a valid TypeScript entry file + output: output['types'], + plugins: [dts()], + }, ]; From 03358160b1feeee7dd43e6012d6e50f0ad7d0c35 Mon Sep 17 00:00:00 2001 From: Joonas Kaski Date: Wed, 29 Jan 2025 14:14:31 +0200 Subject: [PATCH 2/3] add more paths to ignorePatterns in eslintrc --- .eslintrc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index bab3a3280..25d55ca98 100644 --- a/.eslintrc +++ b/.eslintrc @@ -24,7 +24,12 @@ "react", "tree-shaking" ], - "ignorePatterns": ["**/*.config.*", "jest/*.js"], + "ignorePatterns": [ + "**/*.config.*", + "jest/*.js", + "node_modules/", + "dist/**/*" + ], "rules": { "@typescript-eslint/naming-convention": [ "error", From 68266885d913085a4d4929217fc6a738cd6e7224 Mon Sep 17 00:00:00 2001 From: Joonas Kaski Date: Wed, 29 Jan 2025 15:53:48 +0200 Subject: [PATCH 3/3] update the package lock file --- package-lock.json | 99 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5415871f8..ec1dfbe7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "suomifi-ui-components", - "version": "15.0.0", + "version": "16.0.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "suomifi-ui-components", - "version": "15.0.0", + "version": "16.0.0-beta.1", "license": "MIT", "dependencies": { "@babel/runtime": "7.23.5", @@ -29,6 +29,7 @@ "@rollup/plugin-babel": "6.0.4", "@rollup/plugin-commonjs": "28.0.0", "@rollup/plugin-node-resolve": "15.3.0", + "@rollup/plugin-typescript": "12.1.2", "@testing-library/dom": "10.4.0", "@testing-library/jest-dom": "6.5.0", "@testing-library/react": "16.0.1", @@ -83,6 +84,7 @@ "react-styleguidist": "13.1.3", "rimraf": "5.0.1", "rollup": "4.24.0", + "rollup-plugin-dts": "6.1.1", "rollup-plugin-postcss": "4.0.2", "rollup-plugin-progress": "1.1.2", "rollup-plugin-ts": "3.4.5", @@ -150,13 +152,15 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", - "integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, + "license": "MIT", "dependencies": { - "@babel/highlight": "^7.23.4", - "chalk": "^2.4.2" + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" }, "engines": { "node": ">=6.9.0" @@ -517,10 +521,11 @@ } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", - "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -562,20 +567,6 @@ "node": ">=6.9.0" } }, - "node_modules/@babel/highlight": { - "version": "7.23.4", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", - "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", - "dev": true, - "dependencies": { - "@babel/helper-validator-identifier": "^7.22.20", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@babel/parser": { "version": "7.23.5", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.5.tgz", @@ -3494,6 +3485,33 @@ } } }, + "node_modules/@rollup/plugin-typescript": { + "version": "12.1.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-12.1.2.tgz", + "integrity": "sha512-cdtSp154H5sv637uMr1a8OTWB0L1SWDSm1rDGiyfcGcvQ6cuTs4MDk2BVEBGysUWago4OJN4EQZqOTl/QY3Jgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.1.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.14.0||^3.0.0||^4.0.0", + "tslib": "*", + "typescript": ">=3.7.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + }, + "tslib": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz", @@ -18608,6 +18626,39 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-dts": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.1.1.tgz", + "integrity": "sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==", + "dev": true, + "license": "LGPL-3.0-only", + "dependencies": { + "magic-string": "^0.30.10" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.24.2" + }, + "peerDependencies": { + "rollup": "^3.29.4 || ^4", + "typescript": "^4.5 || ^5.0" + } + }, + "node_modules/rollup-plugin-dts/node_modules/magic-string": { + "version": "0.30.17", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", + "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, "node_modules/rollup-plugin-postcss": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/rollup-plugin-postcss/-/rollup-plugin-postcss-4.0.2.tgz",