mirror of
https://github.com/yexi-by/dsh-unrestricted.git
synced 2026-11-28 10:30:23 +08:00
修复跨盘符 Profile 更新时的 pnpm store-dir 识别
This commit is contained in:
1 parent
829bb9228d
commit
b08da17e97
1 file changed
+29
-5
+29
-5
@@ -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. */
|
/** 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 command = packageManager?.command ?? (process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm')
|
||||||
const fullArgs = [...(packageManager?.argsPrefix ?? []), '--dir', profileDir, ...args]
|
const storeDir = await detectProfileStoreDir(profileDir)
|
||||||
const env = packageManager?.env !== undefined
|
const storeArgs = storeDir !== undefined ? ['--store-dir', storeDir] : []
|
||||||
? { ...process.env, ...packageManager.env }
|
const fullArgs = [...(packageManager?.argsPrefix ?? []), '--dir', profileDir, ...storeArgs, ...args]
|
||||||
: process.env
|
const env = {
|
||||||
|
...process.env,
|
||||||
|
...(packageManager?.env ?? {}),
|
||||||
|
...(storeDir !== undefined ? { npm_config_store_dir: storeDir } : {}),
|
||||||
|
}
|
||||||
const useShell = packageManager?.command === undefined && process.platform === 'win32'
|
const useShell = packageManager?.command === undefined && process.platform === 'win32'
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
execFile(
|
execFile(
|
||||||
|
|||||||
Reference in new issue
Block a user