diff --git a/node_modules/@npmcli/promise-spawn/README.md b/node_modules/@npmcli/promise-spawn/README.md index 3b604f2a73398..b569948c9a111 100644 --- a/node_modules/@npmcli/promise-spawn/README.md +++ b/node_modules/@npmcli/promise-spawn/README.md @@ -45,13 +45,18 @@ Result or error will be decorated with the properties in the `extra` object. You can use this to attach some helpful info about _why_ the command is being run, if it makes sense for your use case. +If `stdio` is set to anything other than `'inherit'`, then the result/error +will be decorated with `stdout` and `stderr` values. If `stdioString` is +set to `true`, these will be strings. Otherwise they will be Buffer +objects. + Returned promise is decorated with the `stdin` stream if the process is set to pipe from `stdin`. Writing to this stream writes to the `stdin` of the spawned process. #### Options -- `stdioString` Boolean, default `false`. Return stdio/stderr output as +- `stdioString` Boolean, default `false`. Return stdout/stderr output as strings rather than buffers. - `cwd` String, default `process.cwd()`. Current working directory for running the script. Also the argument to `infer-owner` to determine diff --git a/node_modules/@npmcli/promise-spawn/index.js b/node_modules/@npmcli/promise-spawn/index.js index f977297bb49ec..cc73d1dad6b07 100644 --- a/node_modules/@npmcli/promise-spawn/index.js +++ b/node_modules/@npmcli/promise-spawn/index.js @@ -2,6 +2,11 @@ const {spawn} = require('child_process') const inferOwner = require('infer-owner') +const isPipe = (stdio = 'pipe', fd) => + stdio === 'pipe' || stdio === null ? true + : Array.isArray(stdio) ? isPipe(stdio[fd], fd) + : false + // 'extra' object is for decorating the error a bit more const promiseSpawn = (cmd, args, opts, extra = {}) => { const cwd = opts.cwd || process.cwd() @@ -20,13 +25,14 @@ const promiseSpawn = (cmd, args, opts, extra = {}) => { }, extra)) } -const stdioResult = (stdout, stderr, {stdioString}) => +const stdioResult = (stdout, stderr, {stdioString, stdio}) => stdioString ? { - stdout: Buffer.concat(stdout).toString(), - stderr: Buffer.concat(stderr).toString(), - } : { - stdout: Buffer.concat(stdout), - stderr: Buffer.concat(stderr), + stdout: isPipe(stdio, 1) ? Buffer.concat(stdout).toString() : null, + stderr: isPipe(stdio, 2) ? Buffer.concat(stderr).toString() : null, + } + : { + stdout: isPipe(stdio, 1) ? Buffer.concat(stdout) : null, + stderr: isPipe(stdio, 2) ? Buffer.concat(stderr) : null, } const promiseSpawnUid = (cmd, args, opts, extra) => { @@ -67,6 +73,7 @@ const promiseSpawnUid = (cmd, args, opts, extra) => { }) p.stdin = proc.stdin + p.process = proc return p } diff --git a/node_modules/@npmcli/promise-spawn/package.json b/node_modules/@npmcli/promise-spawn/package.json index 9cabd33e7f9ae..d640c9457d2d4 100644 --- a/node_modules/@npmcli/promise-spawn/package.json +++ b/node_modules/@npmcli/promise-spawn/package.json @@ -1,6 +1,6 @@ { "name": "@npmcli/promise-spawn", - "version": "1.2.0", + "version": "1.3.1", "files": [ "index.js" ], diff --git a/package-lock.json b/package-lock.json index 4ff1d1f1db2fd..6fbf7c73cbd7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -515,9 +515,10 @@ "license": "ISC" }, "node_modules/@npmcli/promise-spawn": { - "version": "1.2.0", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@npmcli/promise-spawn/-/promise-spawn-1.3.1.tgz", + "integrity": "sha512-S+I+ADqj66+ZpmmmvWXdNQkVyvikMYm/yrlk7xzoF6qf8AqL26yLwaxn0/ZTB0r3j1pur8Q/lyxL8yg4fZI76A==", "inBundle": true, - "license": "ISC", "dependencies": { "infer-owner": "^1.0.4" } @@ -9155,7 +9156,9 @@ "version": "1.0.1" }, "@npmcli/promise-spawn": { - "version": "1.2.0", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@npmcli/promise-spawn/-/promise-spawn-1.3.1.tgz", + "integrity": "sha512-S+I+ADqj66+ZpmmmvWXdNQkVyvikMYm/yrlk7xzoF6qf8AqL26yLwaxn0/ZTB0r3j1pur8Q/lyxL8yg4fZI76A==", "requires": { "infer-owner": "^1.0.4" }