From 9a50ce03d3c64b08c08fc32e5bff94d1aee3a3c1 Mon Sep 17 00:00:00 2001 From: qcqcqc <1220204124@zust.edu.cn> Date: Tue, 4 Nov 2025 10:01:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=A8=A1=E5=9D=97=E6=97=B6=E6=9B=B4=E6=96=B0configura?= =?UTF-8?q?tion/compiler.js=E4=BC=9A=E5=87=BA=E7=8E=B0=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/create.js | 6 ++++-- lib/file-handle.d.ts | 2 +- lib/template.js | 7 ++++++- src/create.ts | 6 ++++-- src/template.ts | 9 +++++++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/create.js b/lib/create.js index b30d4c1..f1a5b1b 100644 --- a/lib/create.js +++ b/lib/create.js @@ -234,8 +234,10 @@ async function create(dirName, cmd) { (0, file_handle_1.checkFileExistsAndCreate)(tsConfigMpJsonPath, tsConfigMpJson, enum_1.checkFileExistsAndCreateType.FILE); // 创建tsconfig.web.json (0, file_handle_1.checkFileExistsAndCreate)(tsConfigWebJsonPath, tsConfigWebJson, enum_1.checkFileExistsAndCreateType.FILE); - // 更新configuration/compiler.js - (0, template_1.updateCompilerJsContent)(rootPath, deps); + // 更新configuration/compiler.js (仅在非模块化模式下) + if (!isModule) { + (0, template_1.updateCompilerJsContent)(rootPath, deps); + } (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Successfully created project ${(0, tip_style_1.primary)(name)}, directory name is ${(0, tip_style_1.primary)(dirName)}`)}`); shelljs_1.default.cd(dirName); if (deps.length > 0) { diff --git a/lib/file-handle.d.ts b/lib/file-handle.d.ts index c3136cd..9f0f136 100644 --- a/lib/file-handle.d.ts +++ b/lib/file-handle.d.ts @@ -37,7 +37,7 @@ export declare function writeFile(path: string | PathLike, data: any): void; export declare function readFile(path: string | PathLike, options?: { encoding?: null | undefined; flag?: string | undefined; -} | null): Buffer | undefined; +} | null): NonSharedBuffer | undefined; /** * @name 拷贝文件夹 * @export diff --git a/lib/template.js b/lib/template.js index e1e16cc..cb0e8e3 100644 --- a/lib/template.js +++ b/lib/template.js @@ -636,8 +636,13 @@ function oakConfigContentWithWeb() { } function updateCompilerJsContent(directory, deps) { const compilerJsPath = (0, path_1.join)(directory, 'configuration', 'compiler.js'); - (0, assert_1.default)((0, fs_1.existsSync)(compilerJsPath)); + // 只有在有依赖项时才需要修改 compiler.js if (deps.length > 0) { + // 检查文件是否存在 + if (!(0, fs_1.existsSync)(compilerJsPath)) { + console.warn(`Warning: ${compilerJsPath} does not exist, skipping compiler.js update`); + return; + } const { ast } = (0, core_1.transformFileSync)(compilerJsPath, { ast: true }); const { program } = ast; const { body } = program; diff --git a/src/create.ts b/src/create.ts index 8efbdd8..d26c1ef 100644 --- a/src/create.ts +++ b/src/create.ts @@ -356,8 +356,10 @@ export async function create(dirName: string, cmd: any) { tsConfigWebJson, checkFileExistsAndCreateType.FILE ); - // 更新configuration/compiler.js - updateCompilerJsContent(rootPath, deps); + // 更新configuration/compiler.js (仅在非模块化模式下) + if (!isModule) { + updateCompilerJsContent(rootPath, deps); + } Success( `${success( `Successfully created project ${primary( diff --git a/src/template.ts b/src/template.ts index fa75c07..f76fa05 100644 --- a/src/template.ts +++ b/src/template.ts @@ -663,9 +663,14 @@ export function oakConfigContentWithWeb() { export function updateCompilerJsContent(directory: string, deps: string[]) { const compilerJsPath = join(directory, 'configuration', 'compiler.js'); - assert(existsSync(compilerJsPath)); - + + // 只有在有依赖项时才需要修改 compiler.js if (deps.length > 0) { + // 检查文件是否存在 + if (!existsSync(compilerJsPath)) { + console.warn(`Warning: ${compilerJsPath} does not exist, skipping compiler.js update`); + return; + } const { ast } = transformFileSync(compilerJsPath, { ast: true })!; const { program } = ast!; const { body } = program!;