From ef03c236e7cfde8732c5a5ebea9db37219da9b25 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Thu, 28 Aug 2025 15:36:24 +0800 Subject: [PATCH] chore(dts): enhance error logs for dts mainEntryPointFilePath not found --- packages/plugin-dts/src/apiExtractor.ts | 14 ++++++++++++-- packages/plugin-dts/src/index.ts | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/plugin-dts/src/apiExtractor.ts b/packages/plugin-dts/src/apiExtractor.ts index 6f0f719ad..784ad3b6f 100644 --- a/packages/plugin-dts/src/apiExtractor.ts +++ b/packages/plugin-dts/src/apiExtractor.ts @@ -1,3 +1,4 @@ +import fs from 'node:fs'; import { join, relative } from 'node:path'; import type * as ApiExtractor from '@microsoft/api-extractor'; import { logger } from '@rsbuild/core'; @@ -53,7 +54,15 @@ export async function bundleDts(options: BundleOptions): Promise { relative(cwd, distPath), `${entry.name}${dtsExtension}`, ); - const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, ''); + + const mainEntryPointFilePath = entry.path; + + if (!fs.existsSync(mainEntryPointFilePath)) { + throw new Error( + `Declaration entry file ${color.underline(entry.path)} not found.\nPlease ensure that your tsconfig file ${color.underline(tsconfigPath)} is correctly configured to generate declaration files. If needed, a custom tsconfig can be specified using the ${color.cyan('source.tsconfigPath')} option.`, + ); + } + const internalConfig = { mainEntryPointFilePath, bundledPackages, @@ -106,8 +115,9 @@ export async function bundleDts(options: BundleOptions): Promise { }), ); } catch (e) { + const message = e instanceof Error ? e.message : e; const error = new Error( - `${logPrefixApiExtractor} ${e} ${color.dim(`(${name})`)}`, + `${logPrefixApiExtractor} ${message} ${color.dim(`(${name})`)}`, ); // do not log the stack trace, it is not helpful for users error.stack = ''; diff --git a/packages/plugin-dts/src/index.ts b/packages/plugin-dts/src/index.ts index 500662171..443b4b7f2 100644 --- a/packages/plugin-dts/src/index.ts +++ b/packages/plugin-dts/src/index.ts @@ -47,8 +47,8 @@ export type PluginDtsOptions = { }; export type DtsEntry = { - name?: string; - path?: string; + name: string; + path: string; }; export type DtsGenOptions = Omit & {