Skip to content

Commit

Permalink
add shell:true to npm spawns for windows benefit
Browse files Browse the repository at this point in the history
Re: #988

Similar to #990, but without adding cross-spawn as a dep.
  • Loading branch information
isaacs committed Jan 19, 2024
1 parent 5e28526 commit 81dd0ad
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
11 changes: 9 additions & 2 deletions scripts/version.mts
Expand Up @@ -84,7 +84,11 @@ const run = (
args: string[] = [],
options: SpawnSyncOptions = {}
) => {
const res = spawnSync(cmd, args, { ...options, encoding: 'utf8' })
const res = spawnSync(cmd, args, {
...options,
encoding: 'utf8',
shell: true,
})
if (res.error || res.status || res.signal) {
const cause = {
cmd,
Expand Down Expand Up @@ -463,7 +467,10 @@ const pubAll = () => {
if (!pubs.length) {
console.log('all packages published')
}
console.error('PUBS', pubs.map(p => [p.name, p.version]))
console.error(
'PUBS',
pubs.map(p => [p.name, p.version])
)
for (const p of pubs) {
const tag = parse(p.version)?.prerelease?.length
? 'pre'
Expand Down
3 changes: 3 additions & 0 deletions src/run/src/npm.ts
Expand Up @@ -31,6 +31,7 @@ const npmGetPrefix = (cwd: string) =>
env: npmFreeEnv,
encoding: 'utf8',
cwd,
shell: true,
}).stdout || null

export const npmFindCwd = async (globCwd: string): Promise<string> =>
Expand All @@ -57,6 +58,7 @@ export const npmBg = (args: string[], config: LoadedConfig) =>
env: npmFreeEnv,
encoding: 'utf8',
cwd: npmCwd || config.globCwd,
shell: true,
})

/**
Expand Down Expand Up @@ -84,6 +86,7 @@ const npmFg = (
{
env: npmFreeEnv,
cwd: npmCwd || config.globCwd,
shell: true,
/* c8 ignore stop */
},
cb
Expand Down
6 changes: 6 additions & 0 deletions src/run/tap-snapshots/test/npm.ts.test.cjs
Expand Up @@ -25,6 +25,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
Function (code, signal),
],
Expand All @@ -48,6 +49,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
],
]
Expand All @@ -72,6 +74,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
Function (code, signal),
],
Expand All @@ -98,6 +101,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
Function (code, signal),
],
Expand All @@ -121,6 +125,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
],
]
Expand All @@ -145,6 +150,7 @@ Array [
"env": Object {
"ok": true,
},
"shell": true,
},
Function (code, signal),
],
Expand Down
14 changes: 13 additions & 1 deletion src/test/scripts/build.mts
Expand Up @@ -429,7 +429,19 @@ writeFileSync(
const nm = resolve(dir, 'node_modules')
mkdirpSync(resolve(nm, '@tapjs'))
symlinkSync('../..', resolve(nm, '@tapjs/test-built'))
spawnSync('npm', ['run', 'prepare'], { cwd: dir, stdio: 'inherit' })
const res = spawnSync('npm', ['run', 'prepare'], {
shell: true,
cwd: dir,
stdio: 'inherit',
})
if (res.status !== 0 || res.signal !== null) {
console.error('`npm run prepare` failed', {
code: res.status,
signal: res.signal,
...( res.error && { error: res.error })
})
process.exitCode = 1
}
rimrafSync(nm)

export {}

0 comments on commit 81dd0ad

Please sign in to comment.