From 48d9d51b398e12292f33e658baee90fc9b724018 Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Tue, 9 Jun 2020 12:11:53 -0700 Subject: [PATCH] Prefer using npm_execpath when spawning Yarn (#68673) Prevents instances where an incorrect version of Yarn is used from a parent directory containing node_modules. Signed-off-by: Tyler Smalley --- packages/kbn-pm/dist/index.js | 9 +++++---- packages/kbn-pm/src/utils/scripts.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/kbn-pm/dist/index.js b/packages/kbn-pm/dist/index.js index a6a5ea6efad68..ff62fac7d9f97 100644 --- a/packages/kbn-pm/dist/index.js +++ b/packages/kbn-pm/dist/index.js @@ -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 @@ -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 }); } @@ -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 @@ -55359,7 +55360,7 @@ 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 }); @@ -55367,7 +55368,7 @@ function runScriptInPackageStreaming({ 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' }); diff --git a/packages/kbn-pm/src/utils/scripts.ts b/packages/kbn-pm/src/utils/scripts.ts index 728ac4287b1ce..6b1dc729906f2 100644 --- a/packages/kbn-pm/src/utils/scripts.ts +++ b/packages/kbn-pm/src/utils/scripts.ts @@ -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[]; @@ -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, }); } @@ -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); } /** @@ -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 { - const { stdout } = await spawn('yarn', ['--json', 'workspaces', 'info'], { + const { stdout } = await spawn(YARN_EXEC, ['--json', 'workspaces', 'info'], { cwd: directory, stdio: 'pipe', });