From 8ad081d803466ce2d1608a32ff3cca4c605b37a9 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Thu, 23 Jan 2025 12:06:04 +0800 Subject: [PATCH] fix: use pre hook order to promise dts task --- packages/plugin-dts/src/index.ts | 44 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/plugin-dts/src/index.ts b/packages/plugin-dts/src/index.ts index b7fba3def..63c07258d 100644 --- a/packages/plugin-dts/src/index.ts +++ b/packages/plugin-dts/src/index.ts @@ -135,35 +135,35 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({ }, ); - api.onAfterBuild(async ({ isFirstCompile }) => { - if (!isFirstCompile) { - return; - } - - promisesResult = await Promise.all(dtsPromises); - }); - api.onAfterBuild({ - handler: ({ isFirstCompile }) => { + handler: async ({ isFirstCompile }) => { if (!isFirstCompile) { return; } - for (const result of promisesResult) { - if (result.status === 'error') { - if (options.abortOnError) { - throw new Error(result.errorMessage); - } - result.errorMessage && logger.error(result.errorMessage); - logger.warn( - 'With the `abortOnError` configuration currently turned off, type errors do not cause build failures, but they do not guarantee proper type file output.', - ); + promisesResult = await Promise.all(dtsPromises); + }, + // Set the order to 'pre' to ensure that when DTS files of multiple formats are generated simultaneously, + // all errors are thrown together before exiting the process. + order: 'pre', + }); + + api.onAfterBuild(({ isFirstCompile }) => { + if (!isFirstCompile) { + return; + } + + for (const result of promisesResult) { + if (result.status === 'error') { + if (options.abortOnError) { + throw new Error(result.errorMessage); } + result.errorMessage && logger.error(result.errorMessage); + logger.warn( + 'With the `abortOnError` configuration currently turned off, type errors do not cause build failures, but they do not guarantee proper type file output.', + ); } - }, - // Set the order to 'post' to ensure that when DTS files of multiple formats are generated - // simultaneously, all errors are thrown together before exiting the process. - order: 'post', + } }); const killProcesses = () => {