在自动更新执行 pnpm 时禁用跨存储确认阻塞

This commit is contained in:
yexi committed 2026-10-31 21:47:54 +08:00
1 parent b08da17e97
commit d09ce5c3ee
1 file changed
+11 -29
+11 -29
View File
@@ -82,37 +82,19 @@ async function readJsonFile(filePath) {
}
}
/** Detect the pnpm storeDir recorded in a profile's node_modules/.modules.yaml. */
async function detectProfileStoreDir(profileDir) {
const modulesYamlPath = path.join(profileDir, 'node_modules', '.modules.yaml')
try {
const raw = await fs.readFile(modulesYamlPath, 'utf8')
try {
const parsed = JSON.parse(raw)
if (typeof parsed?.storeDir === 'string' && parsed.storeDir.trim() !== '') {
return parsed.storeDir.trim()
}
} catch {
const match = raw.match(/^\s*"?storeDir"?\s*:\s*"?([^"\r\n]+)"?/m)
if (match?.[1]) return match[1].trim()
}
} catch {
// No .modules.yaml yet; let pnpm pick its default store.
}
return undefined
}
/** Run pnpm inside a profile directory using Desktop's bundled runtime or system pnpm. */
async function runPnpm(profileDir, args, packageManager) {
function runPnpm(profileDir, args, packageManager) {
const command = packageManager?.command ?? (process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm')
const storeDir = await detectProfileStoreDir(profileDir)
const storeArgs = storeDir !== undefined ? ['--store-dir', storeDir] : []
const fullArgs = [...(packageManager?.argsPrefix ?? []), '--dir', profileDir, ...storeArgs, ...args]
const env = {
...process.env,
...(packageManager?.env ?? {}),
...(storeDir !== undefined ? { npm_config_store_dir: storeDir } : {}),
}
const fullArgs = [
...(packageManager?.argsPrefix ?? []),
'--dir',
profileDir,
'--config.confirmModulesPurge=false',
...args,
]
const env = packageManager?.env !== undefined
? { ...process.env, ...packageManager.env }
: process.env
const useShell = packageManager?.command === undefined && process.platform === 'win32'
return new Promise((resolve, reject) => {
execFile(