From 941401cc36ed163d4f26a7d2b84d7ef9486e6450 Mon Sep 17 00:00:00 2001 From: 2heal1 Date: Tue, 21 Jan 2025 19:12:06 +0800 Subject: [PATCH] fix: order issue --- .../src/plugins/GenerateTypesPlugin.ts | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts index 5c62059f3d..c3855d16f8 100644 --- a/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts +++ b/packages/dts-plugin/src/plugins/GenerateTypesPlugin.ts @@ -92,12 +92,11 @@ export class GenerateTypesPlugin implements WebpackPluginInstance { const emitTypesFiles = async (compilation: Compilation) => { // Dev types will be generated by DevPlugin, the archive filename usually is dist/.dev-server.zip try { - await consumeTypesPromise; - const { zipTypesPath, apiTypesPath, zipName, apiFileName } = retrieveTypesAssetsInfo(finalOptions.remote); if (isProd && zipName && compilation.getAsset(zipName)) { + callback(); return; } @@ -153,19 +152,15 @@ export class GenerateTypesPlugin implements WebpackPluginInstance { compiler.outputFileSystem.mkdir( path.dirname(zipOutputPath), (err) => { - if (err) { - if (!isEEXIST(err)) { - reject(err); - } + if (err && !isEEXIST(err)) { + reject(err); } else { compiler.outputFileSystem.writeFile( zipOutputPath, zipContent, (writeErr) => { - if (writeErr) { - if (!isEEXIST(writeErr)) { - reject(writeErr); - } + if (writeErr && !isEEXIST(writeErr)) { + reject(writeErr); } else { resolve(); } @@ -188,19 +183,15 @@ export class GenerateTypesPlugin implements WebpackPluginInstance { compiler.outputFileSystem.mkdir( path.dirname(apiOutputPath), (err) => { - if (err) { - if (!isEEXIST(err)) { - reject(err); - } + if (err && !isEEXIST(err)) { + reject(err); } else { compiler.outputFileSystem.writeFile( apiOutputPath, apiContent, (writeErr) => { - if (writeErr) { - if (!isEEXIST(writeErr)) { - reject(writeErr); - } + if (writeErr && !isEEXIST(writeErr)) { + reject(writeErr); } else { resolve(); } @@ -231,6 +222,7 @@ export class GenerateTypesPlugin implements WebpackPluginInstance { compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER, }, async () => { + await consumeTypesPromise; const emitTypesFilesPromise = emitTypesFiles(compilation); if (isProd) { await emitTypesFilesPromise;