Skip to content

Commit

Permalink
Enforce --output-dir with --build-command
Browse files Browse the repository at this point in the history
  • Loading branch information
codykaup committed Oct 24, 2024
1 parent 6c57be1 commit a1c1456
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 6 additions & 0 deletions node-src/lib/getOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ export default function getOptions(ctx: InitialContext): Options {
throw new Error(incompatibleOptions(['--build-script-name', '--build-command']));
}

// --build-command can put the built Storybook anywhere. Rather than reading through the value,
// we require `--output-dir` to avoid the issue.
if (potentialOptions.buildCommand && !potentialOptions.outputDir) {
throw new Error(dependentOption('--build-command', '--output-dir'));
}

if (
typeof potentialOptions.junitReport === 'string' &&
path.extname(potentialOptions.junitReport) !== '.xml'
Expand Down
2 changes: 1 addition & 1 deletion node-src/lib/parseArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function parseArguments(argv: string[]) {
Storybook options
--build-script-name, -b [name] The npm script that builds your Storybook we should take snapshots against. Use this if your Storybook build script is named differently. [build-storybook]
--build-command <command> The command that builds your Storybook we should take snapshots against. Use this if your Storybook build command does not exist in "scripts" of your package.json (like using NX).
--build-command <command> The command that builds your Storybook we should take snapshots against. Use this if your Storybook build command does not exist in "scripts" of your package.json (like using NX). Requires --output-dir.
--output-dir, -o <dirname> Relative path to target directory for building your Storybook, in case you want to preserve it. Otherwise a temporary directory is used if possible.
--storybook-build-dir, -d <dirname> If you have already built your Storybook, provide the path to the static build directory.
Expand Down
3 changes: 0 additions & 3 deletions node-src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export const setBuildCommand = async (ctx: Context) => {
const buildCommand = ctx.flags.buildCommand || ctx.options.buildCommand;

const buildCommandOptions = [
// NOTE: There is a bug in NX that outputs an invalid Storybook if the `--output-dir` flag is
// passed. Therefore, we need to skip that until it's fixed: https://github.com/nrwl/nx/issues/28594
// When that's fixed, we can remove the `!buildCommand &&` below.
!buildCommand && `--output-dir=${ctx.sourceDir}`,
ctx.git.changedFiles && webpackStatsSupported && `--webpack-stats-json=${ctx.sourceDir}`,
].filter((c): c is string => !!c);
Expand Down

0 comments on commit a1c1456

Please sign in to comment.