From 7bd17f1a42371d5720d7dab94dcd87d1db854fa6 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 5 Aug 2024 13:04:58 +0800 Subject: [PATCH 1/2] feat: print DTS generation time --- packages/plugin-dts/src/dts.ts | 2 +- packages/plugin-dts/src/tsc.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/plugin-dts/src/dts.ts b/packages/plugin-dts/src/dts.ts index 8b6100ccc..92c339fb5 100644 --- a/packages/plugin-dts/src/dts.ts +++ b/packages/plugin-dts/src/dts.ts @@ -6,7 +6,7 @@ import { emitDts } from './tsc'; import { ensureTempDeclarationDir, loadTsconfig } from './utils'; export async function generateDts(data: DtsGenOptions) { - logger.info('Generating DTS...'); + logger.ready('Generating DTS...'); const { options: pluginOptions, cwd, isWatch } = data; const { tsconfigPath, distPath, bundle, entryPath } = pluginOptions; const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath); diff --git a/packages/plugin-dts/src/tsc.ts b/packages/plugin-dts/src/tsc.ts index fc718e4ed..289da7b50 100644 --- a/packages/plugin-dts/src/tsc.ts +++ b/packages/plugin-dts/src/tsc.ts @@ -14,6 +14,10 @@ export function emitDts( onComplete: (isSuccess: boolean) => void, isWatch = false, ) { + const start = Date.now(); + const getTimeCost = () => { + return `${Math.floor(Date.now() - start)}ms`; + }; const { configPath, declarationDir } = options; const { options: rawCompilerOptions, fileNames } = loadTsconfig(configPath); @@ -58,10 +62,10 @@ export function emitDts( logger.error(message); } - throw new Error('TypeScript compilation failed'); + throw new Error('DTS generation failed'); } - logger.info('TypeScript compilation succeeded\n'); + logger.info(`DTS generation succeeded in ${getTimeCost()}`); } else { const createProgram = ts.createSemanticDiagnosticsBuilderProgram; const formatHost: ts.FormatDiagnosticsHost = { From da83bdb8d643433d15c2300f07e70f39799e9d4f Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Mon, 5 Aug 2024 13:14:59 +0800 Subject: [PATCH 2/2] chore: use start --- packages/plugin-dts/src/dts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-dts/src/dts.ts b/packages/plugin-dts/src/dts.ts index 92c339fb5..7ccc5aa05 100644 --- a/packages/plugin-dts/src/dts.ts +++ b/packages/plugin-dts/src/dts.ts @@ -6,7 +6,7 @@ import { emitDts } from './tsc'; import { ensureTempDeclarationDir, loadTsconfig } from './utils'; export async function generateDts(data: DtsGenOptions) { - logger.ready('Generating DTS...'); + logger.start('Generating DTS...'); const { options: pluginOptions, cwd, isWatch } = data; const { tsconfigPath, distPath, bundle, entryPath } = pluginOptions; const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);