Skip to content

Commit

Permalink
Merge pull request #17174 from storybookjs/17128-fix-process-env-assi…
Browse files Browse the repository at this point in the history
…gnment

Core: Fix process.env assignment
  • Loading branch information
shilman committed Jan 10, 2022
1 parent 72a6d69 commit 2bc5614
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/react-ts/.env
@@ -0,0 +1 @@
FOO=bar
7 changes: 7 additions & 0 deletions examples/react-ts/src/button.stories.tsx
Expand Up @@ -27,6 +27,13 @@ export const StoryNoRender = {
args: { label: 'magic!' },
};

export const ProcessEnv = {
args: { label: process.env.FOO },
play: () => {
process.env.BAZ = 'moo';
},
};

export const StoryWithPlay = {
args: { label: 'play' },
play: () => {
Expand Down
8 changes: 6 additions & 2 deletions lib/core-common/src/utils/envs.ts
Expand Up @@ -59,8 +59,12 @@ export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string
'process.env.XSTORYBOOK_EXAMPLE_APP': '""',
}
);
// support destructuring like
// FIXME: something like this is necessary to support destructuring like:
//
// const { foo } = process.env;
envs['process.env'] = JSON.stringify(raw);
//
// However, it also means that process.env.foo = 'bar' will fail, so removing this:
//
// envs['process.env'] = JSON.stringify(raw);
return envs;
};

0 comments on commit 2bc5614

Please sign in to comment.