Skip to content

Commit 70f87d6

Browse files
committed
Use shell: true for WIN32
1 parent 81ae650 commit 70f87d6

File tree

2 files changed

+70
-25
lines changed

2 files changed

+70
-25
lines changed

src/commands/optimize/ls-by-agent.mts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ function parsableToQueryStdout(stdout: string) {
4747
async function npmQuery(npmExecPath: string, cwd: string): Promise<string> {
4848
let stdout = ''
4949
try {
50-
stdout = (await spawn(npmExecPath, ['query', ':not(.dev)'], { cwd })).stdout
50+
stdout = (
51+
await spawn(npmExecPath, ['query', ':not(.dev)'], {
52+
cwd,
53+
// Lazily access constants.WIN32.
54+
shell: constants.WIN32
55+
})
56+
).stdout
5157
} catch {}
5258
return cleanupQueryStdout(stdout)
5359
}
@@ -57,7 +63,11 @@ async function lsBun(pkgEnvDetails: EnvDetails, cwd: string): Promise<string> {
5763
// Bun does not support filtering by production packages yet.
5864
// https://github.com/oven-sh/bun/issues/8283
5965
return (
60-
await spawn(pkgEnvDetails.agentExecPath, ['pm', 'ls', '--all'], { cwd })
66+
await spawn(pkgEnvDetails.agentExecPath, ['pm', 'ls', '--all'], {
67+
cwd,
68+
// Lazily access constants.WIN32.
69+
shell: constants.WIN32
70+
})
6171
).stdout
6272
} catch {}
6373
return ''
@@ -87,7 +97,11 @@ async function lsPnpm(
8797
// Pnpm uses the alternative spelling of parsable.
8898
// https://en.wiktionary.org/wiki/parsable
8999
['ls', '--parseable', '--prod', '--depth', 'Infinity'],
90-
{ cwd }
100+
{
101+
cwd,
102+
// Lazily access constants.WIN32.
103+
shell: constants.WIN32
104+
}
91105
)
92106
).stdout
93107
} catch {}
@@ -103,7 +117,9 @@ async function lsVlt(pkgEnvDetails: EnvDetails, cwd: string): Promise<string> {
103117
pkgEnvDetails.agentExecPath,
104118
['ls', '--view', 'human', ':not(.dev)'],
105119
{
106-
cwd
120+
cwd,
121+
// Lazily access constants.WIN32.
122+
shell: constants.WIN32
107123
}
108124
)
109125
).stdout
@@ -124,7 +140,9 @@ async function lsYarnBerry(
124140
pkgEnvDetails.agentExecPath,
125141
['info', '--recursive', '--name-only'],
126142
{
127-
cwd
143+
cwd,
144+
// Lazily access constants.WIN32.
145+
shell: constants.WIN32
128146
}
129147
)
130148
).stdout.trim()
@@ -143,7 +161,11 @@ async function lsYarnClassic(
143161
// > Fix: Excludes dev dependencies from the yarn list output when the
144162
// environment is production
145163
return (
146-
await spawn(pkgEnvDetails.agentExecPath, ['list', '--prod'], { cwd })
164+
await spawn(pkgEnvDetails.agentExecPath, ['list', '--prod'], {
165+
cwd,
166+
// Lazily access constants.WIN32.
167+
shell: constants.WIN32
168+
})
147169
).stdout.trim()
148170
} catch {}
149171
return ''

src/utils/package-environment.mts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ async function getAgentVersion(
7070
// and tildes (~).
7171
semver.coerce(
7272
// All package managers support the "--version" flag.
73-
(await spawn(agentExecPath, ['--version'], { cwd })).stdout
73+
(
74+
await spawn(agentExecPath, ['--version'], {
75+
cwd,
76+
// Lazily access constants.WIN32.
77+
shell: constants.WIN32
78+
})
79+
).stdout
7480
) ?? undefined
7581
} catch (e) {
7682
debugLog('getAgentVersion error:\n', e)
@@ -103,6 +109,11 @@ const LOCKS: Record<string, Agent> = {
103109
type ReadLockFile =
104110
| ((lockPath: string) => Promise<string | undefined>)
105111
| ((lockPath: string, agentExecPath: string) => Promise<string | undefined>)
112+
| ((
113+
lockPath: string,
114+
agentExecPath: string,
115+
cwd: string
116+
) => Promise<string | undefined>)
106117

107118
const readLockFileByAgent: Map<Agent, ReadLockFile> = (() => {
108119
function wrapReader<T extends (...args: any[]) => Promise<any>>(
@@ -125,25 +136,37 @@ const readLockFileByAgent: Map<Agent, ReadLockFile> = (() => {
125136
return new Map([
126137
[
127138
BUN,
128-
wrapReader(async (lockPath: string, agentExecPath: string) => {
129-
const ext = path.extname(lockPath)
130-
if (ext === LOCK_EXT) {
131-
return await defaultReader(lockPath)
132-
}
133-
if (ext === BINARY_LOCK_EXT) {
134-
const lockBuffer = await binaryReader(lockPath)
135-
if (lockBuffer) {
136-
try {
137-
return parseBunLockb(lockBuffer)
138-
} catch {}
139+
wrapReader(
140+
async (
141+
lockPath: string,
142+
agentExecPath: string,
143+
cwd = process.cwd()
144+
) => {
145+
const ext = path.extname(lockPath)
146+
if (ext === LOCK_EXT) {
147+
return await defaultReader(lockPath)
148+
}
149+
if (ext === BINARY_LOCK_EXT) {
150+
const lockBuffer = await binaryReader(lockPath)
151+
if (lockBuffer) {
152+
try {
153+
return parseBunLockb(lockBuffer)
154+
} catch {}
155+
}
156+
// To print a Yarn lockfile to your console without writing it to disk
157+
// use `bun bun.lockb`.
158+
// https://bun.sh/guides/install/yarnlock
159+
return (
160+
await spawn(agentExecPath, [lockPath], {
161+
cwd,
162+
// Lazily access constants.WIN32.
163+
shell: constants.WIN32
164+
})
165+
).stdout.trim()
139166
}
140-
// To print a Yarn lockfile to your console without writing it to disk
141-
// use `bun bun.lockb`.
142-
// https://bun.sh/guides/install/yarnlock
143-
return (await spawn(agentExecPath, [lockPath])).stdout.trim()
167+
return undefined
144168
}
145-
return undefined
146-
})
169+
)
147170
],
148171
[NPM, defaultReader],
149172
[PNPM, defaultReader],
@@ -314,7 +337,7 @@ export async function detectPackageEnvironment({
314337
}
315338
lockSrc =
316339
typeof lockPath === 'string'
317-
? await readLockFileByAgent.get(agent)!(lockPath, agentExecPath)
340+
? await readLockFileByAgent.get(agent)!(lockPath, agentExecPath, cwd)
318341
: undefined
319342
} else {
320343
lockName = undefined

0 commit comments

Comments
 (0)