Skip to content

Commit

Permalink
Merge pull request #22517 from storybookjs/fix/upgrade-precheck-failure
Browse files Browse the repository at this point in the history
CLI: Fix storybook upgrade precheckfailure object
  • Loading branch information
yannbf authored and shilman committed May 12, 2023
1 parent 5d27e3a commit fcbe6e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
27 changes: 20 additions & 7 deletions code/lib/cli/src/automigrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export const automigrate = async ({
renderer: rendererPackage,
skipInstall,
hideMigrationSummary = false,
}: FixOptions = {}) => {
}: FixOptions = {}): Promise<{
fixResults: Record<string, FixStatus>;
preCheckFailure: PreCheckFailure;
}> => {
if (list) {
logAvailableMigrations();
return null;
Expand All @@ -79,7 +82,7 @@ export const automigrate = async ({

logger.info('🔎 checking possible migrations..');

const { fixResults, fixSummary } = await runFixes({
const { fixResults, fixSummary, preCheckFailure } = await runFixes({
fixes,
useNpm,
pkgMgr,
Expand Down Expand Up @@ -117,7 +120,7 @@ export const automigrate = async ({

cleanup();

return fixResults;
return { fixResults, preCheckFailure };
};

export async function runFixes({
Expand All @@ -138,7 +141,11 @@ export async function runFixes({
userSpecifiedConfigDir?: string;
rendererPackage?: string;
skipInstall?: boolean;
}) {
}): Promise<{
preCheckFailure?: PreCheckFailure;
fixResults: Record<FixId, FixStatus>;
fixSummary: FixSummary;
}> {
if (useNpm) {
useNpmWarning();
// eslint-disable-next-line no-param-reassign
Expand All @@ -147,6 +154,9 @@ export async function runFixes({

const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr });

const fixResults = {} as Record<FixId, FixStatus>;
const fixSummary: FixSummary = { succeeded: [], failed: {}, manual: [], skipped: [] };

const {
configDir: inferredConfigDir,
mainConfig: mainConfigPath,
Expand All @@ -160,6 +170,8 @@ export async function runFixes({
🤔 Are you running automigrate from your project directory? Please specify your Storybook config directory with the --config-dir flag.
`);
return {
fixResults,
fixSummary,
preCheckFailure: PreCheckFailure.UNDETECTED_SB_VERSION,
};
}
Expand All @@ -175,6 +187,8 @@ export async function runFixes({
)} so the automigrations will be skipped. You might be running this command in a monorepo or a non-standard project structure. If that is the case, please rerun this command by specifying the path to your Storybook config directory via the --config-dir option.`
);
return {
fixResults,
fixSummary,
preCheckFailure: PreCheckFailure.MAINJS_NOT_FOUND,
};
}
Expand All @@ -186,13 +200,12 @@ export async function runFixes({
logger.info('Please fix the error and try again.');

return {
fixResults,
fixSummary,
preCheckFailure: PreCheckFailure.MAINJS_EVALUATION,
};
}

const fixResults = {} as Record<FixId, FixStatus>;
const fixSummary: FixSummary = { succeeded: [], failed: {}, manual: [], skipped: [] };

for (let i = 0; i < fixes.length; i += 1) {
const f = fixes[i] as Fix;
let result;
Expand Down
5 changes: 2 additions & 3 deletions code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,11 @@ export const doUpgrade = async ({
checkVersionConsistency();
automigrationResults = await automigrate({ dryRun, yes, packageManager: pkgMgr, configDir });
}

if (!options.disableTelemetry) {
const afterVersion = await getStorybookCoreVersion();
const { preCheckFailure, ...results } = automigrationResults || {};
const { preCheckFailure, fixResults } = automigrationResults || {};
const automigrationTelemetry = {
automigrationResults: preCheckFailure ? null : results,
automigrationResults: preCheckFailure ? null : fixResults,
automigrationPreCheckFailure: preCheckFailure || null,
};
telemetry('upgrade', {
Expand Down

0 comments on commit fcbe6e3

Please sign in to comment.