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(unstable/npm): initial type checking of npm specifiers #16332

Merged
merged 51 commits into from
Oct 21, 2022

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Oct 17, 2022

Adds initial support for type checking npm specifiers.

  • At the moment, the TS type checker cannot represent the requirements for npm specifiers and so we're using a hopefully temporary fork of the TS compiler to solve this. Once we find out this approach works then we'll explore if there's a way to make a more general solution that can be upstreamed. See feat: additive global context for npm packages (first pass) TypeScript#1 for way more details on this.
  • LSP doesn't work with local node_modules directory since there's no configuration for this at the moment. I think we should consider making this an option in the deno.json file or perhaps it should detect if there's a node_modules folder and prefer to use that? Edit: Opened lsp: should work with local node_modules directory #16373
  • The --remote flag in deno check --remote main.ts should probably be renamed deno check --all main.ts to align with deno run --check=all main.ts. deno run --check/deno check doesn't type check npm packages by default in these changes and --remote doesn't really make sense for that given we have a distinction between "remote" and npm packages elsewhere (ex. --no-remote and --no-npm) Edit: Opened Consider renaming deno check --remote to --all #16374
  • To use node types, a /// <reference types="npm:@types/node" /> directive must be added to the code. This is necessary because there may be scenarios where people want to use npm modules without node types.
  • There are inherent issues with resolving version requirements across files in the LSP since only open files are analyzed. This might lead to different resolution based on what files are open. I'm not sure how this will play out in practice.

todo:

  • Document how to upgrade TypeScript with these changes
  • Add lsp tests
  • Testing out initial caching in the lsp more. I think it's temperamental atm.
  • Npm specifier tracking in the lsp

cli/dts/README.md Show resolved Hide resolved
cli/dts/README.md Outdated Show resolved Hide resolved
Comment on lines +858 to +862
if let Some(npm_resolver) = &snapshot.maybe_npm_resolver {
// show diagnostics for npm package references that aren't cached
if npm_resolver
.resolve_package_folder_from_deno_module(&pkg_ref.req)
.is_err()
Copy link
Member

Choose a reason for hiding this comment

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

That this handle situation when user has --node-modules-dir flag specified?

Copy link
Member Author

@dsherret dsherret Oct 20, 2022

Choose a reason for hiding this comment

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

Nope. That's not supported at the moment because there's no way to provide that to the lsp at the moment (see second point in pr description). Edit: opened an issue.

cli/lsp/documents.rs Outdated Show resolved Hide resolved
cli/lsp/documents.rs Show resolved Hide resolved
cli/node/mod.rs Show resolved Hide resolved
cli/node/mod.rs Outdated Show resolved Hide resolved
cli/npm/resolution.rs Show resolved Hide resolved
ext/node/resolution.rs Outdated Show resolved Hide resolved
ext/node/resolution.rs Outdated Show resolved Hide resolved
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

Tested locally and found a few small problems that were either addressed in this PR or have issues open.

This is already a big PR and it works good enough to land it. Let's iterate further in follow up PRs.

LGTM, amazing work David!

@dsherret dsherret enabled auto-merge (squash) October 21, 2022 14:57
@dsherret dsherret merged commit bcfe279 into denoland:main Oct 21, 2022
@dsherret dsherret deleted the npm_types_01 branch October 21, 2022 15:28
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.

2 participants