修复 deps 目录依赖逻辑

This commit is contained in:
whyour
2026-06-21 12:12:29 +08:00
parent b5a5fb3be6
commit 369dd13212
4 changed files with 13 additions and 34 deletions
+1 -25
View File
@@ -1,22 +1,9 @@
import path from 'path';
import fs from 'fs/promises';
import os from 'os';
import chokidar from 'chokidar';
import config from '../config/index';
import Logger from './logger';
async function linkToNodeModule(src: string, dst?: string) {
const target = path.join(config.rootPath, 'node_modules', dst || src);
const source = path.join(config.rootPath, src);
try {
const stats = await fs.lstat(target);
if (!stats) {
await fs.symlink(source, target, 'dir');
}
} catch (error) { }
}
async function linkCommand() {
const homeDir = os.homedir();
let userBinDir = path.join(homeDir, 'bin');
@@ -59,17 +46,6 @@ async function linkCommandToDir(commandDir: string) {
}
}
export default async (src: string = 'deps') => {
export default async () => {
await linkCommand();
await linkToNodeModule(src);
const source = path.join(config.rootPath, src);
const watcher = chokidar.watch(source, {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
});
watcher
.on('add', () => linkToNodeModule(src))
.on('change', () => linkToNodeModule(src));
};