mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 03:13:12 +00:00
fix(update): pre-remove package on Windows bun before reinstall
On Windows, bun's global binary symlink may not update properly when reinstalling the same package. Pre-remove the existing installation to ensure a clean update, mirroring the dev-install.sh behavior. Closes #435
This commit is contained in:
1 parent
e821a3bee6
commit
a55e0af8ef
1 file changed
+16
-5
@@ -189,8 +189,10 @@ async function performNpmUpdate(
|
|||||||
case 'bun':
|
case 'bun':
|
||||||
updateCommand = 'bun';
|
updateCommand = 'bun';
|
||||||
updateArgs = ['add', '-g', `@kaitranntt/ccs@${targetTag}`];
|
updateArgs = ['add', '-g', `@kaitranntt/ccs@${targetTag}`];
|
||||||
cacheCommand = null;
|
// On Windows, bun's global bin symlink may not update properly without removal first
|
||||||
cacheArgs = null;
|
// Pre-remove to ensure clean reinstall (mirrors dev-install.sh behavior)
|
||||||
|
cacheCommand = process.platform === 'win32' ? 'bun' : null;
|
||||||
|
cacheArgs = process.platform === 'win32' ? ['remove', '-g', '@kaitranntt/ccs'] : null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
updateCommand = 'npm';
|
updateCommand = 'npm';
|
||||||
@@ -271,7 +273,16 @@ async function performNpmUpdate(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (cacheCommand && cacheArgs) {
|
if (cacheCommand && cacheArgs) {
|
||||||
console.log(info('Clearing package cache...'));
|
// For bun on Windows, we pre-remove instead of cache clear
|
||||||
|
const isBunPreRemove = packageManager === 'bun' && cacheArgs.includes('remove');
|
||||||
|
const stepMessage = isBunPreRemove
|
||||||
|
? 'Removing existing installation...'
|
||||||
|
: 'Clearing package cache...';
|
||||||
|
const failMessage = isBunPreRemove
|
||||||
|
? 'Pre-removal failed, proceeding anyway...'
|
||||||
|
: 'Cache clearing failed, proceeding anyway...';
|
||||||
|
|
||||||
|
console.log(info(stepMessage));
|
||||||
// On Windows, use shell with full command string to avoid deprecation warning
|
// On Windows, use shell with full command string to avoid deprecation warning
|
||||||
const cacheChild = isWindows
|
const cacheChild = isWindows
|
||||||
? spawn(`${cacheCommand} ${cacheArgs.join(' ')}`, [], {
|
? spawn(`${cacheCommand} ${cacheArgs.join(' ')}`, [], {
|
||||||
@@ -283,13 +294,13 @@ async function performNpmUpdate(
|
|||||||
|
|
||||||
cacheChild.on('exit', (code) => {
|
cacheChild.on('exit', (code) => {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
console.log(warn('Cache clearing failed, proceeding anyway...'));
|
console.log(warn(failMessage));
|
||||||
}
|
}
|
||||||
performUpdate();
|
performUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
cacheChild.on('error', () => {
|
cacheChild.on('error', () => {
|
||||||
console.log(warn('Cache clearing failed, proceeding anyway...'));
|
console.log(warn(failMessage));
|
||||||
performUpdate();
|
performUpdate();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user