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: support analysis of require() statements #69

Closed
wants to merge 2 commits into from

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Nov 10, 2021

Closes #58

The PR allows the deno_graph to statically analyse require() statements in modules and have them exist as part of the module graph. There are some limitations, which are swc limitations:

  • It statically looks for the require() symbol in code and does not track re-assignment. Meaning it won't find dependencies like const r = require; const b = r("b");.
  • It only detects static strings passed to the require() function, therefore things like const m = "m"; require(m); do not work.

This is a BREAKING CHANGE on the Rust side, but one that shouldn't impact any of the CLI functionality. Essentially Resolver::resolve() and Loader::load() now take an extra argument which indicates what kind of dependency it is. This allows consumers to be able to branch logic in code based on the "reason" the resolution or loading is occurring. On the JavaScript side, it is a non-breaking change, since excess arguments are ignorable.

@kitsonk kitsonk requested review from ry and dsherret November 10, 2021 01:51
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

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

Just did a quick skim through and it's looking good to me.

@kitsonk kitsonk changed the title [POC] feat: support analysis of require() statements feat: support analysis of require() statements Nov 23, 2021
@kitsonk kitsonk marked this pull request as ready for review November 23, 2021 21:35
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.

LGTM, only one nitpick. I think we should wait on upgrade to deno_ast before landing this PR (denoland/deno_ast#46)

Comment on lines +310 to +314
impl Default for DependencyKind {
fn default() -> Self {
Self::Import
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is it required to implement Default trait for this enum? It feels to me like a potential footgun that might lead to discrepancies by too liberal use of Default::default() somewhere in the call chain.

@bartlomieju
Copy link
Member

bartlomieju commented Feb 15, 2022

@kitsonk is there anything I can do to help you to land this PR?

@kitsonk
Copy link
Contributor Author

kitsonk commented Feb 16, 2022

It needs quite a bit of rebasing... let me take care of it. We just didn't need it before, now there is a compelling need.

@kitsonk
Copy link
Contributor Author

kitsonk commented Oct 27, 2022

Stale and uneeded.

@kitsonk kitsonk closed this Oct 27, 2022
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.

Support CommonJs dependency analysis
3 participants