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: Fix storybook upgrade precheckfailure object #22517

Merged
merged 1 commit into from
May 12, 2023
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
27 changes: 20 additions & 7 deletions code/lib/cli/src/automigrate/index.ts
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
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