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

Remove detection of files via import resolution, use static glob and npmignore #788

Merged
merged 67 commits into from
Nov 6, 2023

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Oct 27, 2023

Fixes #769

Files are now determined statically by extension only, ignoring versioned subdirs.

For one-off npm pack in the DT repo, an .npmignore is now required. For react, this looks like:

*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
/v15/
/v16/
/v17/

As outlined in #769, this is the "least bad" solution as far as I can tell, other than to just allow any file in random npm packs and ignore the subdirs.

This required a bunch of lint changes, including moving the relative import check to a lint rule, which required a bunch of other changes.

This is still a WIP with a bunch of TODOs, but it's good enough to start looking at.

TODO

@jakebailey
Copy link
Member Author

jakebailey commented Oct 27, 2023

This PR still uses the same module resolution code to check errors, but that actually nets the same bugs that we are seeing with files today, just in lint form:

Error in node-notifier/v5
Error: 
/home/jabaile/work/DefinitelyTyped/types/node-notifier/v5/index.d.ts
  5:42  error  The relative import "node-notifier/notifiers/notificationcenter" resolves outside of the package; use a bare import to reference other packages  @definitelytyped/no-relative-references
  6:34  error  The relative import "node-notifier/notifiers/notifysend" resolves outside of the package; use a bare import to reference other packages          @definitelytyped/no-relative-references
  7:38  error  The relative import "node-notifier/notifiers/toaster" resolves outside of the package; use a bare import to reference other packages             @definitelytyped/no-relative-references
  8:38  error  The relative import "node-notifier/notifiers/balloon" resolves outside of the package; use a bare import to reference other packages             @definitelytyped/no-relative-references
  9:29  error  The relative import "node-notifier/notifiers/growl" resolves outside of the package; use a bare import to reference other packages               @definitelytyped/no-relative-references

/home/jabaile/work/DefinitelyTyped/types/node-notifier/v5/node-notifier-tests.ts
  28:38  error  The relative import "node-notifier/notifiers/notificationcenter" resolves outside of the package; use a bare import to reference other packages  @definitelytyped/no-relative-references
  31:30  error  The relative import "node-notifier/notifiers/notifysend" resolves outside of the package; use a bare import to reference other packages          @definitelytyped/no-relative-references
  34:34  error  The relative import "node-notifier/notifiers/toaster" resolves outside of the package; use a bare import to reference other packages             @definitelytyped/no-relative-references
  37:25  error  The relative import "node-notifier/notifiers/growl" resolves outside of the package; use a bare import to reference other packages               @definitelytyped/no-relative-references
  40:34  error  The relative import "node-notifier/notifiers/balloon" resolves outside of the package; use a bare import to reference other packages             @definitelytyped/no-relative-references

✖ 10 problems (10 errors, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:172:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:150:13)


Error in parse/v1
Error: 
/home/jabaile/work/DefinitelyTyped/types/parse/v1/index.d.ts
  1149:28  error  The relative import "parse/node" resolves outside of the package; use a bare import to reference other packages  @definitelytyped/no-relative-references
  1156:28  error  The relative import "parse/node" resolves outside of the package; use a bare import to reference other packages  @definitelytyped/no-relative-references

✖ 2 problems (2 errors, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:172:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:150:13)

This fails because module resolution doesn't see declare module on a self package, which we generally ban but people have disabled (boo). As such, these are versioned packages so they do resolve to the parent package!

I'm going to update the PR to instead not use module resolution, as everything we need can actually be done directly on the paths.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Some comments, although I still need to review the new eslint-plugin changes.

.vscode/settings.json Outdated Show resolved Hide resolved
packages/utils/src/miscellany.ts Outdated Show resolved Hide resolved
packages/dtslint/src/checks.ts Outdated Show resolved Hide resolved
.knip.jsonc Outdated Show resolved Hide resolved
packages/utils/src/fs.ts Outdated Show resolved Hide resolved
@jakebailey
Copy link
Member Author

Latest run caught some very fun stuff:

Error in gauge
Error: 
/home/jabaile/work/DefinitelyTyped/types/gauge/lib/themes/index.d.ts
  1:24  error  The reference "../../../node" resolves outside of the package. Use a global reference to reference other packages  @definitelytyped/no-bad-reference

✖ 1 problem (1 error, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)


Error in rangy
Error: 
/home/jabaile/work/DefinitelyTyped/types/rangy/rangy-tests.ts
  1:24  error  The reference "../rangy/rangy-classapplier" resolves to the current package, but uses relative paths  @definitelytyped/no-bad-reference

✖ 1 problem (1 error, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)


Error in slickgrid
Error: 
/home/jabaile/work/DefinitelyTyped/types/slickgrid/test/slick.autotooltips.ts
  1:24  error  The reference "../../slickgrid/slick.autotooltips" resolves to the current package, but uses relative paths  @definitelytyped/no-bad-reference

/home/jabaile/work/DefinitelyTyped/types/slickgrid/test/slick.checkboxselectcolumn.ts
  1:24  error  The reference "../../slickgrid/slick.checkboxselectcolumn" resolves to the current package, but uses relative paths  @definitelytyped/no-bad-reference
  2:24  error  The reference "../../slickgrid/slick.rowselectionmodel" resolves to the current package, but uses relative paths     @definitelytyped/no-bad-reference
  3:24  error  The reference "../../slickgrid/slick.columnpicker" resolves to the current package, but uses relative paths          @definitelytyped/no-bad-reference

✖ 4 problems (4 errors, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)


Error in strophe.js
Error: 
/home/jabaile/work/DefinitelyTyped/types/strophe.js/strophe.js-tests.ts
  1:24  error  The reference "../strophe.js/muc" resolves to the current package, but uses relative paths  @definitelytyped/no-bad-reference

✖ 1 problem (1 error, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)


Error in waypoints
Error: 
/home/jabaile/work/DefinitelyTyped/types/waypoints/waypoints-tests.ts
  1:24  error  The reference "../waypoints/jquery" resolves to the current package, but uses relative paths  @definitelytyped/no-bad-reference

✖ 1 problem (1 error, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)


Error in react-is
Error: 
/home/jabaile/work/DefinitelyTyped/types/react-is/test/canary-tests.tsx
  1:24  error  The reference "../../react/experimental" resolves outside of the package. Use a global reference to reference other packages  @definitelytyped/no-bad-reference

✖ 1 problem (1 error, 0 warnings)

    at testTypesVersion (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:173:15)
    at async runTests (/home/jabaile/work/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:13)

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I have to run to the dentist but I'm all done reviewing except for reading the new test infrastructure and assertions.

},
],
filename: "types/no-declare-current-package/index.d.ts",
errors: [{ messageId: "noDeclareCurrentPackage" }],
Copy link
Member

Choose a reason for hiding this comment

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

this is missing data, which made the tests easier to read in no-bad-reference. Is it possible to get data here too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I just didn't add it since I copied the original test. Will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done; that caught the fact that the lint rule forgot a quote.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Finished up looking at tests.

@jakebailey jakebailey merged commit a18ce6b into microsoft:master Nov 6, 2023
6 checks passed
@jakebailey jakebailey deleted the npmignore branch November 6, 2023 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transition DT packages to use package.json files
2 participants