Skip to content

Commit

Permalink
Use --stats-json flag for SB 8.0.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed Sep 12, 2024
1 parent 4a04431 commit bef1923
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions node-src/tasks/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ describe('setBuildCommand', () => {
'Storybook version 6.2.0 or later is required to use the --only-changed flag'
);
});

it('uses the correct flag for webpack stats for >= 8.0.0', async () => {
getCliCommand.mockReturnValue(Promise.resolve('npm run build:storybook'));

const ctx = {
sourceDir: './source-dir/',
options: { buildScriptName: 'build:storybook' },
storybook: { version: '8.0.0' },
git: { changedFiles: ['./index.js'] },
} as any;
await setBuildCommand(ctx);

expect(getCliCommand).toHaveBeenCalledWith(
expect.anything(),
['build:storybook', '--output-dir=./source-dir/', '--stats-json=./source-dir/'],
{ programmatic: true }
);
expect(ctx.buildCommand).toEqual('npm run build:storybook');
});
});

describe('buildStorybook', () => {
Expand Down
7 changes: 6 additions & 1 deletion node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ export const setBuildCommand = async (ctx: Context) => {
? semver.gte(semver.coerce(ctx.storybook.version), '6.2.0')
: true;

const webpackStatsFlag =
webpackStatsSupported && semver.gte(semver.coerce(ctx.storybook.version), '8.0.0')
? '--stats-json'
: '--webpack-stats-json';

if (ctx.git.changedFiles && !webpackStatsSupported) {
ctx.log.warn('Storybook version 6.2.0 or later is required to use the --only-changed flag');
}

const buildCommandOptions = [
`--output-dir=${ctx.sourceDir}`,
ctx.git.changedFiles && webpackStatsSupported && `--webpack-stats-json=${ctx.sourceDir}`,
ctx.git.changedFiles && webpackStatsSupported && `${webpackStatsFlag}=${ctx.sourceDir}`,
].filter(Boolean);

if (isE2EBuild(ctx.options)) {
Expand Down

0 comments on commit bef1923

Please sign in to comment.