Skip to content

Commit

Permalink
Revert "Sanitize spawn calls which contain .cmd for win32 (#1465)"
Browse files Browse the repository at this point in the history
This reverts commit 6d446d7.
  • Loading branch information
phaze-ZA authored Oct 16, 2024
1 parent 6d446d7 commit affd440
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ const install = async (
// See: https://github.com/raineorshine/npm-check-updates/issues/1191
...(packageManager === 'pnpm' ? { npm_config_strict_peer_dependencies: false } : null),
},
shell: process.platform === 'win32',
},
)
print(options, stdout)
Expand Down
4 changes: 1 addition & 3 deletions src/package-managers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,17 +609,15 @@ export async function defaultPrefix(options: Options): Promise<string | undefine
if (options.prefix) {
return Promise.resolve(options.prefix)
}
const spawnOptions = {}

const cmd = process.platform === 'win32' ? 'npm.cmd' : 'npm'
const sanitizedSpawnOptions = process.platform === 'win32' ? { ...spawnOptions, shell: true } : spawnOptions

let prefix: string | undefined

// catch spawn error which can occur on Windows
// https://github.com/raineorshine/npm-check-updates/issues/703
try {
const { stdout } = await spawn(cmd, ['config', 'get', 'prefix'], {}, sanitizedSpawnOptions)
const { stdout } = await spawn(cmd, ['config', 'get', 'prefix'])
prefix = stdout
} catch (e: any) {
const message = (e.message || e || '').toString()
Expand Down
9 changes: 3 additions & 6 deletions src/package-managers/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ export const list = async (options: Options = {}): Promise<Index<string | undefi
// use npm for local ls for completeness
// this should never happen since list is only called in runGlobal -> getInstalledPackages
if (!options.global) return npm.list(options)
const spawnOptions = {}

const cmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'
const sanitzedSpawnOptions = process.platform === 'win32' ? { ...spawnOptions, shell: true } : spawnOptions
const { stdout } = await spawn(cmd, ['ls', '-g', '--json'], {}, sanitzedSpawnOptions)
const { stdout } = await spawn(cmd, ['ls', '-g', '--json'])
const result = JSON.parse(stdout) as PnpmList
const list = keyValueBy(result[0].dependencies || {}, (name, { version }) => ({
[name]: version,
Expand Down Expand Up @@ -93,19 +91,18 @@ export const semver = withNpmWorkspaceConfig(npm.semver)
async function spawnPnpm(
args: string | string[],
npmOptions: NpmOptions = {},
spawnOptions: SpawnOptions = {},
spawnOptions?: SpawnOptions,
spawnPleaseOptions?: SpawnPleaseOptions,
): Promise<string> {
const cmd = process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'
const sanitzedSpawnOptions = process.platform === 'win32' ? { ...spawnOptions, shell: true } : spawnOptions

const fullArgs = [
...(npmOptions.global ? 'global' : []),
...(Array.isArray(args) ? args : [args]),
...(npmOptions.prefix ? `--prefix=${npmOptions.prefix}` : []),
]

const { stdout } = await spawn(cmd, fullArgs, spawnPleaseOptions, sanitzedSpawnOptions)
const { stdout } = await spawn(cmd, fullArgs, spawnPleaseOptions, spawnOptions)

return stdout
}
Expand Down
4 changes: 1 addition & 3 deletions src/package-managers/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ export async function defaultPrefix(options: Options): Promise<string | null> {
if (options.prefix) {
return Promise.resolve(options.prefix)
}
const spawnOptions = {}

const cmd = process.platform === 'win32' ? 'yarn.cmd' : 'yarn'
const sanitizedSpawnOptions = process.platform === 'win32' ? { ...spawnOptions, shell: true } : spawnOptions

const { stdout: prefix } = await spawn(cmd, ['global', 'dir'], {}, sanitizedSpawnOptions)
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
Expand Down
1 change: 0 additions & 1 deletion src/types/SpawnOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ import { Index } from './IndexType'
export interface SpawnOptions {
cwd?: string
env?: Index<string>
shell?: boolean
}

0 comments on commit affd440

Please sign in to comment.