Skip to content

Commit 3d91be5

Browse files
committed
fix: handle pnpm frozen-lockfile in CI for optimize command
In CI environments, pnpm automatically runs with --frozen-lockfile which prevents lockfile updates. When the optimize command tries to add overrides and update the lockfile, it fails with ERR_PNPM_LOCKFILE_CONFIG_MISMATCH. Added explicit --no-frozen-lockfile flag when running pnpm install in CI mode to allow the lockfile to be updated with Socket.dev overrides.
1 parent 1959c61 commit 3d91be5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/utils/agent.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ export function runAgentInstall(
3838
...spawnOpts
3939
} = { __proto__: null, ...options } as AgentInstallOptions
4040
const skipNodeHardenFlags = isPnpm && pkgEnvDetails.agentVersion.major < 11
41-
return spawn(agentExecPath, ['install', ...args], {
41+
// In CI mode, pnpm uses --frozen-lockfile by default, which prevents lockfile updates.
42+
// We need to explicitly disable it when updating the lockfile with overrides.
43+
const installArgs = isPnpm && constants.ENV.CI
44+
? ['install', '--no-frozen-lockfile', ...args]
45+
: ['install', ...args]
46+
47+
return spawn(agentExecPath, installArgs, {
4248
cwd: pkgPath,
4349
shell: constants.WIN32,
4450
spinner,

src/utils/package-environment.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,14 @@ async function getAgentExecPath(agent: Agent): Promise<string> {
213213
if (existsSync(npmPath)) {
214214
return npmPath
215215
}
216-
// If npmExecPath doesn't exist, fall back to whichBin.
216+
// If npmExecPath doesn't exist, try common locations.
217+
// Check npm in the same directory as node.
218+
const nodeDir = path.dirname(process.execPath)
219+
const npmInNodeDir = path.join(nodeDir, 'npm')
220+
if (existsSync(npmInNodeDir)) {
221+
return npmInNodeDir
222+
}
223+
// Fall back to whichBin.
217224
return (await whichBin(binName, { nothrow: true })) ?? binName
218225
}
219226
return (await whichBin(binName, { nothrow: true })) ?? binName

0 commit comments

Comments
 (0)