Skip to content

Commit

Permalink
fix(storybook): use target project instead of default unless otherwis…
Browse files Browse the repository at this point in the history
…e specified
  • Loading branch information
mandarini committed Jan 14, 2022
1 parent 37fd829 commit 7a28a00
Showing 1 changed file with 61 additions and 12 deletions.
73 changes: 61 additions & 12 deletions packages/storybook/src/executors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,66 @@ export function resolveCommonStorybookOptionMapper(

storybookOptions.angularBrowserTarget = targetString;
} else {
// to preserve the backwards compatibility for our users Nx resolves the
// default project just as Storybook used to before

const ws = new Workspaces(context.root);
const defaultProjectName = ws.calculateDefaultProjectName(
context.cwd,
context.workspace
);

buildProjectName = defaultProjectName;

let defaultProjectName;
let buildable = false;
if (context.projectName) {
buildable =
!!context?.workspace?.projects?.[context.projectName]?.targets?.build;
targetName = buildable ? 'build' : ':build-storybook';
buildProjectName = context.projectName;

logger.warn(
`
No projectBuildConfig was provided. Nx will use the current project
to read build configuration from.
If you want to change that, you can use the "--projectBuildConfig" flag like this:
nx storybook <YOUR-PROJECT-NAME> --projectBuildConfig=<YOUR-PROJECT-NAME>${
buildable ? '' : ':build-storybook'
}
Alternatively, in your project configuration, under the "storybook" target options, you can
set the "projectBuildConfig" property to the name of the project of which you want to use
the build configuration for Storybook.
`
);
} else {
// I guess this will never be reached since context.projectName is always set?
// Then why is it optional?

// to preserve the backwards compatibility for our users Nx resolves the
// default project just as Storybook used to before
const ws = new Workspaces(context.root);
defaultProjectName = ws.calculateDefaultProjectName(
context.cwd,
context.workspace
);
if (defaultProjectName) {
buildProjectName = defaultProjectName;
} else {
logger.error(
`
Could not find project configuration for Storybook.
You can do one of the following to fix this:
1. Specify a "defaultProject" in your nx.json
2. Specify a project in the command line using the "--projectBuildConfig" flag like this:
nx storybook <YOUR-PROJECT-NAME> --projectBuildConfig=<YOUR-PROJECT-NAME>${
buildable ? '' : ':build-storybook'
}
3. In your project configuration, under the "storybook" target options,
set the "projectBuildConfig" property to the name of the project of which you want to use
the build configuration for Storybook.
`
);
return new Error();
}
}
targetOptions = readTargetOptions(
{
project: defaultProjectName,
Expand All @@ -224,12 +273,12 @@ export function resolveCommonStorybookOptionMapper(
},
context
);

storybookOptions.angularBrowserTarget = normalizeTargetString(
defaultProjectName,
targetName
);
}

const project = context.workspace.projects[buildProjectName];

const angularDevkitCompatibleLogger = {
Expand Down

0 comments on commit 7a28a00

Please sign in to comment.