Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop spawnOptions, including preferLocal: true #350

Merged
merged 4 commits into from May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions bin/tasks/build.js
Expand Up @@ -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;
Expand Down Expand Up @@ -38,12 +40,13 @@ export const setSpawnParams = async (ctx) => {
const isNpx = npmExecFile && npmExecFile.includes('npx');

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'],
Expand All @@ -55,10 +58,6 @@ 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'),
},
};
};

Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion bin/ui/messages/errors/buildFailed.js
Expand Up @@ -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('<s>'));

Expand All @@ -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');
Expand Down
15 changes: 15 additions & 0 deletions bin/ui/messages/errors/buildFailed.stories.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down