mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-01 05:05:25 +08:00
Support process.env destructuring
This commit is contained in:
parent
c48b52ef35
commit
c418258573
@ -42,15 +42,14 @@ export function loadEnvs(
|
||||
};
|
||||
}
|
||||
|
||||
/** @deprecated use `stringifyProcessEnvs` */
|
||||
export const stringifyEnvs = (raw: Record<string, string>): Record<string, string> =>
|
||||
Object.entries(raw).reduce<Record<string, string>>((acc, [key, value]) => {
|
||||
acc[key] = JSON.stringify(value);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string, string> =>
|
||||
Object.entries(raw).reduce<Record<string, string>>(
|
||||
export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string, string> => {
|
||||
const envs = Object.entries(raw).reduce<Record<string, string>>(
|
||||
(acc, [key, value]) => {
|
||||
acc[`process.env.${key}`] = JSON.stringify(value);
|
||||
return acc;
|
||||
@ -60,3 +59,8 @@ export const stringifyProcessEnvs = (raw: Record<string, string>): Record<string
|
||||
'process.env.XSTORYBOOK_EXAMPLE_APP': '""',
|
||||
}
|
||||
);
|
||||
// support destructuring like
|
||||
// const { foo } = process.env;
|
||||
envs['process.env'] = JSON.stringify(stringifyEnvs(raw));
|
||||
return envs;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user