From a39524c6f560abcdd8956721c87264b59ca65948 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 5 Feb 2020 14:18:10 -0700 Subject: [PATCH] Fix compatibility with yarn 1.22.0 (#56917) * Revert "force yarn 1.21.1 until we can handle invalid output of 1.22.0 (#56914)" This reverts commit 5686010b46daa5c0acc48b3b3ade3f0ea246dd6c. * move the --json argument before `workspaces` so it still works * update kbn/pm dist (cherry picked from commit 12de6a8459c433628beec4a2c49c23f4cf574ecf) --- packages/kbn-pm/dist/index.js | 12 +++++++++--- packages/kbn-pm/src/utils/scripts.ts | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/kbn-pm/dist/index.js b/packages/kbn-pm/dist/index.js index d74379adc113e..85d045c57bb1f 100644 --- a/packages/kbn-pm/dist/index.js +++ b/packages/kbn-pm/dist/index.js @@ -56565,12 +56565,18 @@ function runScriptInPackageStreaming(script, args, pkg) { }); } async function yarnWorkspacesInfo(directory) { - const workspacesInfo = await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])('yarn', ['workspaces', 'info', '--json'], { + const { + stdout + } = await Object(_child_process__WEBPACK_IMPORTED_MODULE_0__["spawn"])('yarn', ['--json', 'workspaces', 'info'], { cwd: directory, stdio: 'pipe' }); - const stdout = JSON.parse(workspacesInfo.stdout); - return JSON.parse(stdout.data); + + try { + return JSON.parse(JSON.parse(stdout).data); + } catch (error) { + throw new Error(`'yarn workspaces info --json' produced unexpected output: \n${stdout}`); + } } /***/ }), diff --git a/packages/kbn-pm/src/utils/scripts.ts b/packages/kbn-pm/src/utils/scripts.ts index f12aeddec9163..009efa1285c0c 100644 --- a/packages/kbn-pm/src/utils/scripts.ts +++ b/packages/kbn-pm/src/utils/scripts.ts @@ -67,11 +67,14 @@ export function runScriptInPackageStreaming(script: string, args: string[], pkg: } export async function yarnWorkspacesInfo(directory: string): Promise { - const workspacesInfo = await spawn('yarn', ['workspaces', 'info', '--json'], { + const { stdout } = await spawn('yarn', ['--json', 'workspaces', 'info'], { cwd: directory, stdio: 'pipe', }); - const stdout = JSON.parse(workspacesInfo.stdout); - return JSON.parse(stdout.data); + try { + return JSON.parse(JSON.parse(stdout).data); + } catch (error) { + throw new Error(`'yarn workspaces info --json' produced unexpected output: \n${stdout}`); + } }