Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix process.env assignment #17174

Merged
merged 1 commit into from Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
};