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

Revert "Use --stats-json flag for SB 8.0.0+" #1058

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions node-src/tasks/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,43 +113,6 @@ 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');
});

it('uses the old flag when it storybook version is undetected', async () => {
getCliCommand.mockReturnValue(Promise.resolve('npm run build:storybook'));

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

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

describe('buildStorybook', () => {
Expand Down
22 changes: 6 additions & 16 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,19 @@ export const setSourceDir = async (ctx: Context) => {
}
};

// Storybook 8.0.0 deprecated --webpack-stats-json in favor of --stats-json.
const getStatsFlag = (ctx: Context) => {
return ctx?.storybook?.version && semver.gte(semver.coerce(ctx.storybook.version), '8.0.0')
? '--stats-json'
: '--webpack-stats-json';
};

const isStatsFlagSupported = (ctx: Context) => {
return ctx.storybook && ctx.storybook.version
? semver.gte(semver.coerce(ctx.storybook.version), '6.2.0')
: true;
};

export const setBuildCommand = async (ctx: Context) => {
const statsFlagSupported = isStatsFlagSupported(ctx);
const webpackStatsSupported =
ctx.storybook && ctx.storybook.version
? semver.gte(semver.coerce(ctx.storybook.version), '6.2.0')
: true;

if (ctx.git.changedFiles && !statsFlagSupported) {
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 && statsFlagSupported && `${getStatsFlag(ctx)}=${ctx.sourceDir}`,
ctx.git.changedFiles && webpackStatsSupported && `--webpack-stats-json=${ctx.sourceDir}`,
].filter(Boolean);

ctx.buildCommand = await (isE2EBuild(ctx.options)
Expand Down
4 changes: 2 additions & 2 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export interface Context {
matchesBranch?: (glob: boolean | string) => boolean;
packageMetadataChanges?: { changedFiles: string[]; commit: string }[];
};
storybook?: {
version?: string;
storybook: {
version: string;
configDir: string;
staticDir: string[];
viewLayer: string;
Expand Down
Loading