Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: warn on likely failed d.ts file generation #2428

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
29 changes: 28 additions & 1 deletion packages/svelte2tsx/src/emitDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,34 @@ export async function emitDts(config: EmitDtsConfig) {
const { options, filenames } = loadTsconfig(config, svelteMap);
const host = await createTsCompilerHost(options, svelteMap);
const program = ts.createProgram(filenames, options, host);
program.emit();
const result = program.emit();
const likely_failed_files = result.diagnostics.filter((diagnostic) => {
// List of errors which hint at a failed d.ts generation
// https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json
return diagnostic.code === 2527 || (diagnostic.code >= 4000 && diagnostic.code <= 4108);
});

if (likely_failed_files.length > 0) {
const failed_by_file = new Map<string, string[]>();
likely_failed_files.forEach((diagnostic) => {
const file = diagnostic.file?.fileName;
if (file) {
const errors = failed_by_file.get(file) || [];
errors.push(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
failed_by_file.set(file, errors);
}
});
console.warn(
'd.ts type declaration files for the following files were likely not generated due to the following errors:'
);
console.warn(
[...failed_by_file.entries()]
.map(([file, errors]) => {
return `${file}\n${errors.map((error) => ` - ${error}`).join('\n')}`;
})
.join('\n')
);
}
}

function loadTsconfig(config: EmitDtsConfig, svelteMap: SvelteMap) {
Expand Down