Skip to content

Commit

Permalink
Merge pull request #25712 from storybookjs/valentin/fix-addon-bundle-…
Browse files Browse the repository at this point in the history
…aliasing

Addons: Remove Node.js internal aliasing for Node builds
  • Loading branch information
valentinpalkovic authored Jan 23, 2024
2 parents 62337da + 8020d31 commit 13b30d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
1 change: 1 addition & 0 deletions code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"./manager": "./dist/manager.js",
"./preview": "./dist/preview.js",
"./preset": "./dist/preset.js",
"./register.js": "./dist/manager.js",
"./package.json": "./package.json"
},
Expand Down
46 changes: 16 additions & 30 deletions scripts/prepare/addon-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,26 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
shims: false,
watch,
clean: false,
};

const browserOptions: Options = {
target: ['chrome100', 'safari15', 'firefox91'],
platform: 'browser',
esbuildPlugins: [
aliasPlugin({
process: require.resolve('../node_modules/process/browser.js'),
util: require.resolve('../node_modules/util/util.js'),
assert: require.resolve('browser-assert'),
}),
],
format: ['esm'],
esbuildOptions: (options) => {
/* eslint-disable no-param-reassign */
options.conditions = ['module'];
options.platform = 'browser';
Object.assign(options, getESBuildOptions(optimized));
/* eslint-enable no-param-reassign */
},
};

const commonExternals = [
Expand All @@ -98,18 +111,9 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
build({
...commonOptions,
...(optimized ? dtsConfig : {}),
...browserOptions,
entry: exportEntries,
format: ['esm'],
target: ['chrome100', 'safari15', 'firefox91'],
platform: 'browser',
external: [...commonExternals, ...globalManagerPackages, ...globalPreviewPackages],
esbuildOptions: (options) => {
/* eslint-disable no-param-reassign */
options.conditions = ['module'];
options.platform = 'browser';
Object.assign(options, getESBuildOptions(optimized));
/* eslint-enable no-param-reassign */
},
}),
build({
...commonOptions,
Expand Down Expand Up @@ -138,43 +142,25 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
tasks.push(
build({
...commonOptions,
...browserOptions,
entry: managerEntries.map((e: string) => slash(join(cwd, e))),
outExtension: () => ({
js: '.js',
}),
format: ['esm'],
target: ['chrome100', 'safari15', 'firefox91'],
platform: 'browser',
external: [...commonExternals, ...globalManagerPackages],
esbuildOptions: (options) => {
/* eslint-disable no-param-reassign */
options.conditions = ['module'];
options.platform = 'browser';
Object.assign(options, getESBuildOptions(optimized));
/* eslint-enable no-param-reassign */
},
})
);
}
if (previewEntries.length > 0) {
tasks.push(
build({
...commonOptions,
...browserOptions,
entry: previewEntries.map((e: string) => slash(join(cwd, e))),
outExtension: () => ({
js: '.js',
}),
format: ['esm'],
target: ['chrome100', 'safari15', 'firefox91'],
platform: 'browser',
external: [...commonExternals, ...globalPreviewPackages],
esbuildOptions: (c) => {
/* eslint-disable no-param-reassign */
c.conditions = ['module'];
c.platform = 'browser';
Object.assign(c, getESBuildOptions(optimized));
/* eslint-enable no-param-reassign */
},
})
);
}
Expand Down

0 comments on commit 13b30d6

Please sign in to comment.