diff --git a/bin/tasks/build.js b/bin/tasks/build.js index e9baa56e2..37d6073a8 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import path from 'path'; import semver from 'semver'; import tmp from 'tmp-promise'; -import yarnOrNpm, { hasYarn } from 'yarn-or-npm'; +import yarnOrNpm, { spawn } from 'yarn-or-npm'; import { createTask, transitionTo } from '../lib/tasks'; import buildFailed from '../ui/messages/errors/buildFailed'; @@ -26,14 +26,18 @@ export const setSpawnParams = (ctx) => { if (ctx.git.changedFiles && !webpackStatsSupported) { ctx.log.warn('Storybook version 6.2.0 or later is required to use the --only-changed flag'); } + const client = yarnOrNpm(); + const { stdout } = spawn.sync(['--version']); + const clientVersion = stdout && stdout.toString().trim(); ctx.spawnParams = { - client: yarnOrNpm(), + client, + clientVersion, platform: process.platform, - command: yarnOrNpm(), + command: client, clientArgs: ['run', '--silent'], scriptArgs: [ ctx.options.buildScriptName, - hasYarn() ? '' : '--', + client === 'yarn' ? '' : '--', '--output-dir', ctx.sourceDir, ctx.git.changedFiles && webpackStatsSupported && '--webpack-stats-json', diff --git a/bin/ui/messages/errors/fatalError.stories.js b/bin/ui/messages/errors/fatalError.stories.js index 9530f48fb..873bfc363 100644 --- a/bin/ui/messages/errors/fatalError.stories.js +++ b/bin/ui/messages/errors/fatalError.stories.js @@ -30,6 +30,18 @@ const context = { options: { buildScriptName: 'build:storybook', }, + spawnParams: { + client: 'npm', + clientVersion: '7.11.2', + platform: 'darwin', + command: 'npm', + clientArgs: ['run', '--silent'], + scriptArgs: ['build:storybook', '--', '--output-dir', '/tmp/path/to/output'], + spawnOptions: { + preferLocal: true, + localDir: '/path/to/node_modules/.bin', + }, + }, exitCode: 255, build: { id: '5ec5069ae0d35e0022b6a9cc',