Skip to content
Open
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
4 changes: 3 additions & 1 deletion packages/plugin-dts/src/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const calcBundledPackages = (options: {
export async function generateDts(data: DtsGenOptions): Promise<void> {
const {
bundle,
abortOnError,
dtsEntry,
dtsEmitPath,
tsconfigPath,
Expand Down Expand Up @@ -269,6 +270,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
tsConfigResult,
declarationDir,
dtsExtension,
abortOnError,
redirect,
rootDir,
paths,
Expand All @@ -282,7 +284,7 @@ export async function generateDts(data: DtsGenOptions): Promise<void> {
);

if (tsgo) {
if (!hasError) {
if (!hasError || !abortOnError) {
await bundleDtsIfNeeded();
}
} else {
Expand Down
21 changes: 14 additions & 7 deletions packages/plugin-dts/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const formatHost: FormatDiagnosticsHost = {
};

export type EmitDtsOptions = {
abortOnError: boolean | undefined;
name: string;
cwd: string;
configPath: string;
Expand All @@ -42,6 +43,7 @@ export type EmitDtsOptions = {
};

async function handleDiagnosticsAndProcessFiles(
abortOnError: boolean | undefined,
diagnostics: readonly Diagnostic[],
configPath: string,
bundle: boolean,
Expand Down Expand Up @@ -81,12 +83,14 @@ async function handleDiagnosticsAndProcessFiles(
logger.error(logPrefixTsc, message);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When bundle: false with abortOnError: false, the error should still be throwed I think. abortOnError means not exit the process instead of not throwing error.

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

Expand All @@ -99,6 +103,7 @@ export async function emitDtsTsc(
): Promise<void> {
const start = Date.now();
const {
abortOnError,
configPath,
tsConfigResult,
declarationDir,
Expand Down Expand Up @@ -252,6 +257,7 @@ export async function emitDtsTsc(
ts.sortAndDeduplicateDiagnostics(allDiagnostics);

await handleDiagnosticsAndProcessFiles(
abortOnError,
sortAndDeduplicateDiagnostics,
configPath,
bundle,
Expand Down Expand Up @@ -322,6 +328,7 @@ export async function emitDtsTsc(
ts.sortAndDeduplicateDiagnostics(allDiagnostics);

await handleDiagnosticsAndProcessFiles(
abortOnError,
sortAndDeduplicateDiagnostics,
configPath,
bundle,
Expand Down Expand Up @@ -370,7 +377,7 @@ export async function emitDtsTsc(
footer,
);

if (errorNumber > 0) {
if (errorNumber > 0 && abortOnError) {
const error = new Error(
`Failed to generate declaration files. ${color.dim(`(${name})`)}`,
);
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-dts/src/tsgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const generateTsgoArgs = (
};

async function handleDiagnosticsAndProcessFiles(
abortOnError: boolean | undefined,
isWatch: boolean,
hasErrors: boolean,
tsConfigResult: ts.ParsedCommandLine,
Expand Down Expand Up @@ -124,7 +125,7 @@ async function handleDiagnosticsAndProcessFiles(
footer,
);

if (hasErrors && !isWatch) {
if (hasErrors && !isWatch && abortOnError) {
const error = new Error(
`Failed to generate declaration files. ${color.dim(`(${name})`)}`,
);
Expand All @@ -143,6 +144,7 @@ export async function emitDtsTsgo(
): Promise<boolean> {
const start = Date.now();
const {
abortOnError,
configPath,
tsConfigResult,
declarationDir,
Expand Down Expand Up @@ -203,6 +205,7 @@ export async function emitDtsTsgo(
}

await handleDiagnosticsAndProcessFiles(
abortOnError,
isWatch,
hasErrors,
tsConfigResult,
Expand Down