Skip to content

Commit 368c2f4

Browse files
committed
Pass agentExecPath around
1 parent 0b2a745 commit 368c2f4

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/commands/optimize.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,24 @@ const updateManifestByAgent: Record<AgentPlusBun, AgentModifyManifestFn> = {
144144
}
145145
}
146146

147-
type AgentListDepsFn = (cwd: string, rootPath: string) => Promise<string>
147+
type AgentListDepsFn = (
148+
agentExecPath: string,
149+
cwd: string,
150+
rootPath: string
151+
) => Promise<string>
148152

149153
const lsByAgent: Record<AgentPlusBun, AgentListDepsFn> = {
150-
async bun(cwd: string, _rootPath: string) {
154+
async bun(agentExecPath: string, cwd: string, _rootPath: string) {
151155
try {
152-
return (await spawn('bun', ['pm', 'ls', '--all'], { cwd })).stdout
156+
return (await spawn(agentExecPath, ['pm', 'ls', '--all'], { cwd })).stdout
153157
} catch {}
154158
return ''
155159
},
156-
async npm(cwd: string, rootPath: string) {
160+
async npm(agentExecPath: string, cwd: string, rootPath: string) {
157161
try {
158162
;(
159163
await spawn(
160-
'npm',
164+
agentExecPath,
161165
['ls', '--parseable', '--include', 'prod', '--all'],
162166
{ cwd }
163167
)
@@ -167,11 +171,11 @@ const lsByAgent: Record<AgentPlusBun, AgentListDepsFn> = {
167171
} catch {}
168172
return ''
169173
},
170-
async pnpm(cwd: string, rootPath: string) {
174+
async pnpm(agentExecPath: string, cwd: string, rootPath: string) {
171175
try {
172176
return (
173177
await spawn(
174-
'pnpm',
178+
agentExecPath,
175179
['ls', '--parseable', '--prod', '--depth', 'Infinity'],
176180
{ cwd }
177181
)
@@ -181,14 +185,16 @@ const lsByAgent: Record<AgentPlusBun, AgentListDepsFn> = {
181185
} catch {}
182186
return ''
183187
},
184-
async yarn(cwd: string, _rootPath: string) {
188+
async yarn(agentExecPath: string, cwd: string, _rootPath: string) {
185189
try {
186190
return (
187-
await spawn('yarn', ['info', '--recursive', '--name-only'], { cwd })
191+
await spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
192+
cwd
193+
})
188194
).stdout
189195
} catch {}
190196
try {
191-
return (await spawn('yarn', ['list', '--prod'], { cwd })).stdout
197+
return (await spawn(agentExecPath, ['list', '--prod'], { cwd })).stdout
192198
} catch {}
193199
return ''
194200
}
@@ -233,7 +239,7 @@ function getDependencyEntries(pkgJson: PackageJsonContent) {
233239
}
234240

235241
async function getWorkspaces(
236-
agent: Agent,
242+
agent: AgentPlusBun,
237243
pkgPath: string,
238244
pkgJson: PackageJsonContent
239245
): Promise<string[] | undefined> {
@@ -279,7 +285,8 @@ function workspaceToGlobPattern(workspace: string): string {
279285
}
280286

281287
type AddOverridesConfig = {
282-
agent: Agent
288+
agent: AgentPlusBun
289+
agentExecPath: string
283290
lockSrc: string
284291
manifestEntries: ManifestEntry[]
285292
pkgJson?: EditablePackageJson | undefined
@@ -296,6 +303,7 @@ type AddOverridesState = {
296303
async function addOverrides(
297304
{
298305
agent,
306+
agentExecPath,
299307
lockSrc,
300308
manifestEntries,
301309
pkgJson: editablePkgJson,
@@ -315,7 +323,7 @@ async function addOverrides(
315323
const isRoot = pkgPath === rootPath
316324
const thingToScan = isRoot
317325
? lockSrc
318-
: await lsByAgent[agent](pkgPath, rootPath)
326+
: await lsByAgent[agent](agentExecPath, pkgPath, rootPath)
319327
const thingScanner = isRoot
320328
? lockIncludesByAgent[agent]
321329
: depsIncludesByAgent[agent]
@@ -421,6 +429,7 @@ async function addOverrides(
421429
await pEach(wsPkgJsonPaths, 3, async wsPkgJsonPath => {
422430
const { added, updated } = await addOverrides({
423431
agent,
432+
agentExecPath,
424433
lockSrc,
425434
manifestEntries,
426435
pin,
@@ -535,7 +544,8 @@ export const optimize: CliSubcommand = {
535544
)
536545
await addOverrides(
537546
{
538-
agent: agent === 'bun' ? 'yarn' : agent,
547+
agent,
548+
agentExecPath,
539549
lockSrc,
540550
manifestEntries,
541551
pin,

0 commit comments

Comments
 (0)