Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/plugin-dts/src/apiExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
try {
apiExtractor = await import('@microsoft/api-extractor');
} catch {
throw new Error(
const error = new Error(
`${color.cyan('@microsoft/api-extractor')} is required when ${color.cyan('dts.bundle')} is set to ${color.cyan('true')}, please make sure it is installed. You could check https://rslib.rs/guide/advanced/dts#how-to-generate-declaration-files-in-rslib for more details.`,
);
// do not log the stack trace, it is not helpful for users
error.stack = '';
throw error;
}

const { Extractor, ExtractorConfig, ExtractorLogLevel } = apiExtractor!;
Expand Down Expand Up @@ -103,6 +106,9 @@ export async function bundleDts(options: BundleOptions): Promise<void> {
}),
);
} catch (e) {
throw new Error(`${logPrefixApiExtractor} ${e}`);
const error = new Error(`${logPrefixApiExtractor} ${e}`);
// do not log the stack trace, it is not helpful for users
error.stack = '';
throw error;
}
}
11 changes: 8 additions & 3 deletions packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
);

if (!tsconfigPath) {
logger.error(
const error = new Error(
`Failed to resolve tsconfig file ${color.cyan(`"${config.source.tsconfigPath}"`)} from ${color.cyan(cwd)}. Please ensure that the file exists.`,
);
throw new Error();
error.stack = '';
// do not log the stack trace, it is not helpful for users
throw error;
}

const tsConfigResult = loadTsconfig(tsconfigPath);
Expand Down Expand Up @@ -215,7 +217,10 @@ export const pluginDts = (options: PluginDtsOptions = {}): RsbuildPlugin => ({
for (const result of promisesResult) {
if (result.status === 'error') {
if (options.abortOnError) {
throw new Error(result.errorMessage);
const error = new Error(result.errorMessage);
// do not log the stack trace, it is not helpful for users
error.stack = '';
throw error;
}
result.errorMessage && logger.error(result.errorMessage);
logger.warn(
Expand Down
10 changes: 8 additions & 2 deletions packages/plugin-dts/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ async function handleDiagnosticsAndProcessFiles(
logger.error(logPrefixTsc, message);
}

throw new Error(
const error = new Error(
`Failed to generate declaration files. ${color.gray(`(${name})`)}`,
);
// do not log the stack trace, diagnostic messages are enough
error.stack = '';
throw error;
}
}

Expand Down Expand Up @@ -318,9 +321,12 @@ export async function emitDts(
);

if (errorNumber > 0) {
throw new Error(
const error = new Error(
`Failed to generate declaration files. ${color.gray(`(${name})`)}`,
);
// do not log the stack trace, diagnostic messages are enough
error.stack = '';
throw error;
}
}

Expand Down
10 changes: 8 additions & 2 deletions packages/plugin-dts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,23 @@ export function processSourceEntry(
);

if (entries.length === 0) {
throw new Error(
const noValidEntryError = new Error(
`Can not find a valid entry for ${color.cyan('dts.bundle')} option, please check your entry config.`,
);
// do not log the stack trace, it is not helpful for users
noValidEntryError.stack = '';
throw noValidEntryError;
}

return entries;
}

throw new Error(
const error = new Error(
'@microsoft/api-extractor only support entry of Record<string, string> type to bundle declaration files, please check your entry config.',
);
// do not log the stack trace, it is not helpful for users
error.stack = '';
throw error;
}

// same as @rslib/core, we should extract into a single published package to share
Expand Down
10 changes: 2 additions & 8 deletions tests/integration/dts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,13 @@ describe('dts when bundle: false', () => {
const fixturePath = join(__dirname, 'bundle-false', 'tsconfig-path');
await createTempFiles(fixturePath, false);

const { logs, restore } = proxyConsole();
try {
await buildAndGetResults({ fixturePath, type: 'dts' });
} catch (err: any) {
expect(
logs
.map((log) => stripAnsi(log))
.find((log) => log.includes('Failed to resolve tsconfig file')),
).toMatchInlineSnapshot(
`"error Failed to resolve tsconfig file "<ROOT>/tests/integration/dts/bundle-false/tsconfig-path/path_not_exist/tsconfig.json" from <ROOT>/tests/integration/dts/bundle-false/tsconfig-path. Please ensure that the file exists."`,
expect(stripAnsi(err.message)).toMatchInlineSnapshot(
`"Failed to resolve tsconfig file "<ROOT>/tests/integration/dts/bundle-false/tsconfig-path/path_not_exist/tsconfig.json" from <ROOT>/tests/integration/dts/bundle-false/tsconfig-path. Please ensure that the file exists."`,
);
}
restore();
});
});

Expand Down
Loading