fix wrapper version for npm (#1458)

This commit is contained in:
Tong Chen 2026-03-06 17:04:33 +08:00 committed by GitHub
parent 72e5c36bf5
commit 4371a71f59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -961,7 +961,8 @@ export function ensureNpmWrappersForBrowserToolkit(
const eigentBinDir = path.join(os.homedir(), '.eigent', 'bin');
fs.mkdirSync(eigentBinDir, { recursive: true });
const wrapperVersion = '1';
// Store wrapper target so wrappers are recreated when venv path changes (e.g. app upgrade)
const wrapperVersion = `wrapper:${pythonPath}`;
const versionFile = path.join(eigentBinDir, '.npm_wrapper_version');
const storedVersion = fs.existsSync(versionFile)
? fs.readFileSync(versionFile, 'utf-8').trim()
@ -976,10 +977,14 @@ export function ensureNpmWrappersForBrowserToolkit(
process.platform === 'win32' ? 'npx.cmd' : 'npx'
);
// Recreate wrappers when: version changed, wrappers missing, or existing shebang points to wrong Python
const needsUpdate =
storedVersion !== wrapperVersion ||
!fs.existsSync(npmWrapper) ||
!fs.existsSync(npxWrapper);
!fs.existsSync(npxWrapper) ||
(process.platform !== 'win32' &&
fs.existsSync(npmWrapper) &&
!fs.readFileSync(npmWrapper, 'utf-8').startsWith(`#!${pythonPath}`));
if (needsUpdate) {
try {