Skip to content

Commit

Permalink
Inform the user about potentially unintentional use of buildScriptName
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter van Vliet (WOU) authored and Wouter van Vliet (WOU) committed Mar 19, 2024
1 parent d41ae50 commit 9f4313a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
23 changes: 20 additions & 3 deletions node-src/lib/getOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,27 @@ describe('getOptions', () => {
});
});

it('allows you to pass both a build script and a directory', async () => {
await expect(() =>
getOptions(getContext(['-b', 'build:storybook', '--storybook-build-dir', '/tmp/dir']))
it('allows you to pass both a build script and a directory', () => {
const context = getContext(['-b', 'build:storybook', '--storybook-build-dir', '/tmp/dir'])
const log = context.log as unknown as TestLogger
expect(() =>
getOptions(context)
).not.toThrow()

expect(log.entries).to.include('Note: Both --build-script-name and --storybook-build-dir are specified as arguments, --build-script-name is ignored when using static storybook builds')
});

it('warns when both buildScriptName and storybookBuildDir are specified in configuration', () => {
const context = getContext([])
const log = context.log as unknown as TestLogger
expect(() =>
getOptions({...context, configuration: {
buildScriptName: 'other-build-script-name',
storybookBuildDir: '/tmp/storybook-prebuilt'
}})
).not.toThrow()

expect(log.entries).to.include('Both buildScriptName and storybookBuildDir are specified in configuration, buildScriptName is ignored when using static storybook builds')
});

it('allows you to specify the branch name', async () => {
Expand Down
15 changes: 14 additions & 1 deletion node-src/lib/getOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@ export default function getOptions({
process.env.NODE_ENV !== 'test',
};

const combinedCliOptions = {
...optionsFromFlags,
...extraOptions,
}

if (options.debug) {
log.setLevel('debug');
log.setInteractive(false);
}

if (combinedCliOptions.buildScriptName && combinedCliOptions.storybookBuildDir){
log.info('Both --build-script-name and --storybook-build-dir are specified as arguments, --build-script-name is ignored when using static storybook builds')
}

if (configuration && configuration.buildScriptName && configuration.storybookBuildDir) {
log.warn('Both buildScriptName and storybookBuildDir are specified in configuration, buildScriptName is ignored when using static storybook builds')
}

if (options.debug || options.uploadMetadata) {
// Implicitly enable these options unless they're already enabled or explicitly disabled
options.logFile = options.logFile ?? DEFAULT_LOG_FILE;
Expand Down Expand Up @@ -206,7 +219,6 @@ export default function getOptions({
}

const { storybookBuildDir } = options;
let { buildScriptName } = options;

// We can only have one of these arguments
const singularOpts = {
Expand Down Expand Up @@ -275,6 +287,7 @@ export default function getOptions({
}

const { scripts } = packageJson;
let { buildScriptName } = options;
if (typeof buildScriptName !== 'string') {
buildScriptName = 'build-storybook';
if (!scripts[buildScriptName]) {
Expand Down

0 comments on commit 9f4313a

Please sign in to comment.