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: include some possible dynamic imports with template literals in graph #334

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Nov 22, 2023

  1. This does not have a directory entry limit.
  2. This swallows errors.

Closes #275

Copy link
Contributor

@marvinhagemeister marvinhagemeister left a 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 🎉

Comment on lines +2173 to +2177
// 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();
}
Copy link
Member

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?

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.

maybe_resolver: Option<&dyn Resolver>,
maybe_module_analyzer: Option<&dyn ModuleAnalyzer>,
maybe_npm_resolver: Option<&dyn NpmResolver>,
options: ParseModuleOptions,
Copy link
Member

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!

Comment on lines +507 to +518
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;
Copy link
Member

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?

Copy link
Contributor

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.

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.

Copy link

@Mutefish0 Mutefish0 Jul 30, 2024

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.

Copy link
Member Author

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.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

Looks great!

@dsherret dsherret merged commit 60de461 into denoland:main Nov 27, 2023
3 checks passed
@dsherret dsherret deleted the feat_dynamic_imports_expr branch November 27, 2023 14:59
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.

More statically analyzable dynamic imports
5 participants