Skip to content

Commit

Permalink
Merge pull request #20606 from storybookjs/cli-repro-envs
Browse files Browse the repository at this point in the history
fix: cli repros creation not working on windows
  • Loading branch information
ndelangen authored Jan 13, 2023
2 parents 94bdf09 + e9b0fa1 commit dd78738
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions code/lib/cli/src/repro-generators/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface Parameters {
typescript?: boolean;
/** Merge configurations to main.js before running the tests */
mainOverrides?: Partial<StorybookConfig> & Record<string, any>;
/** Environment variables to inject while running generator */
envs?: Record<string, string>;
}

const fromDeps = (...args: string[]): string =>
Expand All @@ -45,11 +47,12 @@ export const cra: Parameters = {
version: 'latest',
generator: [
// Force npm otherwise we have a mess between Yarn 1, Yarn 2 and NPM
'npm_config_user_agent=npm npx -p create-react-app@{{version}} create-react-app {{appName}}',
'npx -p create-react-app@{{version}} create-react-app {{appName}}',
'cd {{appName}}',
'echo "FAST_REFRESH=true" > .env',
'echo "SKIP_PREFLIGHT_CHECK=true" > .env',
].join(' && '),
envs: { npm_config_user_agent: 'npm' },
};

export const cra_typescript: Parameters = {
Expand All @@ -58,8 +61,9 @@ export const cra_typescript: Parameters = {
version: 'latest',
generator: [
// Force npm otherwise we have a mess between Yarn 1, Yarn 2 and NPM
'npm_config_user_agent=npm npx -p create-react-app@{{version}} create-react-app {{appName}} --template typescript',
'npx -p create-react-app@{{version}} create-react-app {{appName}} --template typescript',
].join(' && '),
envs: { npm_config_user_agent: 'npm' },
};

export const react: Parameters = {
Expand Down
6 changes: 4 additions & 2 deletions code/lib/cli/src/repro-generators/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface Parameters {
}[];
/** Add typescript dependency and creates a tsconfig.json file */
typescript?: boolean;
/** Environment variables to inject while running generator */
envs?: Record<string, string>;
}

interface Configuration {
Expand Down Expand Up @@ -165,13 +167,13 @@ const configureYarn2ForE2E = async ({ cwd }: Options) => {
);
};

const generate = async ({ cwd, name, appName, version, generator }: Options) => {
const generate = async ({ cwd, name, appName, version, generator, envs }: Options) => {
// eslint-disable-next-line @typescript-eslint/no-shadow
const command = generator.replace(/{{appName}}/g, appName).replace(/{{version}}/g, version);

await exec(
command,
{ cwd },
{ cwd, env: { ...process.env, ...envs } },
{
startMessage: `🏗 Bootstrapping ${name} project (this might take a few minutes)`,
errorMessage: `🚨 Bootstrapping ${name} failed`,
Expand Down

0 comments on commit dd78738

Please sign in to comment.