Skip to content

Commit

Permalink
Merge pull request #296 from amacneil/detectyarn
Browse files Browse the repository at this point in the history
Support yarn execpath
  • Loading branch information
ghengeveld committed Mar 11, 2021
2 parents 5b67483 + 2f084fd commit e58364c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/tasks/build.js
Expand Up @@ -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'],
Expand Down
11 changes: 11 additions & 0 deletions bin/tasks/build.test.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit e58364c

Please sign in to comment.