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!;