fix: 修复了非ts文件修改时,未处理源文件路径导致误删除的bug

This commit is contained in:
Pan Qiancheng 2025-12-20 14:42:19 +08:00
parent 09d14be5e7
commit 35095a0219
2 changed files with 4 additions and 4 deletions

View File

@ -280,11 +280,12 @@ const createCompiler = async (projectPath, options, projectReferences, treatFile
};
const compileTask = async (task) => {
const { filePath, changeType } = task;
const modulePath = path_1.default.resolve(filePath);
// 判断文件类型
if (!filePath.endsWith(".ts")) {
// 处理非TypeScript文件 (如JSON文件)
if (filePath.endsWith(".json")) {
const targetPath = filePath.replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib"));
const targetPath = modulePath.replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib"));
try {
if (changeType === "remove") {
if (fs_1.default.existsSync(targetPath)) {
@ -331,7 +332,6 @@ const createCompiler = async (projectPath, options, projectReferences, treatFile
// 处理TypeScript文件
console.clear();
console.warn(`File ${filePath} has been ${changeType}d`);
const modulePath = path_1.default.resolve(filePath);
const libPath = modulePath
.replace(path_1.default.join(projectPath, "src"), path_1.default.join(projectPath, "lib"))
.replace(/\.ts$/, ".js");

View File

@ -477,11 +477,12 @@ const createCompiler = async (
const compileTask = async (task: CompileTask): Promise<CompileResult> => {
const { filePath, changeType } = task;
const modulePath = pathLib.resolve(filePath);
// 判断文件类型
if (!filePath.endsWith(".ts")) {
// 处理非TypeScript文件 (如JSON文件)
if (filePath.endsWith(".json")) {
const targetPath = filePath.replace(
const targetPath = modulePath.replace(
pathLib.join(projectPath, "src"),
pathLib.join(projectPath, "lib")
);
@ -533,7 +534,6 @@ const createCompiler = async (
console.clear();
console.warn(`File ${filePath} has been ${changeType}d`);
const modulePath = pathLib.resolve(filePath);
const libPath = modulePath
.replace(pathLib.join(projectPath, "src"), pathLib.join(projectPath, "lib"))
.replace(/\.ts$/, ".js");