Skip to content

Commit

Permalink
Merge pull request #22330 from storybookjs/norbert/fix-21316
Browse files Browse the repository at this point in the history
Tech: do not generate ESM dist for preset files
  • Loading branch information
ndelangen authored May 2, 2023
2 parents 7a461f3 + 7ad4309 commit 5c3ec1f
Show file tree
Hide file tree
Showing 24 changed files with 9 additions and 27 deletions.
2 changes: 0 additions & 2 deletions code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./blocks": {
Expand All @@ -53,7 +52,6 @@
},
"./dist/preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./dist/shims/mdx-react-shim": {
Expand Down
1 change: 0 additions & 1 deletion code/addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./manager": {
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/html-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/html-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./preview.js": {
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/preact-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/preact-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/react-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/react-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/server-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/svelte-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/svelte-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/vue-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/vue-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/vue3-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/vue3-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/web-components-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/frameworks/web-components-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
},
"./preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
2 changes: 0 additions & 2 deletions code/lib/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
"./presets/custom-webpack-preset": {
"node": "./dist/presets/custom-webpack-preset.js",
"require": "./dist/presets/custom-webpack-preset.js",
"import": "./dist/presets/custom-webpack-preset.mjs",
"types": "./dist/presets/custom-webpack-preset.d.ts"
},
"./presets/preview-preset": {
"node": "./dist/presets/preview-preset.js",
"require": "./dist/presets/preview-preset.js",
"import": "./dist/presets/preview-preset.mjs",
"types": "./dist/presets/preview-preset.d.ts"
},
"./templates/virtualModuleModernEntry.js.handlebars": "./templates/virtualModuleModernEntry.js.handlebars",
Expand Down
2 changes: 0 additions & 2 deletions code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
"./dist/presets/babel-cache-preset": {
"node": "./dist/presets/babel-cache-preset.js",
"require": "./dist/presets/babel-cache-preset.js",
"import": "./dist/presets/babel-cache-preset.mjs",
"types": "./dist/presets/babel-cache-preset.d.ts"
},
"./dist/presets/common-preset": {
"node": "./dist/presets/common-preset.js",
"require": "./dist/presets/common-preset.js",
"import": "./dist/presets/common-preset.mjs",
"types": "./dist/presets/common-preset.d.ts"
},
"./public/favicon.svg": "./public/favicon.svg",
Expand Down
1 change: 0 additions & 1 deletion code/lib/react-dom-shim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"./dist/preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
1 change: 0 additions & 1 deletion code/renderers/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
},
"./dist/preset": {
"require": "./dist/preset.js",
"import": "./dist/preset.mjs",
"types": "./dist/preset.d.ts"
},
"./package.json": "./package.json"
Expand Down
10 changes: 9 additions & 1 deletion scripts/prepare/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,19 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
optimized,
});

/* preset files are always CJS only.
* Generating an ESM file for them anyway is problematic because they often have a reference to `require`.
* TSUP generated code will then have a `require` polyfill/guard in the ESM files, which causes issues for webpack.
*/
const nonPresetEntries = allEntries.filter((f) => !path.parse(f).name.includes('preset'));

if (formats.includes('esm')) {
tasks.push(
build({
silent: true,
entry: allEntries,
treeshake: true,
entry: nonPresetEntries,
shims: false,
watch,
outDir,
format: ['esm'],
Expand Down

0 comments on commit 5c3ec1f

Please sign in to comment.