diff --git a/package-lock.json b/package-lock.json index 3c5e2239e..582e4f4bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "semver": "^7.6.0", "semver-utils": "^1.1.4", "source-map-support": "^0.5.21", - "spawn-please": "^2.0.2", + "spawn-please": "^3.0.0", "strip-ansi": "^7.1.0", "strip-json-comments": "^5.0.1", "untildify": "^4.0.0", @@ -848,6 +848,14 @@ "node": ">= 14" } }, + "node_modules/@npmcli/agent/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/@npmcli/agent/node_modules/socks-proxy-agent": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.2.tgz", @@ -899,6 +907,14 @@ "node": ">=16" } }, + "node_modules/@npmcli/git/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/@npmcli/git/node_modules/which": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", @@ -1763,6 +1779,12 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/@yarnpkg/parsers/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, "node_modules/abbrev": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz", @@ -2761,8 +2783,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true, - "license": "MIT" + "dev": true }, "node_modules/combined-stream": { "version": "1.0.8", @@ -3919,7 +3940,6 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -4263,7 +4283,6 @@ "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", "dev": true, - "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -4273,7 +4292,6 @@ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true, - "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" } @@ -5625,8 +5643,7 @@ "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "license": "MIT" + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, "node_modules/log-symbols": { "version": "4.1.0", @@ -6280,8 +6297,7 @@ "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "license": "MIT" + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==" }, "node_modules/negotiator": { "version": "0.6.3", @@ -6364,6 +6380,28 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/node-gyp/node_modules/cacache": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-18.0.0.tgz", + "integrity": "sha512-I7mVOPl3PUCeRub1U8YoGz2Lqv9WOBpobZ8RyWFXmReuILz+3OAyTa5oH3QPdtKZD7N0Yk00aLfzn0qvp8dZ1w==", + "dependencies": { + "@npmcli/fs": "^3.1.0", + "fs-minipass": "^3.0.0", + "glob": "^10.2.2", + "lru-cache": "^10.0.1", + "minipass": "^7.0.3", + "minipass-collect": "^1.0.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "p-map": "^4.0.0", + "ssri": "^10.0.0", + "tar": "^6.1.11", + "unique-filename": "^3.0.0" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, "node_modules/node-gyp/node_modules/isexe": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz", @@ -6372,6 +6410,35 @@ "node": ">=16" } }, + "node_modules/node-gyp/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/node-gyp/node_modules/make-fetch-happen": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-13.0.0.tgz", + "integrity": "sha512-7ThobcL8brtGo9CavByQrQi+23aIfgYU++wg4B87AIS8Rb2ZBt/MEaDqzA00Xwv/jUjAjYkLHjVolYuTLKda2A==", + "dependencies": { + "@npmcli/agent": "^2.0.0", + "cacache": "^18.0.0", + "http-cache-semantics": "^4.1.1", + "is-lambda": "^1.0.1", + "minipass": "^7.0.2", + "minipass-fetch": "^3.0.0", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.3", + "promise-retry": "^2.0.1", + "ssri": "^10.0.0" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, "node_modules/node-gyp/node_modules/which": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", @@ -6414,6 +6481,25 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/normalize-package-data/node_modules/hosted-git-info": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-7.0.1.tgz", + "integrity": "sha512-+K84LB1DYwMHoHSgaOY/Jfhw3ucPmSET5v98Ke/HdNSw4a0UktWzyW1mjhjpuxxTqOOsfWT/7iVshHmVZ4IpOA==", + "dependencies": { + "lru-cache": "^10.0.1" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, + "node_modules/normalize-package-data/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -6482,6 +6568,25 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/npm-package-arg/node_modules/hosted-git-info": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-7.0.1.tgz", + "integrity": "sha512-+K84LB1DYwMHoHSgaOY/Jfhw3ucPmSET5v98Ke/HdNSw4a0UktWzyW1mjhjpuxxTqOOsfWT/7iVshHmVZ4IpOA==", + "dependencies": { + "lru-cache": "^10.0.1" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, + "node_modules/npm-package-arg/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/npm-packlist": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-8.0.0.tgz", @@ -6524,6 +6629,57 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/npm-registry-fetch/node_modules/cacache": { + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-18.0.0.tgz", + "integrity": "sha512-I7mVOPl3PUCeRub1U8YoGz2Lqv9WOBpobZ8RyWFXmReuILz+3OAyTa5oH3QPdtKZD7N0Yk00aLfzn0qvp8dZ1w==", + "dependencies": { + "@npmcli/fs": "^3.1.0", + "fs-minipass": "^3.0.0", + "glob": "^10.2.2", + "lru-cache": "^10.0.1", + "minipass": "^7.0.3", + "minipass-collect": "^1.0.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "p-map": "^4.0.0", + "ssri": "^10.0.0", + "tar": "^6.1.11", + "unique-filename": "^3.0.0" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, + "node_modules/npm-registry-fetch/node_modules/lru-cache": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.1.tgz", + "integrity": "sha512-IJ4uwUTi2qCccrioU6g9g/5rvvVl13bsdczUUcqbciD9iLr095yj8DQKdObriEvuNSx325N1rV1O0sJFszx75g==", + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/npm-registry-fetch/node_modules/make-fetch-happen": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-13.0.0.tgz", + "integrity": "sha512-7ThobcL8brtGo9CavByQrQi+23aIfgYU++wg4B87AIS8Rb2ZBt/MEaDqzA00Xwv/jUjAjYkLHjVolYuTLKda2A==", + "dependencies": { + "@npmcli/agent": "^2.0.0", + "cacache": "^18.0.0", + "http-cache-semantics": "^4.1.1", + "is-lambda": "^1.0.1", + "minipass": "^7.0.2", + "minipass-fetch": "^3.0.0", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.3", + "promise-retry": "^2.0.1", + "ssri": "^10.0.0" + }, + "engines": { + "node": "^16.14.0 || >=18.0.0" + } + }, "node_modules/npm-run-all": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz", @@ -7973,9 +8129,9 @@ } }, "node_modules/spawn-please": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-2.0.2.tgz", - "integrity": "sha512-KM8coezO6ISQ89c1BzyWNtcn2V2kAVtwIXd3cN/V5a0xPYc1F/vydrRc01wsKFEQ/p+V1a4sw4z2yMITIXrgGw==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/spawn-please/-/spawn-please-3.0.0.tgz", + "integrity": "sha512-XFHEGgEG9R/MCypDDQVWoSSQoGAz5LFYcGoFpdYvnqgYDumHvapPDj54C5Xv7tqTkzEC17AY7Iz90KgrDfj7Gg==", "dependencies": { "cross-spawn": "^7.0.3" }, @@ -8477,12 +8633,6 @@ "json5": "lib/cli.js" } }, - "node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, "node_modules/tuf-js": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/tuf-js/-/tuf-js-2.2.0.tgz", diff --git a/package.json b/package.json index 33aec74e6..7e62ee08b 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "semver": "^7.6.0", "semver-utils": "^1.1.4", "source-map-support": "^0.5.21", - "spawn-please": "^2.0.2", + "spawn-please": "^3.0.0", "strip-ansi": "^7.1.0", "strip-json-comments": "^5.0.1", "untildify": "^4.0.0", diff --git a/src/index.ts b/src/index.ts index ce45a0fe2..71ce47bd7 100755 --- a/src/index.ts +++ b/src/index.ts @@ -145,26 +145,32 @@ const install = async ( const cwd = options.cwd || path.resolve(pkgFile, '..') let stdout = '' try { - await spawn(cmd, ['install'], { - cwd, - env: { - ...process.env, - ...(options.color !== false ? { FORCE_COLOR: true } : null), - // With spawn, pnpm install will fail with ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies. - // When pnpm install is run directly from the terminal, this error does not occur. - // When pnpm install is run from a simple spawn script, this error does not occur. - // The issue only seems to be when pnpm install is executed from npm-check-updates, but it's not clear what configuration or environmental factors are causing this. - // For now, turn off strict-peer-dependencies on pnpm auto-install. - // See: https://github.com/raineorshine/npm-check-updates/issues/1191 - ...(packageManager === 'pnpm' ? { npm_config_strict_peer_dependencies: false } : null), + await spawn( + cmd, + ['install'], + { + stdout: (data: string) => { + stdout += data + }, + stderr: (data: string) => { + console.error(chalk.red(data.toString())) + }, }, - stdout: (data: string) => { - stdout += data + { + cwd, + env: { + ...process.env, + ...(options.color !== false ? { FORCE_COLOR: true } : null), + // With spawn, pnpm install will fail with ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies. + // When pnpm install is run directly from the terminal, this error does not occur. + // When pnpm install is run from a simple spawn script, this error does not occur. + // The issue only seems to be when pnpm install is executed from npm-check-updates, but it's not clear what configuration or environmental factors are causing this. + // For now, turn off strict-peer-dependencies on pnpm auto-install. + // See: https://github.com/raineorshine/npm-check-updates/issues/1191 + ...(packageManager === 'pnpm' ? { npm_config_strict_peer_dependencies: false } : null), + }, }, - stderr: (data: string) => { - console.error(chalk.red(data.toString())) - }, - }) + ) print(options, stdout) print(options, 'Done') } catch (err: any) { diff --git a/src/lib/doctor.ts b/src/lib/doctor.ts index 60f01ab94..8c2a5663f 100644 --- a/src/lib/doctor.ts +++ b/src/lib/doctor.ts @@ -10,6 +10,7 @@ import { Options } from '../types/Options' import { PackageFile } from '../types/PackageFile' import { PackageInfo } from '../types/PackageInfo' import { SpawnOptions } from '../types/SpawnOptions' +import { SpawnPleaseOptions } from '../types/SpawnPleaseOptions' import { VersionSpec } from '../types/VersionSpec' import chalk, { chalkInit } from './chalk' import loadPackageInfoFromFile from './loadPackageInfoFromFile' @@ -22,7 +23,7 @@ const npm = ( args: string[], options: Options, print?: boolean, - { spawnOptions }: { spawnOptions?: SpawnOptions } = {}, + { spawnOptions, spawnPleaseOptions }: { spawnOptions?: SpawnOptions; spawnPleaseOptions?: SpawnPleaseOptions } = {}, ): Promise => { if (print) { console.log(chalk.blue([options.packageManager, ...args].join(' '))) @@ -53,7 +54,7 @@ const npm = ( : options.packageManager === 'bun' ? spawnBun : spawnNpm - )(args, npmOptions, spawnOptionsMerged as any) + )(args, npmOptions, spawnPleaseOptions, spawnOptionsMerged) } /** Load and validate package file and tests. */ @@ -120,7 +121,7 @@ const doctor = async (run: Run, options: Options): Promise => { /** Run the tests using "npm run test" or a custom script given by --doctorTest. */ const runTests = async (): Promise => { - const spawnOptions = { + const spawnPleaseOptions = { stderr: (data: string): void => { console.error(chalk.red(data.toString())) }, @@ -140,7 +141,7 @@ const doctor = async (run: Run, options: Options): Promise => { } const [testCommand, ...testArgs] = groups console.log(chalk.blue(options.doctorTest)) - await spawn(testCommand, testArgs, spawnOptions) + await spawn(testCommand, testArgs, spawnPleaseOptions) } else { await npm( ['run', 'test'], @@ -148,7 +149,7 @@ const doctor = async (run: Run, options: Options): Promise => { packageManager: options.packageManager, }, true, - { spawnOptions }, + { spawnPleaseOptions }, ) } } diff --git a/src/package-managers/bun.ts b/src/package-managers/bun.ts index 59b44deda..b4715a9da 100644 --- a/src/package-managers/bun.ts +++ b/src/package-managers/bun.ts @@ -5,14 +5,16 @@ import programError from '../lib/programError' import { Index } from '../types/IndexType' import { NpmOptions } from '../types/NpmOptions' import { Options } from '../types/Options' +import { SpawnPleaseOptions } from '../types/SpawnPleaseOptions' import * as npm from './npm' /** Spawn bun. */ async function spawnBun( args: string | string[], npmOptions: NpmOptions = {}, + spawnPleaseOptions: SpawnPleaseOptions = {}, spawnOptions: Index = {}, -): Promise { +): Promise<{ stdout: string; stderr: string }> { // Bun not yet supported on Windows. // @see https://github.com/oven-sh/bun/issues/43 if (process.platform === 'win32') { @@ -25,13 +27,13 @@ async function spawnBun( ...(Array.isArray(args) ? args : [args]), ] - return spawn('bun', fullArgs, spawnOptions) + return spawn('bun', fullArgs, spawnPleaseOptions, spawnOptions) } /** Returns the global directory of bun. */ export const defaultPrefix = async (options: Options): Promise => options.global - ? options.prefix || process.env.BUN_INSTALL || path.dirname(await spawn('bun', ['pm', '-g', 'bin'])) + ? options.prefix || process.env.BUN_INSTALL || path.dirname((await spawn('bun', ['pm', '-g', 'bin'])).stdout) : undefined /** @@ -41,12 +43,15 @@ export const list = async (options: Options = {}): Promise = {}, ): Promise { const cmd = process.platform === 'win32' ? 'npm.cmd' : 'npm' @@ -543,7 +545,8 @@ async function spawnNpm( '--json', ...(Array.isArray(args) ? args : [args]), ] - return spawn(cmd, fullArgs, spawnOptions) + const { stdout } = await spawn(cmd, fullArgs, spawnPleaseOptions, spawnOptions) + return stdout } /** @@ -566,7 +569,8 @@ export async function defaultPrefix(options: Options): Promise diff --git a/src/package-managers/pnpm.ts b/src/package-managers/pnpm.ts index d63ec474c..16464e95d 100644 --- a/src/package-managers/pnpm.ts +++ b/src/package-managers/pnpm.ts @@ -12,6 +12,7 @@ import { NpmConfig } from '../types/NpmConfig' import { NpmOptions } from '../types/NpmOptions' import { Options } from '../types/Options' import { SpawnOptions } from '../types/SpawnOptions' +import { SpawnPleaseOptions } from '../types/SpawnPleaseOptions' import { Version } from '../types/Version' import * as npm from './npm' @@ -57,7 +58,8 @@ export const list = async (options: Options = {}): Promise ({ [name]: version, })) @@ -90,6 +92,7 @@ export default async function spawnPnpm( args: string | string[], npmOptions: NpmOptions = {}, spawnOptions?: SpawnOptions, + spawnPleaseOptions?: SpawnPleaseOptions, ): Promise { const cmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm' @@ -99,7 +102,9 @@ export default async function spawnPnpm( ...(npmOptions.prefix ? `--prefix=${npmOptions.prefix}` : []), ] - return spawn(cmd, fullArgs, spawnOptions) + const { stdout } = await spawn(cmd, fullArgs, spawnPleaseOptions, spawnOptions) + + return stdout } export { defaultPrefix, getPeerDependencies, packageAuthorChanged } from './npm' diff --git a/src/package-managers/yarn.ts b/src/package-managers/yarn.ts index c82da7406..96c84031b 100644 --- a/src/package-managers/yarn.ts +++ b/src/package-managers/yarn.ts @@ -16,6 +16,7 @@ import { NpmConfig } from '../types/NpmConfig' import { NpmOptions } from '../types/NpmOptions' import { Options } from '../types/Options' import { SpawnOptions } from '../types/SpawnOptions' +import { SpawnPleaseOptions } from '../types/SpawnPleaseOptions' import { VersionSpec } from '../types/VersionSpec' import * as npm from './npm' @@ -190,7 +191,8 @@ function parseJsonLines(result: string): Promise<{ dependencies: Index { const cmd = process.platform === 'win32' ? 'yarn.cmd' : 'yarn' @@ -205,7 +207,9 @@ async function spawnYarn( ...(Array.isArray(args) ? args : [args]), ] - return spawn(cmd, fullArgs, spawnOptions) + const { stdout } = await spawn(cmd, fullArgs, spawnPleaseOptions, spawnOptions) + + return stdout } /** @@ -216,20 +220,20 @@ async function spawnYarn( * @param [options.prefix] * @returns */ -export async function defaultPrefix(options: Options): Promise { +export async function defaultPrefix(options: Options): Promise { if (options.prefix) { return Promise.resolve(options.prefix) } const cmd = process.platform === 'win32' ? 'yarn.cmd' : 'yarn' - const prefix = await spawn(cmd, ['global', 'dir']) + const { stdout: prefix } = await spawn(cmd, ['global', 'dir']) // yarn 2.0 does not support yarn global // catch error to prevent process from crashing // https://github.com/raineorshine/npm-check-updates/issues/873 - .catch(() => { - /* empty */ - }) + .catch(() => ({ + stdout: null, + })) // FIX: for ncu -g doesn't work on homebrew or windows #146 // https://github.com/raineorshine/npm-check-updates/issues/146 @@ -255,10 +259,15 @@ export async function defaultPrefix(options: Options): Promise { * @returns */ export const list = async (options: Options = {}, spawnOptions?: SpawnOptions): Promise> => { - const jsonLines: string = await spawnYarn('list', options as Index, { - ...(options.cwd ? { cwd: options.cwd } : {}), - ...spawnOptions, - }) + const jsonLines: string = await spawnYarn( + 'list', + options as Index, + {}, + { + ...(options.cwd ? { cwd: options.cwd } : {}), + ...spawnOptions, + }, + ) const json: { dependencies: Index } = await parseJsonLines(jsonLines) const keyValues: Index = keyValueBy( json.dependencies, diff --git a/src/scripts/build-options.ts b/src/scripts/build-options.ts index 7eb95e3ac..ef77c7074 100644 --- a/src/scripts/build-options.ts +++ b/src/scripts/build-options.ts @@ -103,10 +103,12 @@ export interface RunOptions { } /** Generates a JSON schema for the ncurc file. */ -const generateRunOptionsJsonSchema = async (): Promise => +const generateRunOptionsJsonSchema = async (): Promise => { // programmatic usage of typescript-json-schema does not work, at least not straightforwardly. // Use the CLI which works out-of-the-box. - spawn('typescript-json-schema', ['tsconfig.json', 'RunOptions']) + const { stdout } = await spawn('typescript-json-schema', ['tsconfig.json', 'RunOptions']) + return stdout +} ;(async () => { await fs.writeFile('README.md', await injectReadme()) diff --git a/src/types/SpawnOptions.ts b/src/types/SpawnOptions.ts index 01681aa5f..fff99f8cc 100644 --- a/src/types/SpawnOptions.ts +++ b/src/types/SpawnOptions.ts @@ -2,6 +2,6 @@ import { Index } from './IndexType' /** Options to the spawn node built-in. */ export interface SpawnOptions { + cwd?: string env?: Index - stderr?: (s: string) => void } diff --git a/src/types/SpawnPleaseOptions.ts b/src/types/SpawnPleaseOptions.ts new file mode 100644 index 000000000..7f462e3c3 --- /dev/null +++ b/src/types/SpawnPleaseOptions.ts @@ -0,0 +1,6 @@ +export interface SpawnPleaseOptions { + rejectOnError?: boolean + stdin?: string + stdout?: (s: string) => void + stderr?: (s: string) => void +} diff --git a/src/types/spawn-please.d.ts b/src/types/spawn-please.d.ts deleted file mode 100644 index 05592f1e9..000000000 --- a/src/types/spawn-please.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// add to tsconfig compilerOptions.paths -declare module 'spawn-please' diff --git a/test/bin.test.ts b/test/bin.test.ts index 6611c926a..1c0d52cf9 100644 --- a/test/bin.test.ts +++ b/test/bin.test.ts @@ -13,69 +13,65 @@ const bin = path.join(__dirname, '../build/src/bin/cli.js') describe('bin', async function () { it('fetch latest version from registry (not stubbed)', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-v2') }) it('output only upgraded with --jsonUpgraded', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-v2') stub.restore() }) it('--loglevel verbose', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn( - 'node', - [bin, '--loglevel', 'verbose'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), - ) - output.should.containIgnoreCase('Initializing') - output.should.containIgnoreCase('Running in local mode') - output.should.containIgnoreCase('Finding package file data') + const { stdout } = await spawn('node', [bin, '--loglevel', 'verbose'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), + }) + stdout.should.containIgnoreCase('Initializing') + stdout.should.containIgnoreCase('Running in local mode') + stdout.should.containIgnoreCase('Finding package file data') stub.restore() }) it('--verbose', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn('node', [bin, '--verbose'], JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } })) - output.should.containIgnoreCase('Initializing') - output.should.containIgnoreCase('Running in local mode') - output.should.containIgnoreCase('Finding package file data') + const { stdout } = await spawn('node', [bin, '--verbose'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), + }) + stdout.should.containIgnoreCase('Initializing') + stdout.should.containIgnoreCase('Running in local mode') + stdout.should.containIgnoreCase('Finding package file data') stub.restore() }) it('accept stdin', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies: { express: '1' } })) - output.trim().should.startWith('express') + const { stdout } = await spawn('node', [bin, '--stdin'], { + stdin: JSON.stringify({ dependencies: { express: '1' } }), + }) + stdout.trim().should.startWith('express') stub.restore() }) it('reject out-of-date stdin with errorLevel 2', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - await spawn( - 'node', - [bin, '--stdin', '--errorLevel', '2'], - JSON.stringify({ dependencies: { express: '1' } }), - ).should.eventually.be.rejectedWith('Dependencies not up-to-date') + await spawn('node', [bin, '--stdin', '--errorLevel', '2'], { + stdin: JSON.stringify({ dependencies: { express: '1' } }), + }).should.eventually.be.rejectedWith('Dependencies not up-to-date') stub.restore() }) it('fall back to package.json search when receiving empty content on stdin', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const stdout = await spawn('node', [bin, '--stdin']) + const { stdout } = await spawn('node', [bin, '--stdin']) stdout .toString() .trim() @@ -85,15 +81,15 @@ describe('bin', async function () { it('use package.json in cwd by default', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn('node', [bin, '--jsonUpgraded'], { cwd: path.join(__dirname, 'test-data/ncu') }) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded'], {}, { cwd: path.join(__dirname, 'test-data/ncu') }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') stub.restore() }) it('throw error if there is no package', async () => { // run from tmp dir to avoid ncu analyzing the project's package.json - return spawn('node', [bin], { cwd: os.tmpdir() }).should.eventually.be.rejectedWith('No package.json') + return spawn('node', [bin], {}, { cwd: os.tmpdir() }).should.eventually.be.rejectedWith('No package.json') }) it('throw error if there is no package in --cwd', async () => { @@ -112,8 +108,8 @@ describe('bin', async function () { const pkgFile = path.join(tempDir, 'package.json') await fs.writeFile(pkgFile, JSON.stringify({ dependencies: { express: '1' } }), 'utf-8') try { - const text = await spawn('node', [bin, '--jsonUpgraded', '--packageFile', pkgFile]) - const pkgData = JSON.parse(text) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--packageFile', pkgFile]) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') } finally { await fs.rm(tempDir, { recursive: true, force: true }) @@ -181,7 +177,9 @@ describe('bin', async function () { const pkgFile = path.join(tempDir, 'package.json') await fs.writeFile(pkgFile, JSON.stringify({ dependencies: { express: '1' } }), 'utf-8') try { - await spawn('node', [bin, '-u', '--stdin', '--packageFile', pkgFile], JSON.stringify({ dependencies: {} })) + await spawn('node', [bin, '-u', '--stdin', '--packageFile', pkgFile], { + stdin: JSON.stringify({ dependencies: {} }), + }) const upgradedPkg = JSON.parse(await fs.readFile(pkgFile, 'utf-8')) upgradedPkg.should.have.property('dependencies') upgradedPkg.dependencies.should.have.property('express') @@ -194,8 +192,10 @@ describe('bin', async function () { it('suppress stdout when --silent is provided', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn('node', [bin, '--silent'], JSON.stringify({ dependencies: { express: '1' } })) - output.trim().should.equal('') + const { stdout } = await spawn('node', [bin, '--silent'], { + stdin: JSON.stringify({ dependencies: { express: '1' } }), + }) + stdout.trim().should.equal('') stub.restore() }) @@ -211,8 +211,8 @@ describe('bin', async function () { const pkgFile = path.join(tempDir, 'package.json') await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - const output = await spawn('node', [bin, '--packageFile', pkgFile, '--filter', 'ncu-test-v2 ncu-test-tag']) - output.should.include('"ncu-test-v2 ncu-test-tag"') + const { stdout } = await spawn('node', [bin, '--packageFile', pkgFile, '--filter', 'ncu-test-v2 ncu-test-tag']) + stdout.should.include('"ncu-test-v2 ncu-test-tag"') } finally { await fs.rm(tempDir, { recursive: true, force: true }) stub.restore() @@ -227,20 +227,18 @@ describe('bin', async function () { event: 'link:../link', workspace: 'workspace:../workspace', } - const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies })) + const { stdout } = await spawn('node', [bin, '--stdin'], { stdin: JSON.stringify({ dependencies }) }) - stripAnsi(output)!.should.not.include('No package versions were returned.') + stripAnsi(stdout)!.should.not.include('No package versions were returned.') stub.restore() }) it('combine boolean flags with arguments', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - const output = await spawn( - 'node', - [bin, '--stdin', '--jsonUpgraded', 'ncu-test-v2'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0', 'ncu-test-tag': '0.1.0' } }), - ) - const upgraded = JSON.parse(output) as Index + const { stdout } = await spawn('node', [bin, '--stdin', '--jsonUpgraded', 'ncu-test-v2'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0', 'ncu-test-tag': '0.1.0' } }), + }) + const upgraded = JSON.parse(stdout) as Index upgraded.should.deep.equal({ 'ncu-test-v2': '99.9.9', }) @@ -261,8 +259,8 @@ describe('bin', async function () { const dependencies = { 'ncu-test-v2': 'https://github.com/raineorshine/ncu-test-v2.git#v1.0.0', } - const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies })) - stripAnsi(output) + const { stdout } = await spawn('node', [bin, '--stdin'], { stdin: JSON.stringify({ dependencies }) }) + stripAnsi(stdout) .trim() .should.equal('ncu-test-v2 https://github.com/raineorshine/ncu-test-v2.git#v1.0.0 → v2.0.0') }) @@ -274,41 +272,41 @@ describe('bin', async function () { const dependencies = { request: 'npm:ncu-test-v2@1.0.0', } - const output = await spawn('node', [bin, '--stdin'], JSON.stringify({ dependencies })) - stripAnsi(output).trim().should.equal('request npm:ncu-test-v2@1.0.0 → 99.9.9') + const { stdout } = await spawn('node', [bin, '--stdin'], { stdin: JSON.stringify({ dependencies }) }) + stripAnsi(stdout).trim().should.equal('request npm:ncu-test-v2@1.0.0 → 99.9.9') stub.restore() }) }) describe('option-specific help', () => { it('long option', async () => { - const output = await spawn('node', [bin, '--help', '--filter']) - output.trim().should.match(/^Usage:\s+ncu --filter/) + const { stdout } = await spawn('node', [bin, '--help', '--filter']) + stdout.trim().should.match(/^Usage:\s+ncu --filter/) }) it('long option without "--" prefix', async () => { - const output = await spawn('node', [bin, '--help', '-f']) - output.trim().should.match(/^Usage:\s+ncu --filter/) + const { stdout } = await spawn('node', [bin, '--help', '-f']) + stdout.trim().should.match(/^Usage:\s+ncu --filter/) }) it('short option', async () => { - const output = await spawn('node', [bin, '--help', 'filter']) - output.trim().should.match(/^Usage:\s+ncu --filter/) + const { stdout } = await spawn('node', [bin, '--help', 'filter']) + stdout.trim().should.match(/^Usage:\s+ncu --filter/) }) it('short option without "-" prefix', async () => { - const output = await spawn('node', [bin, '--help', 'f']) - output.trim().should.match(/^Usage:\s+ncu --filter/) + const { stdout } = await spawn('node', [bin, '--help', 'f']) + stdout.trim().should.match(/^Usage:\s+ncu --filter/) }) it('option with default', async () => { - const output = await spawn('node', [bin, '--help', '--concurrency']) - output.trim().should.containIgnoreCase('Default:') + const { stdout } = await spawn('node', [bin, '--help', '--concurrency']) + stdout.trim().should.containIgnoreCase('Default:') }) it('option with extended help', async () => { - const output = await spawn('node', [bin, '--help', '--target']) - output.trim().should.containIgnoreCase('Upgrade to the highest version number') + const { stdout } = await spawn('node', [bin, '--help', '--target']) + stdout.trim().should.containIgnoreCase('Upgrade to the highest version number') // run extended help on other options for test coverage await spawn('node', [bin, '--help', 'doctor']) @@ -319,13 +317,13 @@ describe('bin', async function () { }) it('unknown option', async () => { - const output = await spawn('node', [bin, '--help', '--foo']) - output.trim().should.containIgnoreCase('Unknown option') + const { stdout } = await spawn('node', [bin, '--help', '--foo']) + stdout.trim().should.containIgnoreCase('Unknown option') }) it('special --help --help', async () => { - const output = await spawn('node', [bin, '--help', '--help']) - output.trim().should.not.include('Usage') + const { stdout } = await spawn('node', [bin, '--help', '--help']) + stdout.trim().should.not.include('Usage') }) }) }) diff --git a/test/deep.test.ts b/test/deep.test.ts index f94d03639..43a94a6a3 100644 --- a/test/deep.test.ts +++ b/test/deep.test.ts @@ -57,7 +57,8 @@ describe('--deep', function () { it('output json with --jsonAll', async () => { const tempDir = await setupDeepTest() try { - const deepJsonOut = await spawn('node', [bin, '--jsonAll', '--deep'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--deep'], {}, { cwd: tempDir }) + const deepJsonOut = JSON.parse(stdout) deepJsonOut.should.have.property('package.json') deepJsonOut.should.have.property('packages/sub1/package.json') deepJsonOut.should.have.property('packages/sub2/package.json') @@ -75,7 +76,7 @@ describe('--deep', function () { await spawn( 'node', [bin, '-u', '--packageFile', path.join(tempDir, '/**/package.json')], - '{ "dependencies": {}}', + { stdin: '{ "dependencies": {}}' }, { cwd: tempDir, }, @@ -92,10 +93,10 @@ describe('--deep', function () { it('update multiple packages', async () => { const tempDir = await setupDeepTest() try { - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '-u', '--jsonUpgraded', '--packageFile', path.join(tempDir, '**/package.json')], - '{ "dependencies": {}}', + { stdin: '{ "dependencies": {}}' }, { cwd: tempDir }, ) @@ -109,7 +110,7 @@ describe('--deep', function () { upgradedPkg2.dependencies.should.have.property('express') upgradedPkg2.dependencies.express.should.not.equal('1') - const json = JSON.parse(output) + const json = JSON.parse(stdout) // Make sure to fix windows paths with replace json.should.have.property(path.join(tempDir, 'packages/sub1/package.json').replace(/\\/g, '/')) json.should.have.property(path.join(tempDir, 'packages/sub2/package.json').replace(/\\/g, '/')) @@ -130,7 +131,8 @@ describe('--deep with nested ncurc files', function () { after(() => stub.restore()) it('use ncurc of nested packages', async () => { - const deepJsonOut = await spawn('node', [bin, '--jsonUpgraded', '--deep'], { cwd }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--deep'], {}, { cwd }) + const deepJsonOut = JSON.parse(stdout) // root: reject: ['cute-animals'] deepJsonOut.should.have.property('package.json') @@ -157,9 +159,8 @@ describe('--deep with nested ncurc files', function () { }) it('use ncurc of nested packages with --mergeConfig option', async () => { - const deepJsonOut = await spawn('node', [bin, '--jsonUpgraded', '--deep', '--mergeConfig'], { cwd }).then( - JSON.parse, - ) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--deep', '--mergeConfig'], {}, { cwd }) + const deepJsonOut = JSON.parse(stdout) // root: reject: ['cute-animals'] deepJsonOut.should.have.property('package.json') diff --git a/test/doctor.test.ts b/test/doctor.test.ts index 447a556fc..e4cb4ef79 100644 --- a/test/doctor.test.ts +++ b/test/doctor.test.ts @@ -21,7 +21,14 @@ const mockNpmVersions = { } /** Run the ncu CLI. */ -const ncu = (args: string[], options?: Record) => spawn('node', [bin, ...args], options) +const ncu = async ( + args: string[], + spawnPleaseOptions?: Parameters[2], + spawnOptions?: Parameters[3], +) => { + const { stdout } = await spawn('node', [bin, ...args], spawnPleaseOptions, spawnOptions) + return stdout +} /** Assertions for npm or yarn when tests pass. */ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) => { @@ -53,15 +60,18 @@ const testPass = ({ packageManager }: { packageManager: PackageManagerName }) => try { // explicitly set packageManager to avoid auto yarn detection - await ncu(['--doctor', '-u', '-p', packageManager], { - cwd, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await ncu( + ['--doctor', '-u', '-p', packageManager], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd }, + ) } catch (e) {} const pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') @@ -121,15 +131,18 @@ const testFail = ({ packageManager }: { packageManager: PackageManagerName }) => try { // explicitly set packageManager to avoid auto yarn detection - await ncu(['--doctor', '-u', '-p', packageManager], { - cwd, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await ncu( + ['--doctor', '-u', '-p', packageManager], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd }, + ) } finally { pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') await fs.writeFile(pkgPath, pkgOriginal) @@ -174,7 +187,7 @@ describe('doctor', function () { await chalkInit() const { default: stripAnsi } = await import('strip-ansi') const cwd = path.join(doctorTests, 'nopackagefile') - const output = await ncu(['--doctor'], { cwd }) + const output = await ncu(['--doctor'], {}, { cwd }) return stripAnsi(output).should.equal( `Usage: ncu --doctor\n\n${stripAnsi( (cliOptionsMap.doctor.help as (options: { markdown: boolean }) => string)({ markdown: false }), @@ -184,12 +197,12 @@ describe('doctor', function () { it('throw an error if there is no package file', async () => { const cwd = path.join(doctorTests, 'nopackagefile') - return ncu(['--doctor', '-u'], { cwd }).should.eventually.be.rejectedWith('Missing or invalid package.json') + return ncu(['--doctor', '-u'], {}, { cwd }).should.eventually.be.rejectedWith('Missing or invalid package.json') }) it('throw an error if there is no test script', async () => { const cwd = path.join(doctorTests, 'notestscript') - return ncu(['--doctor', '-u'], { cwd }).should.eventually.be.rejectedWith('No npm "test" script') + return ncu(['--doctor', '-u'], {}, { cwd }).should.eventually.be.rejectedWith('No npm "test" script') }) it('throw an error if --packageData or --packageFile are supplied', async () => { @@ -219,15 +232,18 @@ describe('doctor', function () { try { // check only ncu-test-v2 (excluding ncu-return-version) - await ncu(['--doctor', '-u', '--filter', 'ncu-test-v2'], { - cwd, - stdout: function (data: string) { - stdout += data + await ncu( + ['--doctor', '-u', '--filter', 'ncu-test-v2'], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - stderr: function (data: string) { - stderr += data - }, - }) + { cwd }, + ) } catch (e) {} const pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') @@ -261,15 +277,18 @@ describe('doctor', function () { let stderr = '' try { - await ncu(['--doctor', '-u', '--doctorInstall', npmCmd + ' run myinstall'], { - cwd, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await ncu( + ['--doctor', '-u', '--doctorInstall', npmCmd + ' run myinstall'], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd }, + ) } catch (e) {} const pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') @@ -302,15 +321,18 @@ describe('doctor', function () { let stderr = '' try { - await ncu(['--doctor', '-u', '--doctorTest', npmCmd + ' run mytest'], { - cwd, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await ncu( + ['--doctor', '-u', '--doctorTest', npmCmd + ' run mytest'], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd }, + ) } catch (e) {} const pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') @@ -343,15 +365,18 @@ describe('doctor', function () { let stderr = '' try { - await ncu(['--doctor', '-u', '--doctorTest', `node ${echoPath} '123 456'`], { - cwd, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await ncu( + ['--doctor', '-u', '--doctorTest', `node ${echoPath} '123 456'`], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd }, + ) } catch (e) {} const pkgUpgraded = await fs.readFile(pkgPath, 'utf-8') @@ -416,17 +441,20 @@ else { try { // explicitly set packageManager to avoid auto yarn detection - await spawn('npm', ['install'], { cwd: tempDir }) - - await ncu(['--doctor', '-u', '-p', 'npm'], { - cwd: tempDir, - stdout: function (data: string) { - stdout += data - }, - stderr: function (data: string) { - stderr += data + await spawn('npm', ['install'], {}, { cwd: tempDir }) + + await ncu( + ['--doctor', '-u', '-p', 'npm'], + { + stdout: function (data: string) { + stdout += data + }, + stderr: function (data: string) { + stderr += data + }, }, - }) + { cwd: tempDir }, + ) pkgUpgraded = JSON.parse(await fs.readFile(pkgPath, 'utf-8')) } finally { diff --git a/test/filter.test.ts b/test/filter.test.ts index 27218de43..80b7add3e 100644 --- a/test/filter.test.ts +++ b/test/filter.test.ts @@ -207,23 +207,19 @@ describe('filter', () => { after(() => stub.restore()) it('filter by package name with --filter', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin', '--filter', 'express'], - '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'express'], { + stdin: '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') pkgData.should.not.have.property('chalk') }) it('filter by package name with -f', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin', '-f', 'express'], - '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '-f', 'express'], { + stdin: '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') pkgData.should.not.have.property('chalk') }) @@ -236,8 +232,9 @@ describe('filter', () => { }, } - await spawn('node', [bin, '--jsonUpgraded', '--filter', 'lodash.map', 'lodash.filter'], JSON.stringify(pkgData)) - .should.eventually.be.rejected + await spawn('node', [bin, '--jsonUpgraded', '--filter', 'lodash.map', 'lodash.filter'], { + stdin: JSON.stringify(pkgData), + }).should.eventually.be.rejected }) it('allow matching --filter and arguments', async () => { @@ -248,12 +245,12 @@ describe('filter', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'lodash.map lodash.filter', 'lodash.map', 'lodash.filter'], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.have.property('lodash.map') upgraded.should.have.property('lodash.filter') }) @@ -266,12 +263,12 @@ describe('filter', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'lodash.map lodash.filter', ' '], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.have.property('lodash.map') upgraded.should.have.property('lodash.filter') }) @@ -284,12 +281,12 @@ describe('filter', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--stdin', '--filter', 'ncu-test-v2', '--filter', 'ncu-test-tag'], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.have.property('ncu-test-v2') upgraded.should.have.property('ncu-test-tag') }) @@ -303,34 +300,28 @@ describe('reject', () => { after(() => stub.restore()) it('reject by package name with --reject', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin', '--reject', 'chalk'], - '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '--reject', 'chalk'], { + stdin: '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') pkgData.should.not.have.property('chalk') }) it('reject by package name with -x', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--stdin', '-x', 'chalk'], - '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--stdin', '-x', 'chalk'], { + stdin: '{ "dependencies": { "express": "1", "chalk": "0.1.0" } }', + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('express') pkgData.should.not.have.property('chalk') }) it('reject with empty string should not reject anything', async () => { - const output = await spawn( - 'node', - [bin, '--jsonUpgraded', '--reject', '""', '--stdin', '-x', 'chalk'], - '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "1.0.0" } }', - ) - const pkgData = JSON.parse(output) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--reject', '""', '--stdin', '-x', 'chalk'], { + stdin: '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "1.0.0" } }', + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-v2') pkgData.should.have.property('ncu-test-tag') }) @@ -343,12 +334,12 @@ describe('reject', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--stdin', '--reject', 'ncu-test-v2', '--reject', 'ncu-test-tag'], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.not.have.property('ncu-test-v2') upgraded.should.not.have.property('ncu-test-tag') }) diff --git a/test/filterVersion.test.ts b/test/filterVersion.test.ts index 5360f7864..8a3993b32 100644 --- a/test/filterVersion.test.ts +++ b/test/filterVersion.test.ts @@ -127,12 +127,12 @@ describe('filterVersion', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--verbose', '--stdin', '--filterVersion', '1.0.0', '--filterVersion', '1.0.9'], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.have.property('ncu-test-v2') upgraded.should.have.property('ncu-test-10') stub.restore() @@ -151,12 +151,12 @@ describe('rejectVersion', () => { }, } - const output = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--verbose', '--stdin', '--rejectVersion', '1.0.0', '--rejectVersion', '1.0.9'], - JSON.stringify(pkgData), + { stdin: JSON.stringify(pkgData) }, ) - const upgraded = JSON.parse(output) + const upgraded = JSON.parse(stdout) upgraded.should.not.have.property('ncu-test-v2') upgraded.should.not.have.property('ncu-test-10') stub.restore() diff --git a/test/format.test.ts b/test/format.test.ts index 5f6ea1659..7a23f33dc 100644 --- a/test/format.test.ts +++ b/test/format.test.ts @@ -27,8 +27,8 @@ describe('format', () => { 'ncu-test-v2': '^1.0.0', }, } - const output = await spawn('node', [bin, '--format', 'time', '--stdin'], JSON.stringify(packageData)) - expect(output).contains(timestamp) + const { stdout } = await spawn('node', [bin, '--format', 'time', '--stdin'], { stdin: JSON.stringify(packageData) }) + expect(stdout).contains(timestamp) stub.restore() }) @@ -45,9 +45,9 @@ describe('format', () => { 'utf-8', ) try { - await spawn('npm', ['install'], { cwd: tempDir }) - const output = await spawn('node', [bin, '--format', 'repo'], { cwd: tempDir }) - output.should.include('https://github.com/Mitsunee/modern-diacritics') + await spawn('npm', ['install'], {}, { cwd: tempDir }) + const { stdout } = await spawn('node', [bin, '--format', 'repo'], {}, { cwd: tempDir }) + stdout.should.include('https://github.com/Mitsunee/modern-diacritics') } finally { await fs.rm(tempDir, { recursive: true, force: true }) } @@ -74,8 +74,8 @@ describe('format', () => { 'utf-8', ) try { - const output = await spawn('node', [bin, '--format', 'lines'], { cwd: tempDir }) - output.should.equals('ncu-test-v2@^2.0.0\nncu-test-tag@^1.1.0\n') + const { stdout } = await spawn('node', [bin, '--format', 'lines'], {}, { cwd: tempDir }) + stdout.should.equals('ncu-test-v2@^2.0.0\nncu-test-tag@^1.1.0\n') } finally { await fs.rm(tempDir, { recursive: true, force: true }) stub.restore() @@ -103,9 +103,14 @@ describe('format', () => { 'utf-8', ) try { - await spawn('node', [bin, '--format', 'lines', '--jsonUpgraded'], { - cwd: tempDir, - }).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonUpgraded.') + await spawn( + 'node', + [bin, '--format', 'lines', '--jsonUpgraded'], + {}, + { + cwd: tempDir, + }, + ).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonUpgraded.') } finally { await fs.rm(tempDir, { recursive: true, force: true }) stub.restore() @@ -133,9 +138,14 @@ describe('format', () => { 'utf-8', ) try { - await spawn('node', [bin, '--format', 'lines', '--jsonAll'], { - cwd: tempDir, - }).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonAll.') + await spawn( + 'node', + [bin, '--format', 'lines', '--jsonAll'], + {}, + { + cwd: tempDir, + }, + ).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonAll.') } finally { await fs.rm(tempDir, { recursive: true, force: true }) stub.restore() @@ -163,9 +173,14 @@ describe('format', () => { 'utf-8', ) try { - await spawn('node', [bin, '--format', 'lines,group'], { - cwd: tempDir, - }).should.eventually.be.rejectedWith('Cannot use --format lines with other formatting options.') + await spawn( + 'node', + [bin, '--format', 'lines,group'], + {}, + { + cwd: tempDir, + }, + ).should.eventually.be.rejectedWith('Cannot use --format lines with other formatting options.') } finally { await fs.rm(tempDir, { recursive: true, force: true }) stub.restore() diff --git a/test/global.test.ts b/test/global.test.ts index 38cca4bfd..5baada4e9 100644 --- a/test/global.test.ts +++ b/test/global.test.ts @@ -12,7 +12,7 @@ describe('global', () => { const itSkipWindows = process.platform === 'win32' ? it.skip : it itSkipWindows('global should run', async () => { // to speed up the test, only check npm (which is always installed globally) - const stdout = await spawn('node', [bin, '--jsonAll', '--global', 'npm']) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--global', 'npm']) const json = JSON.parse(stdout) expect(json).to.have.property('npm') }) diff --git a/test/group.test.ts b/test/group.test.ts index a771a3459..f2f75a16d 100644 --- a/test/group.test.ts +++ b/test/group.test.ts @@ -41,9 +41,14 @@ async function groupTestScaffold( const configFile = path.join(tempDir, '.ncurc.js') await fs.writeFile(configFile, `module.exports = { groupFunction: ${groupFn.toString()} }`, 'utf-8') try { - const stdout = await spawn('node', [bin, '--format', 'group', '--configFilePath', tempDir], { - cwd: tempDir, - }) + const { stdout } = await spawn( + 'node', + [bin, '--format', 'group', '--configFilePath', tempDir], + {}, + { + cwd: tempDir, + }, + ) stripAnsi(stdout).should.containIgnoreCase(expectedOutput) } finally { await fs.rm(tempDir, { recursive: true, force: true }) diff --git a/test/install.test.ts b/test/install.test.ts index af7daac07..0087be9d7 100644 --- a/test/install.test.ts +++ b/test/install.test.ts @@ -29,8 +29,8 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - const output = await spawn('node', [bin, '-u', '--packageFile', pkgFile]) - stripAnsi(output).should.include('Run npm install to install new versions') + const { stdout } = await spawn('node', [bin, '-u', '--packageFile', pkgFile]) + stripAnsi(stdout).should.include('Run npm install to install new versions') expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.false expect(await exists(path.join(tempDir, 'node_modules'))).to.be.false } finally { @@ -53,8 +53,8 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - const output = await spawn('node', [bin, '-u', '--packageFile', pkgFile, '--install', 'always']) - stripAnsi(output).should.not.include('Run npm install to install new versions') + const { stdout } = await spawn('node', [bin, '-u', '--packageFile', pkgFile, '--install', 'always']) + stripAnsi(stdout).should.not.include('Run npm install to install new versions') expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.true expect(await exists(path.join(tempDir, 'node_modules'))).to.be.true } finally { @@ -77,8 +77,8 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - const output = await spawn('node', [bin, '-u', '--packageFile', pkgFile, '--install', 'never']) - stripAnsi(output).should.not.include('Run npm install to install new versions') + const { stdout } = await spawn('node', [bin, '-u', '--packageFile', pkgFile, '--install', 'never']) + stripAnsi(stdout).should.not.include('Run npm install to install new versions') expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.false expect(await exists(path.join(tempDir, 'node_modules'))).to.be.false } finally { @@ -102,12 +102,17 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - await spawn('node', [bin, '-iu', '--packageFile', pkgFile], { - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2'], true]), + await spawn( + 'node', + [bin, '-iu', '--packageFile', pkgFile], + {}, + { + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2'], true]), + }, }, - }) + ) expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.true expect(await exists(path.join(tempDir, 'node_modules'))).to.be.true } finally { @@ -129,12 +134,17 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - await spawn('node', [bin, '-iu', '--packageFile', pkgFile], { - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2'], false]), + await spawn( + 'node', + [bin, '-iu', '--packageFile', pkgFile], + {}, + { + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2'], false]), + }, }, - }) + ) expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.false expect(await exists(path.join(tempDir, 'node_modules'))).to.be.false } finally { @@ -156,14 +166,19 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - await spawn('node', [bin, '-iu', '--packageFile', pkgFile, '--install', 'always'], { - env: { - ...process.env, - // NOTE: We can inject valuees, but we cannot test if the prompt was actually shown or not. - // i.e. Testing that the prompt is not shown with --install always must be done manually. - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2']]), + await spawn( + 'node', + [bin, '-iu', '--packageFile', pkgFile, '--install', 'always'], + {}, + { + env: { + ...process.env, + // NOTE: We can inject valuees, but we cannot test if the prompt was actually shown or not. + // i.e. Testing that the prompt is not shown with --install always must be done manually. + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2']]), + }, }, - }) + ) expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.true expect(await exists(path.join(tempDir, 'node_modules'))).to.be.true } finally { @@ -185,14 +200,19 @@ describe('install', () => { await fs.writeFile(pkgFile, JSON.stringify(pkgData), 'utf-8') try { - await spawn('node', [bin, '-iu', '--packageFile', pkgFile, '--install', 'never'], { - env: { - ...process.env, - // NOTE: We can inject valuees, but we cannot test if the prompt was actually shown or not. - // i.e. Testing that the prompt is not shown with --install never must be done manually. - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2']]), + await spawn( + 'node', + [bin, '-iu', '--packageFile', pkgFile, '--install', 'never'], + {}, + { + env: { + ...process.env, + // NOTE: We can inject valuees, but we cannot test if the prompt was actually shown or not. + // i.e. Testing that the prompt is not shown with --install never must be done manually. + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2']]), + }, }, - }) + ) expect(await exists(path.join(tempDir, 'package-lock.json'))).to.be.false expect(await exists(path.join(tempDir, 'node_modules'))).to.be.false } finally { diff --git a/test/interactive.test.ts b/test/interactive.test.ts index 5e9355e08..60ea12ae0 100644 --- a/test/interactive.test.ts +++ b/test/interactive.test.ts @@ -37,13 +37,18 @@ describe('--interactive', () => { 'utf-8', ) try { - const stdout = await spawn('node', [bin, '--interactive'], { - cwd: tempDir, - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + const { stdout } = await spawn( + 'node', + [bin, '--interactive'], + {}, + { + cwd: tempDir, + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + }, }, - }) + ) should.equal(/^Upgrading/m.test(stdout), true) @@ -74,13 +79,18 @@ describe('--interactive', () => { 'utf-8', ) try { - await spawn('node', [bin, '--interactive', '--format', 'group'], { - cwd: tempDir, - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + await spawn( + 'node', + [bin, '--interactive', '--format', 'group'], + {}, + { + cwd: tempDir, + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + }, }, - }) + ) const upgradedPkg = JSON.parse(await fs.readFile(pkgFile, 'utf-8')) upgradedPkg.dependencies.should.deep.equal({ @@ -114,13 +124,18 @@ describe('--interactive', () => { const configFile = path.join(tempDir, '.ncurc.js') await fs.writeFile(configFile, `module.exports = { groupFunction: () => 'minor' }`, 'utf-8') try { - await spawn('node', [bin, '--interactive', '--format', 'group', '--configFilePath', tempDir], { - cwd: tempDir, - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + await spawn( + 'node', + [bin, '--interactive', '--format', 'group', '--configFilePath', tempDir], + {}, + { + cwd: tempDir, + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['ncu-test-v2', 'ncu-test-return-version'], true]), + }, }, - }) + ) const upgradedPkg = JSON.parse(await fs.readFile(pkgFile, 'utf-8')) upgradedPkg.dependencies.should.deep.equal({ @@ -150,16 +165,21 @@ describe('--interactive', () => { 'utf-8', ) try { - await spawn('npm', ['install'], { cwd: tempDir }) - const output = await spawn('node', [bin, '--interactive', '--format', 'repo'], { - cwd: tempDir, - env: { - ...process.env, - INJECT_PROMPTS: JSON.stringify([['modern-diacritics'], true]), + await spawn('npm', ['install'], {}, { cwd: tempDir }) + const { stdout } = await spawn( + 'node', + [bin, '--interactive', '--format', 'repo'], + {}, + { + cwd: tempDir, + env: { + ...process.env, + INJECT_PROMPTS: JSON.stringify([['modern-diacritics'], true]), + }, }, - }) + ) - output.should.include('https://github.com/Mitsunee/modern-diacritics') + stdout.should.include('https://github.com/Mitsunee/modern-diacritics') } finally { await fs.rm(tempDir, { recursive: true, force: true }) } diff --git a/test/package-managers/deno/index.test.ts b/test/package-managers/deno/index.test.ts index 5b8b873a1..e6e752afc 100644 --- a/test/package-managers/deno/index.test.ts +++ b/test/package-managers/deno/index.test.ts @@ -20,12 +20,12 @@ describe('deno', async function () { } await fs.writeFile(pkgFile, JSON.stringify(pkg)) try { - const pkgData = await spawn( + const { stdout } = await spawn( 'node', [bin, '--jsonUpgraded', '--packageManager', 'deno', '--packageFile', pkgFile], undefined, ) - const pkg = jph.parse(pkgData) + const pkg = jph.parse(stdout) pkg.should.have.property('ncu-test-v2') } finally { await fs.rm(tempDir, { recursive: true, force: true }) @@ -42,10 +42,10 @@ describe('deno', async function () { } await fs.writeFile(pkgFile, JSON.stringify(pkg)) try { - const pkgData = await spawn('node', [bin, '--jsonUpgraded'], undefined, { + const { stdout } = await spawn('node', [bin, '--jsonUpgraded'], undefined, { cwd: tempDir, }) - const pkg = jph.parse(pkgData) + const pkg = jph.parse(stdout) pkg.should.have.property('ncu-test-v2') } finally { await fs.rm(tempDir, { recursive: true, force: true }) @@ -86,10 +86,10 @@ describe('deno', async function () { }` await fs.writeFile(pkgFile, pkgString) try { - const pkgData = await spawn('node', [bin, '--jsonUpgraded'], undefined, { + const { stdout } = await spawn('node', [bin, '--jsonUpgraded'], undefined, { cwd: tempDir, }) - const pkg = jph.parse(pkgData) + const pkg = jph.parse(stdout) pkg.should.have.property('ncu-test-v2') } finally { await fs.rm(tempDir, { recursive: true, force: true }) diff --git a/test/peer.test.ts b/test/peer.test.ts index ea9b5b50d..6fe3cfd6e 100644 --- a/test/peer.test.ts +++ b/test/peer.test.ts @@ -10,7 +10,7 @@ describe('peer dependencies', function () { it('peer dependencies of installed packages are ignored by default', async () => { const cwd = path.join(__dirname, 'test-data/peer/') try { - await spawnNpm('install', {}, { cwd }) + await spawnNpm('install', {}, {}, { cwd }) const upgrades = await ncu({ cwd }) upgrades!.should.deep.equal({ 'ncu-test-return-version': '2.0.0', @@ -24,7 +24,7 @@ describe('peer dependencies', function () { it('peer dependencies of installed packages are checked when using option peer', async () => { const cwd = path.join(__dirname, 'test-data/peer/') try { - await spawnNpm('install', {}, { cwd }) + await spawnNpm('install', {}, {}, { cwd }) const upgrades = await ncu({ cwd, peer: true }) upgrades!.should.deep.equal({ 'ncu-test-return-version': '1.1.0', @@ -38,7 +38,7 @@ describe('peer dependencies', function () { it('peer dependencies of installed packages are checked iteratively when using option peer', async () => { const cwd = path.join(__dirname, 'test-data/peer-update/') try { - await spawnNpm('install', {}, { cwd }) + await spawnNpm('install', {}, {}, { cwd }) const upgrades = await ncu({ cwd, peer: true }) upgrades!.should.deep.equal({ 'ncu-test-return-version': '1.1.0', diff --git a/test/rc-config.test.ts b/test/rc-config.test.ts index 50ae1fcd9..418ac5958 100644 --- a/test/rc-config.test.ts +++ b/test/rc-config.test.ts @@ -20,12 +20,10 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, '.ncurc.json') await fs.writeFile(tempConfigFile, JSON.stringify({ filter: 'ncu-test-v2' }), 'utf-8') try { - const text = await spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0', 'ncu-test-tag': '0.1.0' } }), - ) - text.should.containIgnoreCase(`Using config file ${tempConfigFile}`) + const { stdout } = await spawn('node', [bin, '--stdin', '--configFilePath', tempDir], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0', 'ncu-test-tag': '0.1.0' } }), + }) + stdout.should.containIgnoreCase(`Using config file ${tempConfigFile}`) } finally { await fs.rm(tempDir, { recursive: true, force: true }) } @@ -34,12 +32,10 @@ describe('rc-config', () => { it('do not print rcConfigPath when there is no rc config file', async () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) try { - const text = await spawn( - 'node', - [bin, '--stdin', '--cwd', tempDir], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), - ) - text.should.not.include('Using config file') + const { stdout } = await spawn('node', [bin, '--stdin', '--cwd', tempDir], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1.0.0' } }), + }) + stdout.should.not.include('Using config file') } finally { await fs.rm(tempDir, { recursive: true, force: true }) } @@ -50,12 +46,10 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, '.ncurc.json') await fs.writeFile(tempConfigFile, '{}', 'utf-8') try { - const text = await spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), - ) - text.should.not.include('Using config file') + const { stdout } = await spawn('node', [bin, '--stdin', '--configFilePath', tempDir], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + }) + stdout.should.not.include('Using config file') } finally { await fs.rm(tempDir, { recursive: true, force: true }) } @@ -65,11 +59,9 @@ describe('rc-config', () => { const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-')) const configFileName = '.ncurc_missing.json' try { - const result = spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir, '--configFileName', configFileName], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), - ) + const result = spawn('node', [bin, '--stdin', '--configFilePath', tempDir, '--configFileName', configFileName], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + }) await result.should.eventually.be.rejectedWith(`Config file ${configFileName} not found in ${tempDir}`) } finally { await fs.rm(tempDir, { recursive: true, force: true }) @@ -81,12 +73,10 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, '.ncurc.json') await fs.writeFile(tempConfigFile, JSON.stringify({ jsonUpgraded: true, filter: 'ncu-test-v2' }), 'utf-8') try { - const text = await spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), - ) - const pkgData = JSON.parse(text) + const { stdout } = await spawn('node', [bin, '--stdin', '--configFilePath', tempDir], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-v2') pkgData.should.not.have.property('ncu-test-tag') } finally { @@ -100,12 +90,12 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, tempConfigFileName) await fs.writeFile(tempConfigFile, JSON.stringify({ jsonUpgraded: true, filter: 'ncu-test-v2' }), 'utf-8') try { - const text = await spawn( + const { stdout } = await spawn( 'node', [bin, '--stdin', '--configFilePath', tempDir, '--configFileName', tempConfigFileName], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + { stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }) }, ) - const pkgData = JSON.parse(text) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-v2') pkgData.should.not.have.property('ncu-test-tag') } finally { @@ -118,12 +108,12 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, '.ncurc.json') await fs.writeFile(tempConfigFile, JSON.stringify({ jsonUpgraded: true, filter: 'ncu-test-v2' }), 'utf-8') try { - const text = await spawn( + const { stdout } = await spawn( 'node', [bin, '--stdin', '--configFilePath', tempDir, '--filter', 'ncu-test-tag'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + { stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }) }, ) - const pkgData = JSON.parse(text) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-tag') pkgData.should.not.have.property('ncu-test-v2') } finally { @@ -136,13 +126,11 @@ describe('rc-config', () => { const tempConfigFile = path.join(tempDir, '.ncurc.json') await fs.writeFile(tempConfigFile, JSON.stringify({ jsonUpgraded: true }), 'utf-8') try { - const output = await spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir, '--no-jsonUpgraded'], - JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), - ) + const { stdout } = await spawn('node', [bin, '--stdin', '--configFilePath', tempDir, '--no-jsonUpgraded'], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-v2': '1', 'ncu-test-tag': '0.1.0' } }), + }) // if the output contains "Using config file", then we know that jsonUpgraded was overridden - output.should.include('Using config file') + stdout.should.include('Using config file') } finally { await fs.rm(tempDir, { recursive: true, force: true }) } @@ -154,12 +142,10 @@ describe('rc-config', () => { // if boolean arguments are not handled as a special case, ncu will incorrectly pass "--deep false" to commander, which will interpret it as two args, i.e. --deep and --filter false await fs.writeFile(tempConfigFile, JSON.stringify({ jsonUpgraded: true, deep: false }), 'utf-8') try { - const text = await spawn( - 'node', - [bin, '--stdin', '--configFilePath', tempDir], - JSON.stringify({ dependencies: { 'ncu-test-tag': '0.1.0' } }), - ) - const pkgData = JSON.parse(text) + const { stdout } = await spawn('node', [bin, '--stdin', '--configFilePath', tempDir], { + stdin: JSON.stringify({ dependencies: { 'ncu-test-tag': '0.1.0' } }), + }) + const pkgData = JSON.parse(stdout) pkgData.should.have.property('ncu-test-tag') } finally { await fs.rm(tempDir, { recursive: true, force: true }) @@ -178,8 +164,8 @@ describe('rc-config', () => { ) try { // awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests - const text = await spawn('node', [bin, '--mergeConfig'], { cwd: tempDir }) - const firstLine = text.split('\n')[0] + const { stdout } = await spawn('node', [bin, '--mergeConfig'], {}, { cwd: tempDir }) + const firstLine = stdout.split('\n')[0] // On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345. // Apparently OSX symlinks /tmp to /private/tmp for historical reasons. // Therefore, ignore any directories prepended to the config file path. @@ -202,8 +188,8 @@ describe('rc-config', () => { ) try { // awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests - const text = await spawn('node', [bin, '--mergeConfig'], { cwd: tempDir }) - const firstLine = text.split('\n')[0] + const { stdout } = await spawn('node', [bin, '--mergeConfig'], {}, { cwd: tempDir }) + const firstLine = stdout.split('\n')[0] // On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345. // Apparently OSX symlinks /tmp to /private/tmp for historical reasons. // Therefore, ignore any directories prepended to the config file path. @@ -223,7 +209,7 @@ describe('rc-config', () => { try { // awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests - await spawn('node', [bin, '--mergeConfig'], { cwd: tempDir }) + await spawn('node', [bin, '--mergeConfig'], {}, { cwd: tempDir }) } finally { await fs.rm(tempDir, { recursive: true, force: true }) } diff --git a/test/timeout.test.ts b/test/timeout.test.ts index 4585bf3ec..08e340179 100644 --- a/test/timeout.test.ts +++ b/test/timeout.test.ts @@ -19,16 +19,14 @@ describe('timeout', function () { }) it('exit with error when timeout is exceeded', async () => { - return spawn( - 'node', - [bin, '--timeout', '1'], - '{ "dependencies": { "express": "1" } }', - ).should.eventually.be.rejectedWith('Exceeded global timeout of 1ms') + return spawn('node', [bin, '--timeout', '1'], { + stdin: '{ "dependencies": { "express": "1" } }', + }).should.eventually.be.rejectedWith('Exceeded global timeout of 1ms') }) it('completes successfully with timeout', async () => { const stub = stubNpmView('99.9.9', { spawn: true }) - await spawn('node', [bin, '--timeout', '100000'], '{ "dependencies": { "express": "1" } }') + await spawn('node', [bin, '--timeout', '100000'], { stdin: '{ "dependencies": { "express": "1" } }' }) stub.restore() }) }) diff --git a/test/workspaces.test.ts b/test/workspaces.test.ts index 3d64732d6..15cfd7570 100644 --- a/test/workspaces.test.ts +++ b/test/workspaces.test.ts @@ -136,7 +136,8 @@ describe('workspaces', () => { it('update workspaces with --workspaces', async () => { const tempDir = await setup(['packages/a']) try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.not.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -148,7 +149,8 @@ describe('workspaces', () => { it('update workspaces glob', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -161,7 +163,8 @@ describe('workspaces', () => { it('update workspaces with -ws', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '-ws'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '-ws'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -185,7 +188,8 @@ describe('workspaces', () => { ) try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output.should.not.have.property('other/package.json') @@ -201,7 +205,8 @@ describe('workspaces', () => { it('update workspaces/packages', async () => { const tempDir = await setup({ packages: ['packages/**'] }) try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -215,9 +220,8 @@ describe('workspaces', () => { it('ignore local workspace packages', async () => { const tempDir = await setupSymlinkedPackages() try { - const upgrades = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], { cwd: tempDir }).then( - JSON.parse, - ) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], {}, { cwd: tempDir }) + const upgrades = JSON.parse(stdout) upgrades.should.deep.equal({ 'package.json': {}, 'packages/foo/package.json': { @@ -235,9 +239,8 @@ describe('workspaces', () => { it('ignore local workspace packages with different names than their folders', async () => { const tempDir = await setupSymlinkedPackages(['packages/**'], 'chalk') try { - const upgrades = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], { cwd: tempDir }).then( - JSON.parse, - ) + const { stdout } = await spawn('node', [bin, '--jsonUpgraded', '--workspaces'], {}, { cwd: tempDir }) + const upgrades = JSON.parse(stdout) upgrades.should.deep.equal({ 'package.json': {}, 'packages/foo/package.json': { @@ -267,7 +270,8 @@ describe('workspaces', () => { it('update single workspace with --workspace', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.not.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -279,7 +283,8 @@ describe('workspaces', () => { it('update single workspace with -w', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '-w', 'a'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '-w', 'a'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.not.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -291,9 +296,15 @@ describe('workspaces', () => { it('update more than one workspace', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], { - cwd: tempDir, - }).then(JSON.parse) + const { stdout } = await spawn( + 'node', + [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], + {}, + { + cwd: tempDir, + }, + ) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -307,9 +318,15 @@ describe('workspaces', () => { const tempDir = await setup() try { // when npm-check-updates is executed in a workspace directory but uses --cwd to point up to the root, make sure that the root package.json is checked for the workspaces property - const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--cwd', '../../'], { - cwd: path.join(tempDir, 'packages', 'a'), - }).then(JSON.parse) + const { stdout } = await spawn( + 'node', + [bin, '--jsonAll', '--workspace', 'a', '--cwd', '../../'], + {}, + { + cwd: path.join(tempDir, 'packages', 'a'), + }, + ) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.not.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -322,9 +339,15 @@ describe('workspaces', () => { it('update namespaced workspace', async () => { const tempDir = await setupSymlinkedPackages(['packages/**'], '@ncu/bar') try { - const upgrades = await spawn('node', [bin, '--jsonUpgraded', '--workspace', '@ncu/bar'], { - cwd: tempDir, - }).then(JSON.parse) + const { stdout } = await spawn( + 'node', + [bin, '--jsonUpgraded', '--workspace', '@ncu/bar'], + {}, + { + cwd: tempDir, + }, + ) + const upgrades = JSON.parse(stdout) upgrades.should.deep.equal({ 'package.json': {}, 'packages/bar/package.json': { @@ -343,9 +366,8 @@ describe('workspaces', () => { it('update root project by default', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces', '--root'], { cwd: tempDir }).then( - JSON.parse, - ) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces', '--root'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('package.json') output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') @@ -360,9 +382,8 @@ describe('workspaces', () => { it('do not update the root project with --no-root', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces', '--no-root'], { cwd: tempDir }).then( - JSON.parse, - ) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces', '--no-root'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.not.have.property('package.json') output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') @@ -376,9 +397,14 @@ describe('workspaces', () => { it('update root project and workspaces if errorLevel=2', async () => { const tempDir = await setup() try { - await spawn('node', [bin, '--upgrade', '--workspaces', '--errorLevel', '2'], { - cwd: tempDir, - }).should.eventually.be.rejectedWith('Dependencies not up-to-date') + await spawn( + 'node', + [bin, '--upgrade', '--workspaces', '--errorLevel', '2'], + {}, + { + cwd: tempDir, + }, + ).should.eventually.be.rejectedWith('Dependencies not up-to-date') const upgradedPkg = JSON.parse(await fs.readFile(path.join(tempDir, 'package.json'), 'utf-8')) upgradedPkg.should.have.property('dependencies') upgradedPkg.dependencies.should.have.property('ncu-test-v2') @@ -410,7 +436,8 @@ describe('workspaces', () => { ) try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('package.json') output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') @@ -430,7 +457,8 @@ describe('workspaces', () => { it('update root project and single workspace', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspace', 'a'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('package.json') output.should.have.property('packages/a/package.json') output.should.not.have.property('packages/b/package.json') @@ -444,9 +472,15 @@ describe('workspaces', () => { it('update more than one workspace', async () => { const tempDir = await setup() try { - const output = await spawn('node', [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], { - cwd: tempDir, - }).then(JSON.parse) + const { stdout } = await spawn( + 'node', + [bin, '--jsonAll', '--workspace', 'a', '--workspace', 'b'], + {}, + { + cwd: tempDir, + }, + ) + const output = JSON.parse(stdout) output.should.have.property('package.json') output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') @@ -463,7 +497,8 @@ describe('workspaces', () => { it('read packages from pnpm-workspace.yaml', async () => { const tempDir = await setup(['packages/**'], { pnpm: true }) try { - const output = await spawn('node', [bin, '--jsonAll', '--workspaces'], { cwd: tempDir }).then(JSON.parse) + const { stdout } = await spawn('node', [bin, '--jsonAll', '--workspaces'], {}, { cwd: tempDir }) + const output = JSON.parse(stdout) output.should.have.property('packages/a/package.json') output.should.have.property('packages/b/package.json') output['packages/a/package.json'].dependencies.should.have.property('ncu-test-tag') @@ -478,18 +513,23 @@ describe('workspaces', () => { // cannot be stubbed because npm config printing occurs in viewMany describe('not stubbed', () => { // This test fails on Node v20.3.1 on Github Actions (only). - // The output fails to match the expected value: "npm config (workspace project):\n{ncutest: 'root' }" + // The stdout fails to match the expected value: "npm config (workspace project):\n{ncutest: 'root' }" // Strangely, it matches up to the single quote: "npm config (workspace project):\n{ncutest: " it.skip('merge local npm config with pnpm workspace npm config', async () => { const tempDir = await setup(['packages/**'], { pnpm: true }) try { await fs.writeFile(path.join(tempDir, '.npmrc'), 'ncutest=root') await fs.writeFile(path.join(tempDir, 'packages/a/.npmrc'), 'ncutest=a') - const output = await spawn('node', [bin, '--verbose', '--packageManager', 'pnpm'], { - cwd: path.join(tempDir, 'packages/a'), - }) - output.should.include(`npm config (workspace project):\n{ ncutest: 'root' }`) - output.should.include(`Using merged npm config:\n{\n ncutest: 'a',`) + const { stdout } = await spawn( + 'node', + [bin, '--verbose', '--packageManager', 'pnpm'], + {}, + { + cwd: path.join(tempDir, 'packages/a'), + }, + ) + stdout.should.include(`npm config (workspace project):\n{ ncutest: 'root' }`) + stdout.should.include(`Using merged npm config:\n{\n ncutest: 'a',`) } finally { await fs.rm(tempDir, { recursive: true, force: true }) } diff --git a/tsconfig.json b/tsconfig.json index 752951288..fa5ea8922 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,8 +15,7 @@ "noImplicitAny": true, "paths": { "libnpmconfig": ["./src/types/libnpmconfig"], - "prompts-ncu": ["./src/types/prompts-ncu"], - "spawn-please": ["./src/types/spawn-please"] + "prompts-ncu": ["./src/types/prompts-ncu"] }, "resolveJsonModule": true, "outDir": "./build",