-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2653 from modernweb-dev/fix/storybook-builder-pro…
…cess-env fix(storybook-builder): define only necessary process.env globally
- Loading branch information
Showing
5 changed files
with
20 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@web/storybook-builder': patch | ||
--- | ||
|
||
define only necessary process.env globally to improve security and decrease prebundling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { stringifyProcessEnvs } from '@storybook/core-common'; | ||
import { build } from 'esbuild'; | ||
import { join } from 'path'; | ||
import type { Plugin } from 'rollup'; | ||
import { getNodeModuleDir } from './get-node-module-dir.js'; | ||
|
||
export const PREBUNDLED_MODULES_DIR = 'node_modules/.prebundled_modules'; | ||
|
||
export function rollupPluginPrebundleModules(env: Record<string, string>): Plugin { | ||
export function rollupPluginPrebundleModules(): Plugin { | ||
const modulePaths: Record<string, string> = {}; | ||
|
||
return { | ||
|
@@ -37,9 +36,6 @@ export function rollupPluginPrebundleModules(env: Record<string, string>): Plugi | |
lodash: getNodeModuleDir('lodash-es'), // more optimal, but also solves esbuild incorrectly compiling lodash/_nodeUtil | ||
path: require.resolve('path-browserify'), | ||
}, | ||
define: { | ||
...stringifyProcessEnvs(env), | ||
}, | ||
plugins: [esbuildCommonjsPlugin()], | ||
}); | ||
}, | ||
|
@@ -64,7 +60,7 @@ function getModules() { | |
|
||
// this is different to https://github.com/storybookjs/storybook/blob/v7.0.0/code/lib/builder-vite/src/optimizeDeps.ts#L7 | ||
// builder-vite bundles different dependencies for performance reasons | ||
// we aim only at browserifying NodeJS dependencies (CommonJS/process.env/...) | ||
// we aim only at browserifying dependencies which are CommonJS, or sometimes ESM with issues | ||
export const CANDIDATES = [ | ||
// @testing-library has ESM, but imports/exports are not working correctly between packages | ||
// specifically "@testing-library/user-event" has "dist/esm/utils/misc/getWindow.js" (see https://cdn.jsdelivr.net/npm/@testing-library/[email protected]/dist/esm/utils/misc/getWindow.js) | ||
|
@@ -82,7 +78,4 @@ export const CANDIDATES = [ | |
|
||
// CommonJS module used in Storybook MJS files | ||
'lodash/mapValues.js', | ||
|
||
// ESM, but uses `process.env.NODE_ENV` | ||
'tiny-invariant', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters