-
Notifications
You must be signed in to change notification settings - Fork 43
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: include some possible dynamic imports with template literals in graph #334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiice, really looking forward to giving this a go 🎉
// TODO(nayeemrmn): Import attributes should be visited and checked for | ||
// every import, not one per specifier. | ||
if dep.maybe_attribute_type.is_none() { | ||
dep.maybe_attribute_type = import.attributes.get("type").cloned(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
maybe_resolver: Option<&dyn Resolver>, | ||
maybe_module_analyzer: Option<&dyn ModuleAnalyzer>, | ||
maybe_npm_resolver: Option<&dyn NpmResolver>, | ||
options: ParseModuleOptions, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see this cleaned up!
run_test( | ||
" | ||
await import(`./${test}`); | ||
", | ||
vec![ | ||
("file:///a/mod.ts", ""), | ||
("file:///a/sub_dir/a.ts", ""), | ||
("file:///b.ts", ""), | ||
], | ||
vec!["file:///a/mod.ts", "file:///a/sub_dir/a.ts", "file:///b.ts"], | ||
) | ||
.await; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I don't understand this bit - I assume you are returning all files that "might" match depending on the value of test
variable - will this be handled somehow downstream or is the goal to just discover all possible files that might get imported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it works like in vite where it treats variables in the string as a **
glob so it would include any possible file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it uses a * glob instead of a ** glob.
For reference, the Vite documentation notes that variables only represent file names one level deep.
Additionally, Vite utilizes @rollup/plugin-dynamic-import-vars, which is described here. According to the documentation:
When generating globs, each variable in the string is converted to a glob * with a maximum of one star per directory depth. This avoids unintentionally adding files from many directories to your import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example:
// /dev/main.ts
await import(`./b/${test}.ts`)
This should not include: file:///dev/b/c/c/test.ts
. However, currently, it does include that path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We ended up going with this behaviour here that's similar to vite, but not exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Closes #275