From 9b0a59c2795dbf7a46b246ae8d782222950e3c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 20 Apr 2022 15:16:46 +0200 Subject: [PATCH] Fixed PnP compatibility for bundled components package --- lib/components/package.json | 8 ++++---- scripts/bundle-package.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/components/package.json b/lib/components/package.json index 0baeca461e5c..86721f9c3ed7 100644 --- a/lib/components/package.json +++ b/lib/components/package.json @@ -45,8 +45,10 @@ "@storybook/theming": "6.5.0-beta.7", "@types/react-syntax-highlighter": "11.0.5", "core-js": "^3.8.2", + "qs": "^6.10.0", "react-syntax-highlighter": "^15.4.5", - "regenerator-runtime": "^0.13.7" + "regenerator-runtime": "^0.13.7", + "util-deprecate": "^1.0.2" }, "devDependencies": { "@popperjs/core": "^2.6.0", @@ -64,13 +66,11 @@ "polished": "^4.2.2", "prettier": ">=2.2.1 <=2.3.0", "prop-types": "^15.7.2", - "qs": "^6.10.0", "react-colorful": "^5.1.2", "react-popper-tooltip": "^3.1.1", "react-textarea-autosize": "^8.3.0", "ts-dedent": "^2.0.0", - "ts-node": "^10.4.0", - "util-deprecate": "^1.0.2" + "ts-node": "^10.4.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", diff --git a/scripts/bundle-package.ts b/scripts/bundle-package.ts index 9779bc39955b..6ac070fc99bf 100644 --- a/scripts/bundle-package.ts +++ b/scripts/bundle-package.ts @@ -21,11 +21,19 @@ interface Options { watch?: boolean; } +const makeExternalPredicate = (externals: string[]) => { + if (externals.length === 0) { + return () => false; + } + const pattern = new RegExp(`^(${externals.join('|')})($|/)`); + return (id: string) => pattern.test(id); +}; + async function build(options: Options) { const { input, externals, cwd, optimized } = options; const setting: RollupOptions = { input, - external: externals, + external: makeExternalPredicate(externals), plugins: [ nodeResolve({ preferBuiltins: true,