Skip to content

Commit

Permalink
Merge pull request #948 from chromaui/tom/ap-4362-cli-should-tell-sb8…
Browse files Browse the repository at this point in the history
…-users-to-use-stats-json

Tell SB8 users to pass `--stats-json` rather than `--webpack-stats-json`
  • Loading branch information
ghengeveld committed Mar 13, 2024
2 parents 0bde8db + d0c3ff6 commit 419e60d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions node-src/tasks/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { uploadBuild } from '../lib/upload';
import { getFileHashes } from '../lib/getFileHashes';
import { waitForSentinel } from '../lib/waitForSentinel';
import { checkStorybookBaseDir } from '../lib/checkStorybookBaseDir';
import semver from 'semver';

interface PathSpec {
pathname: string;
Expand Down Expand Up @@ -109,8 +110,12 @@ export const traceChangedFiles = async (ctx: Context, task: Task) => {
if (!ctx.turboSnap || ctx.turboSnap.unavailable) return;
if (!ctx.git.changedFiles) return;
if (!ctx.fileInfo.statsPath) {
// If we don't know the SB version, we should assume we don't support `--stats-json`
const nonLegacyStatsSupported =
ctx.storybook?.version && semver.gte(semver.coerce(ctx.storybook.version), '8.0.0');

ctx.turboSnap.bailReason = { missingStatsFile: true };
throw new Error(missingStatsFile());
throw new Error(missingStatsFile({ legacy: !nonLegacyStatsSupported }));
}

transitionTo(tracing)(ctx, task);
Expand Down Expand Up @@ -158,7 +163,9 @@ export const traceChangedFiles = async (ctx: Context, task: Task) => {
);
if (onlyStoryFiles) {
// Escape special characters in the filename so it does not conflict with picomatch
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) => key.split(specialCharsRegex).join('\\'));
ctx.onlyStoryFiles = Object.keys(onlyStoryFiles).map((key) =>
key.split(specialCharsRegex).join('\\')
);

if (!ctx.options.interactive) {
if (!ctx.options.traceChanged) {
Expand Down
4 changes: 3 additions & 1 deletion node-src/ui/messages/errors/missingStatsFile.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export default {
title: 'CLI/Messages/Errors',
};

export const MissingStatsFile = () => missingStatsFile();
export const MissingStatsFile = () => missingStatsFile({ legacy: false });

export const MissingStatsFileLegacy = () => missingStatsFile({ legacy: true });
6 changes: 4 additions & 2 deletions node-src/ui/messages/errors/missingStatsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { dedent } from 'ts-dedent';

import { error } from '../../components/icons';

export default () =>
export default ({ legacy }: { legacy: boolean }) =>
dedent(chalk`
${error} {bold TurboSnap disabled due to missing stats file}
Did not find {bold preview-stats.json} in your built Storybook.
Make sure you pass {bold --webpack-stats-json} when building your Storybook.
Make sure you pass {bold ${
legacy ? `--webpack-stats-json` : `--stats-json`
}} when building your Storybook.
`);

0 comments on commit 419e60d

Please sign in to comment.