From b14c8f3134e9a40946e3385a5661b86b325b0e06 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Wed, 19 May 2021 23:07:20 +0200 Subject: [PATCH 1/4] Log npm_execpath --- bin/tasks/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/tasks/build.js b/bin/tasks/build.js index 026d98447..af5621d25 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -36,6 +36,7 @@ export const setSpawnParams = async (ctx) => { const isJsPath = npmExecFile && /\.m?js$/.test(npmExecFile); const isYarn = npmExecFile && npmExecFile.includes('yarn'); const isNpx = npmExecFile && npmExecFile.includes('npx'); + ctx.log.debug(`npm_execpath: ${npmExecPath}`); const client = isYarn ? 'yarn' : 'npm'; const { stdout } = await execa(client, ['--version']); From c349994e877fc1695a818c29e0009ed7e0efe9b2 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Wed, 19 May 2021 23:07:38 +0200 Subject: [PATCH 2/4] Drop preferLocal spawn option --- bin/tasks/build.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/tasks/build.js b/bin/tasks/build.js index af5621d25..5ee61c26c 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -56,10 +56,7 @@ export const setSpawnParams = async (ctx) => { ctx.git.changedFiles && webpackStatsSupported && '--webpack-stats-json', ctx.git.changedFiles && webpackStatsSupported && ctx.sourceDir, ].filter(Boolean), - spawnOptions: { - preferLocal: true, - localDir: path.resolve('node_modules/.bin'), - }, + spawnOptions: {}, }; }; From 7c11133ab1a57ef0852f75a824c8f33281d11783 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Wed, 19 May 2021 23:48:16 +0200 Subject: [PATCH 3/4] Log nodeVersion --- bin/tasks/build.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/tasks/build.js b/bin/tasks/build.js index 5ee61c26c..87954d11b 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -8,6 +8,8 @@ import { createTask, transitionTo } from '../lib/tasks'; import buildFailed from '../ui/messages/errors/buildFailed'; import { failed, initial, pending, skipped, success } from '../ui/tasks/build'; +const trimOutput = ({ stdout }) => stdout && stdout.toString().trim(); + export const setSourceDir = async (ctx) => { if (ctx.options.outputDir) { ctx.sourceDir = ctx.options.outputDir; @@ -36,15 +38,15 @@ export const setSpawnParams = async (ctx) => { const isJsPath = npmExecFile && /\.m?js$/.test(npmExecFile); const isYarn = npmExecFile && npmExecFile.includes('yarn'); const isNpx = npmExecFile && npmExecFile.includes('npx'); - ctx.log.debug(`npm_execpath: ${npmExecPath}`); const client = isYarn ? 'yarn' : 'npm'; - const { stdout } = await execa(client, ['--version']); - const clientVersion = stdout && stdout.toString().trim(); + const clientVersion = await execa(client, ['--version']).then(trimOutput); + const nodeVersion = await execa('node', ['--version']).then(trimOutput); ctx.spawnParams = { client, clientVersion, + nodeVersion, platform: process.platform, command: (!isNpx && (isJsPath ? process.execPath : npmExecPath)) || 'npm', clientArgs: !isNpx && isJsPath ? [npmExecPath, 'run'] : ['run', '--silent'], From f0d2bdacedc95fe675ab81b874980fa13f700232 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Thu, 20 May 2021 00:20:02 +0200 Subject: [PATCH 4/4] Log spawnParams on build failed and drop spawnOptions altogether --- bin/tasks/build.js | 8 ++------ bin/ui/messages/errors/buildFailed.js | 3 ++- bin/ui/messages/errors/buildFailed.stories.js | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bin/tasks/build.js b/bin/tasks/build.js index 87954d11b..1c8149a0e 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -58,7 +58,6 @@ export const setSpawnParams = async (ctx) => { ctx.git.changedFiles && webpackStatsSupported && '--webpack-stats-json', ctx.git.changedFiles && webpackStatsSupported && ctx.sourceDir, ].filter(Boolean), - spawnOptions: {}, }; }; @@ -74,13 +73,10 @@ export const buildStorybook = async (ctx) => { }); try { - const { command, clientArgs, scriptArgs, spawnOptions } = ctx.spawnParams; + const { command, clientArgs, scriptArgs } = ctx.spawnParams; ctx.log.debug('Using spawnParams:', JSON.stringify(ctx.spawnParams, null, 2)); await Promise.race([ - execa(command, [...clientArgs, ...scriptArgs], { - stdio: [null, logFile, logFile], - ...spawnOptions, - }), + execa(command, [...clientArgs, ...scriptArgs], { stdio: [null, logFile, logFile] }), timeoutAfter(ctx.env.STORYBOOK_BUILD_TIMEOUT), ]); } catch (e) { diff --git a/bin/ui/messages/errors/buildFailed.js b/bin/ui/messages/errors/buildFailed.js index 21a24be9e..08fe2bc69 100644 --- a/bin/ui/messages/errors/buildFailed.js +++ b/bin/ui/messages/errors/buildFailed.js @@ -5,7 +5,7 @@ import dedent from 'ts-dedent'; import { info } from '../../components/icons'; import link from '../../components/link'; -export default ({ options, buildLogFile }, { message }, buildLog) => { +export default ({ options, buildLogFile, spawnParams }, { message }, buildLog) => { const { buildScriptName } = options; const lines = buildLog.split(EOL).filter((line) => line && !line.startsWith('')); @@ -20,6 +20,7 @@ export default ({ options, buildLogFile }, { message }, buildLog) => { )} `), message, + chalk`${info} Spawn settings:\n{dim ${JSON.stringify(spawnParams, null, 2)}}`, chalk`${info} Storybook build output:\n{dim ${buildLogFile}}`, lines.join(`\n`), ].join('\n\n'); diff --git a/bin/ui/messages/errors/buildFailed.stories.js b/bin/ui/messages/errors/buildFailed.stories.js index 0f9eb0861..a9b388afb 100644 --- a/bin/ui/messages/errors/buildFailed.stories.js +++ b/bin/ui/messages/errors/buildFailed.stories.js @@ -4,6 +4,20 @@ export default { title: 'CLI/Messages/Errors', }; +const spawnParams = { + client: 'npm', + clientVersion: '7.11.2', + platform: 'darwin', + command: '/path/to/node', + clientArgs: ['/path/to/npm-cli.js', 'run'], + scriptArgs: [ + 'build-storybook', + '--', + '--output-dir', + '/var/folders/h3/ff9kk23958l99z2qbzfjdlxc0000gn/T/chromatic-10717MxArPfgMkIgp', + ].filter(Boolean), +}; + const buildLog = ` info @storybook/react v6.1.0-alpha.33 info @@ -43,6 +57,7 @@ export const BuildFailed = () => { options: { buildScriptName: 'build:storybook' }, buildLogFile: '/path/to/project/build-storybook.log', + spawnParams, }, { message: 'Command failed with exit code 1' }, buildLog