From f17f3ee65f909f6b48ab6d39f7edb3a0d448f940 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Wed, 1 May 2024 09:24:04 +0100 Subject: [PATCH] fix: typescript and storybook v7 compatability --- package-lock.json | 20 ++++++++------------ package.json | 12 +++++++++--- tsconfig.json | 10 ++++++++++ tsup.config.js | 12 ++++++++++-- 4 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 tsconfig.json diff --git a/package-lock.json b/package-lock.json index 5e290d6..089518c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,16 @@ { "name": "@etchteam/storybook-addon-css-variables-theme", - "version": "2.1.1", + "version": "2.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etchteam/storybook-addon-css-variables-theme", - "version": "2.1.1", + "version": "2.1.2", "license": "MIT", + "dependencies": { + "@storybook/icons": "^1.2.9" + }, "devDependencies": { "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", @@ -18,7 +21,6 @@ "@storybook/client-logger": "8.0.9", "@storybook/components": "8.0.9", "@storybook/core-events": "8.0.9", - "@storybook/icons": "^1.2.9", "@storybook/manager-api": "8.0.9", "@storybook/preview-api": "^8.0.9", "@storybook/react-webpack5": "^8.0.9", @@ -33,7 +35,8 @@ "react-dom": "18.2.0", "storybook": "8.0.9", "swc-loader": "^0.2.6", - "tsup": "^8.0.2" + "tsup": "^8.0.2", + "typescript": "^5.4.5" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -5119,7 +5122,6 @@ "version": "1.2.9", "resolved": "https://registry.npmjs.org/@storybook/icons/-/icons-1.2.9.tgz", "integrity": "sha512-cOmylsz25SYXaJL/gvTk/dl3pyk7yBFRfeXTsHvTA3dfhoU/LWSq0NKL9nM7WBasJyn6XPSGnLS4RtKXLw5EUg==", - "dev": true, "engines": { "node": ">=14.0.0" }, @@ -12242,8 +12244,7 @@ "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "node_modules/js-yaml": { "version": "4.1.0", @@ -13024,7 +13025,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "dev": true, "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" }, @@ -14672,7 +14672,6 @@ "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", - "dev": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -14730,7 +14729,6 @@ "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", - "dev": true, "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.0" @@ -15333,7 +15331,6 @@ "version": "0.23.1", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.1.tgz", "integrity": "sha512-5GKS5JGfiah1O38Vfa9srZE4s3wdHbwjlCrvIookrg2FO9aIwKLOJXuJQFlEfNcVSOXuaL2hzDeY20uVXcUtrw==", - "dev": true, "dependencies": { "loose-envify": "^1.1.0" } @@ -17131,7 +17128,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", "dev": true, - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 749020f..166a773 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,13 @@ { "name": "@etchteam/storybook-addon-css-variables-theme", - "version": "2.1.1", + "version": "2.1.2", "description": "Switch CSS files to change themes", "type": "module", + "main": "dist/index.js", + "types": "dist/index.d.ts", "exports": { ".": { + "types": "./dist/index.d.ts", "import": "./dist/index.js", "require": "./dist/index.cjs" }, @@ -50,6 +53,9 @@ "url": "https://github.com/etchteam/storybook-addon-css-variables-theme/issues" }, "homepage": "https://github.com/etchteam/storybook-addon-css-variables-theme#readme", + "dependencies": { + "@storybook/icons": "^1.2.9" + }, "devDependencies": { "@commitlint/cli": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", @@ -60,7 +66,6 @@ "@storybook/client-logger": "8.0.9", "@storybook/components": "8.0.9", "@storybook/core-events": "8.0.9", - "@storybook/icons": "^1.2.9", "@storybook/manager-api": "8.0.9", "@storybook/preview-api": "^8.0.9", "@storybook/react-webpack5": "^8.0.9", @@ -75,7 +80,8 @@ "react-dom": "18.2.0", "storybook": "8.0.9", "swc-loader": "^0.2.6", - "tsup": "^8.0.2" + "tsup": "^8.0.2", + "typescript": "^5.4.5" }, "publishConfig": { "access": "public" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6465c60 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "include": ["src/**/*"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "dist", + "declarationMap": true + } +} diff --git a/tsup.config.js b/tsup.config.js index 7294c8a..4ed509d 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -5,6 +5,9 @@ import { defineConfig } from 'tsup'; // The current browsers supported by Storybook v7 const BROWSER_TARGET = ['chrome100', 'safari15', 'firefox91']; const NODE_TARGET = ['node18']; +const globalManagerPackagesExcludingIcons = globalManagerPackages.filter( + (packageName) => packageName !== '@storybook/icons', +); export default defineConfig(async (options) => { const commonConfig = { @@ -19,10 +22,14 @@ export default defineConfig(async (options) => { { ...commonConfig, entry: ['src/index.js'], + dts: { resolve: true }, format: ['esm', 'cjs'], target: [...BROWSER_TARGET, ...NODE_TARGET], platform: 'neutral', - external: [...globalManagerPackages, ...globalPreviewPackages], + external: [ + ...globalManagerPackagesExcludingIcons, + ...globalPreviewPackages, + ], }, { ...commonConfig, @@ -30,11 +37,12 @@ export default defineConfig(async (options) => { format: ['esm'], target: BROWSER_TARGET, platform: 'browser', - external: globalManagerPackages, + external: globalManagerPackagesExcludingIcons, }, { ...commonConfig, entry: ['src/preview.js'], + dts: { resolve: true }, format: ['esm', 'cjs'], target: BROWSER_TARGET, platform: 'browser',