Skip to content

Commit 9f508d5

Browse files
authored
chore(dts): enhance error logs for dts mainEntryPointFilePath not found (#1197)
1 parent a14f8d4 commit 9f508d5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/plugin-dts/src/apiExtractor.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs';
12
import { join, relative } from 'node:path';
23
import type * as ApiExtractor from '@microsoft/api-extractor';
34
import { logger } from '@rsbuild/core';
@@ -53,7 +54,15 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
5354
relative(cwd, distPath),
5455
`${entry.name}${dtsExtension}`,
5556
);
56-
const mainEntryPointFilePath = entry.path!.replace(/\?.*$/, '');
57+
58+
const mainEntryPointFilePath = entry.path;
59+
60+
if (!fs.existsSync(mainEntryPointFilePath)) {
61+
throw new Error(
62+
`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.`,
63+
);
64+
}
65+
5766
const internalConfig = {
5867
mainEntryPointFilePath,
5968
bundledPackages,
@@ -106,8 +115,9 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
106115
}),
107116
);
108117
} catch (e) {
118+
const message = e instanceof Error ? e.message : e;
109119
const error = new Error(
110-
`${logPrefixApiExtractor} ${e} ${color.dim(`(${name})`)}`,
120+
`${logPrefixApiExtractor} ${message} ${color.dim(`(${name})`)}`,
111121
);
112122
// do not log the stack trace, it is not helpful for users
113123
error.stack = '';

packages/plugin-dts/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export type PluginDtsOptions = {
4747
};
4848

4949
export type DtsEntry = {
50-
name?: string;
51-
path?: string;
50+
name: string;
51+
path: string;
5252
};
5353

5454
export type DtsGenOptions = Omit<PluginDtsOptions, 'bundle'> & {

0 commit comments

Comments
 (0)