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

fix: omit dts errors that not in the built files #711

Merged
merged 4 commits into from
Sep 12, 2023
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
4 changes: 3 additions & 1 deletion src/builder/bundless/dts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ export default async function getDeclarations(
// ref: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler
const diagnostics = ts
.getPreEmitDiagnostics(incrProgram.getProgram())
.concat(result.diagnostics);
.concat(result.diagnostics)
// omit error for files which not included by build
.filter((d) => !d.file || inputFiles.includes(d.file.fileName));

/* istanbul ignore if -- @preserve */
if (diagnostics.length) {
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/build/bundless-omit-dts-error/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
esm: {},
};
2 changes: 2 additions & 0 deletions tests/fixtures/build/bundless-omit-dts-error/docs/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// expect omit this error, because .fatherrc not include docs folder
window.nothing = 1;
3 changes: 3 additions & 0 deletions tests/fixtures/build/bundless-omit-dts-error/expect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (files: Record<string, string>) => {
expect(Object.keys(files)).toEqual(['esm/index.d.ts', 'esm/index.js']);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// expect omit this error, because demos folder is ignored by default
window.nothing = 1;
1 change: 1 addition & 0 deletions tests/fixtures/build/bundless-omit-dts-error/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 1;
6 changes: 6 additions & 0 deletions tests/fixtures/build/bundless-omit-dts-error/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declaration": true
}
}
Loading