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

CLI: Only run useful automigrations on init #21203

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion code/lib/cli/src/automigrate/fixes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { bareMdxStoriesGlob } from './bare-mdx-stories-glob';

export * from '../types';

export const fixes: Fix[] = [
export const allFixes: Fix[] = [
nodeJsRequirement,
cra5,
webpack5,
Expand All @@ -39,3 +39,5 @@ export const fixes: Fix[] = [
addReact,
missingBabelRc,
];

export const initFixes: Fix[] = [missingBabelRc];
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../js-package-manager';

import type { Fix } from './fixes';
import { fixes as allFixes } from './fixes';
import { allFixes } from './fixes';
import { cleanLog } from './helpers/cleanLog';

const logger = console;
Expand Down Expand Up @@ -50,6 +50,7 @@ type FixId = string;
interface FixOptions {
fixId?: FixId;
list?: boolean;
fixes?: Fix[];
yes?: boolean;
dryRun?: boolean;
useNpm?: boolean;
Expand Down Expand Up @@ -89,6 +90,7 @@ const logAvailableMigrations = () => {

export const automigrate = async ({
fixId,
fixes: inputFixes,
dryRun,
yes,
useNpm,
Expand All @@ -109,7 +111,8 @@ export const automigrate = async ({
pkgMgr = 'npm';
}

const fixes = fixId ? allFixes.filter((f) => f.id === fixId) : allFixes;
const selectedFixes = inputFixes || allFixes;
const fixes = fixId ? selectedFixes.filter((f) => f.id === fixId) : selectedFixes;

if (fixId && fixes.length === 0) {
logger.info(`📭 No migrations found for ${chalk.magenta(fixId)}.`);
Expand Down
7 changes: 6 additions & 1 deletion code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { JsPackageManagerFactory, useNpmWarning } from './js-package-manager';
import type { NpmOptions } from './NpmOptions';
import { automigrate } from './automigrate';
import type { CommandOptions } from './generators/types';
import { initFixes } from './automigrate/fixes';

const logger = console;

Expand Down Expand Up @@ -339,7 +340,11 @@ async function doInitiate(options: CommandOptions, pkg: PackageJson): Promise<vo
}

if (projectType !== ProjectType.REACT_NATIVE) {
await automigrate({ yes: options.yes || process.env.CI === 'true', packageManager: pkgMgr });
await automigrate({
yes: options.yes || process.env.CI === 'true',
packageManager: pkgMgr,
fixes: initFixes,
});
}

logger.log('\nFor more information visit:', chalk.cyan('https://storybook.js.org'));
Expand Down