修复 task 命令可能软链失败

This commit is contained in:
whyour 2025-10-11 23:15:54 +08:00
parent e4f733320d
commit a7baeba755

View File

@ -13,7 +13,7 @@ async function linkToNodeModule(src: string, dst?: string) {
if (!stats) { if (!stats) {
await fs.symlink(source, target, 'dir'); await fs.symlink(source, target, 'dir');
} }
} catch (error) {} } catch (error) { }
} }
async function linkCommand() { async function linkCommand() {
@ -36,6 +36,10 @@ async function linkCommand() {
const source = path.join(config.rootPath, 'shell', link.src); const source = path.join(config.rootPath, 'shell', link.src);
const target = path.join(commandDir, link.dest); const target = path.join(commandDir, link.dest);
const tmpTarget = path.join(commandDir, link.tmp); const tmpTarget = path.join(commandDir, link.tmp);
const stats = await fs.lstat(tmpTarget);
if (stats) {
await fs.unlink(tmpTarget);
}
await fs.symlink(source, tmpTarget); await fs.symlink(source, tmpTarget);
await fs.rename(tmpTarget, target); await fs.rename(tmpTarget, target);
} }