优化了一下watchServer,在编译前先判断这个文件是否被appLoader使用,如果没有使用,则说明不被后端依赖,直接跳过

This commit is contained in:
Pan Qiancheng 2024-12-01 13:44:52 +08:00
parent 7ebe0c3eea
commit cceea8dd5e
1 changed files with 17 additions and 0 deletions

View File

@ -4,6 +4,7 @@ const chokidar = require('chokidar');
const { join } = require('path');
const ts = require('typescript');
const path = require('path');
const { resolve } = require('path');
const _ = require('lodash');
const { startup } = require('@xuchangzju/oak-cli/lib/server/start');
const projectPath = join(__dirname, '..');
@ -175,6 +176,22 @@ const onChangeDebounced = _.debounce(async (path, type) => {
// 控制台清空
console.clear();
console.warn(`File ${path} has been ${type}d`);
// 先判断一下这个文件在不在require.cache里面
const modulePath = resolve(path);
// 将src替换为lib
const libPath = modulePath.replace('\\src\\', '\\lib\\').replace('.ts', '.js');
if (!require.cache[libPath]) {
console.warn(`File ${libPath} is not in module cache, skiped.`);
isProcessing = false;
return;
} else {
// 如果是删除,则需要发出警告,文件正在被进程使用
if (type === 'remove') {
console.error(`File ${libPath} is being used, skiped.`);
isProcessing = false;
return;
}
}
const program = ts.createProgram({
rootNames: [path],
options,