Skip to content

Commit

Permalink
Prefer using npm_execpath when spawning Yarn (#68673) (#68696)
Browse files Browse the repository at this point in the history
Prevents instances where an incorrect version of Yarn is used from a
parent directory containing node_modules.

Signed-off-by: Tyler Smalley <[email protected]>
  • Loading branch information
Tyler Smalley authored Jun 9, 2020
1 parent 73d30d9 commit 8eb064c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55324,6 +55324,7 @@ __webpack_require__.r(__webpack_exports__);
* under the License.
*/

const YARN_EXEC = process.env.npm_execpath || 'yarn';

/**
* Install all dependencies in the given directory
Expand All @@ -55332,7 +55333,7 @@ async function installInDir(directory, extraArgs = []) {
const options = ['install', '--non-interactive', ...extraArgs]; // We pass the mutex flag to ensure only one instance of yarn runs at any
// given time (e.g. to avoid conflicts).

await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])('yarn', options, {
await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])(YARN_EXEC, options, {
cwd: directory
});
}
Expand All @@ -55344,7 +55345,7 @@ async function runScriptInPackage(script, args, pkg) {
const execOpts = {
cwd: pkg.path
};
await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])('yarn', ['run', script, ...args], execOpts);
await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])(YARN_EXEC, ['run', script, ...args], execOpts);
}
/**
* Run script in the given directory
Expand All @@ -55359,15 +55360,15 @@ function runScriptInPackageStreaming({
const execOpts = {
cwd: pkg.path
};
return Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawnStreaming"])('yarn', ['run', script, ...args], execOpts, {
return Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawnStreaming"])(YARN_EXEC, ['run', script, ...args], execOpts, {
prefix: pkg.name,
debug
});
}
async function yarnWorkspacesInfo(directory) {
const {
stdout
} = await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])('yarn', ['--json', 'workspaces', 'info'], {
} = await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])(YARN_EXEC, ['--json', 'workspaces', 'info'], {
cwd: directory,
stdio: 'pipe'
});
Expand Down
10 changes: 6 additions & 4 deletions packages/kbn-pm/src/utils/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import { spawn, spawnStreaming } from './child_process';
import { Project } from './project';

const YARN_EXEC = process.env.npm_execpath || 'yarn';

interface WorkspaceInfo {
location: string;
workspaceDependencies: string[];
Expand All @@ -37,7 +39,7 @@ export async function installInDir(directory: string, extraArgs: string[] = [])

// We pass the mutex flag to ensure only one instance of yarn runs at any
// given time (e.g. to avoid conflicts).
await spawn('yarn', options, {
await spawn(YARN_EXEC, options, {
cwd: directory,
});
}
Expand All @@ -50,7 +52,7 @@ export async function runScriptInPackage(script: string, args: string[], pkg: Pr
cwd: pkg.path,
};

await spawn('yarn', ['run', script, ...args], execOpts);
await spawn(YARN_EXEC, ['run', script, ...args], execOpts);
}

/**
Expand All @@ -71,14 +73,14 @@ export function runScriptInPackageStreaming({
cwd: pkg.path,
};

return spawnStreaming('yarn', ['run', script, ...args], execOpts, {
return spawnStreaming(YARN_EXEC, ['run', script, ...args], execOpts, {
prefix: pkg.name,
debug,
});
}

export async function yarnWorkspacesInfo(directory: string): Promise<WorkspacesInfo> {
const { stdout } = await spawn('yarn', ['--json', 'workspaces', 'info'], {
const { stdout } = await spawn(YARN_EXEC, ['--json', 'workspaces', 'info'], {
cwd: directory,
stdio: 'pipe',
});
Expand Down

0 comments on commit 8eb064c

Please sign in to comment.