From b08da17e97dc75883dc6d378fbac20b1eeaaa054 Mon Sep 17 00:00:00 2001 From: yexi Date: Sat, 31 Oct 2026 21:46:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=A8=E7=9B=98=E7=AC=A6?= =?UTF-8?q?=20Profile=20=E6=9B=B4=E6=96=B0=E6=97=B6=E7=9A=84=20pnpm=20stor?= =?UTF-8?q?e-dir=20=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/node.js b/src/node.js index c705f02..1ebc61c 100644 --- a/src/node.js +++ b/src/node.js @@ -82,13 +82,37 @@ 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. */ -function runPnpm(profileDir, args, packageManager) { +async function runPnpm(profileDir, args, packageManager) { const command = packageManager?.command ?? (process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm') - const fullArgs = [...(packageManager?.argsPrefix ?? []), '--dir', profileDir, ...args] - const env = packageManager?.env !== undefined - ? { ...process.env, ...packageManager.env } - : process.env + 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 useShell = packageManager?.command === undefined && process.platform === 'win32' return new Promise((resolve, reject) => { execFile(