From 9380ecfe1ac1cf452a64a3c51019f95cbe3f9462 Mon Sep 17 00:00:00 2001 From: Adrian Macneil Date: Wed, 3 Mar 2021 17:24:54 -0800 Subject: [PATCH] Support yarn execpath --- bin/tasks/build.js | 2 +- bin/tasks/build.test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/tasks/build.js b/bin/tasks/build.js index fcda2fd49..52737b9b6 100644 --- a/bin/tasks/build.js +++ b/bin/tasks/build.js @@ -27,7 +27,7 @@ export const setSpawnParams = (ctx) => { // Based on https://github.com/mysticatea/npm-run-all/blob/52eaf86242ba408dedd015f53ca7ca368f25a026/lib/run-task.js#L156-L174 const npmExecPath = process.env.npm_execpath; const isJsPath = typeof npmExecPath === 'string' && /\.m?js/.test(path.extname(npmExecPath)); - const isYarn = npmExecPath && path.basename(npmExecPath) === 'yarn.js'; + const isYarn = npmExecPath && /^yarn(\.js)?$/.test(path.basename(npmExecPath)); ctx.spawnParams = { command: (isJsPath ? process.execPath : npmExecPath) || 'npm', clientArgs: isJsPath ? [npmExecPath, 'run'] : ['run', '--silent'], diff --git a/bin/tasks/build.test.js b/bin/tasks/build.test.js index ad98b77ea..fbc1d7a76 100644 --- a/bin/tasks/build.test.js +++ b/bin/tasks/build.test.js @@ -41,6 +41,17 @@ describe('setSpawnParams', () => { scriptArgs: ['build:storybook', '--', '--output-dir', './source-dir/'], }); }); + + it('supports yarn', async () => { + process.env.npm_execpath = '/path/to/yarn'; + const ctx = { sourceDir: './source-dir/', options: { buildScriptName: 'build:storybook' } }; + await setSpawnParams(ctx); + expect(ctx.spawnParams).toEqual({ + command: '/path/to/yarn', + clientArgs: ['run', '--silent'], + scriptArgs: ['build:storybook', '--output-dir', './source-dir/'], + }); + }); }); describe('buildStorybook', () => {