Skip to content

Commit 0f28206

Browse files
authored
fix: should emit config file parsing diagnostics in DTS build (#335)
1 parent 550f560 commit 0f28206

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/plugin-dts/src/tsc.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ export async function emitDts(
2727
const start = Date.now();
2828
const { configPath, declarationDir, name, dtsExtension, banner, footer } =
2929
options;
30+
const configFileParseResult = loadTsconfig(configPath);
3031
const {
3132
options: rawCompilerOptions,
3233
fileNames,
3334
projectReferences,
34-
} = loadTsconfig(configPath);
35+
} = configFileParseResult;
3536

3637
const compilerOptions = {
3738
...rawCompilerOptions,
@@ -49,6 +50,9 @@ export async function emitDts(
4950
options: compilerOptions,
5051
projectReferences,
5152
host,
53+
configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(
54+
configFileParseResult,
55+
),
5256
});
5357

5458
const emitResult = program.emit();
@@ -60,7 +64,7 @@ export async function emitDts(
6064
const diagnosticMessages: string[] = [];
6165

6266
for (const diagnostic of allDiagnostics) {
63-
const fileLoc = getFileLoc(diagnostic);
67+
const fileLoc = getFileLoc(diagnostic, configPath);
6468
const message = `${fileLoc} - ${color.red('error')} ${color.gray(`TS${diagnostic.code}:`)} ${ts.flattenDiagnosticMessageText(
6569
diagnostic.messageText,
6670
host.getNewLine(),
@@ -94,7 +98,7 @@ export async function emitDts(
9498
};
9599

96100
const reportDiagnostic = (diagnostic: ts.Diagnostic) => {
97-
const fileLoc = getFileLoc(diagnostic);
101+
const fileLoc = getFileLoc(diagnostic, configPath);
98102

99103
logger.error(
100104
`${fileLoc} - ${color.red('error')} ${color.gray(`TS${diagnostic.code}:`)}`,

packages/plugin-dts/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export function ensureTempDeclarationDir(cwd: string): string {
3838
return dirPath;
3939
}
4040

41-
export function getFileLoc(diagnostic: ts.Diagnostic): string {
41+
export function getFileLoc(
42+
diagnostic: ts.Diagnostic,
43+
configPath: string,
44+
): string {
4245
if (diagnostic.file) {
4346
const { line, character } = ts.getLineAndCharacterOfPosition(
4447
diagnostic.file,
@@ -47,7 +50,7 @@ export function getFileLoc(diagnostic: ts.Diagnostic): string {
4750
return `${color.cyan(diagnostic.file.fileName)}:${color.yellow(line + 1)}:${color.yellow(character + 1)}`;
4851
}
4952

50-
return '';
53+
return `${color.cyan(configPath)}`;
5154
}
5255

5356
export const prettyTime = (seconds: number): string => {

0 commit comments

Comments
 (0)