diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-12-01 15:12:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 20:12:10 +0000 |
commit | a1d823e27d1b605b5658fddc1c9273667f0e9e84 (patch) | |
tree | 213f35fb40b5c70832b1d9473947b3de48d4ec9e /cli/module_loader.rs | |
parent | d8e8497eb3049f58632e4d7507090ef9915b3af6 (diff) |
feat(compile): support discovering modules for more dynamic arguments (#21381)
This PR causes Deno to include more files in the graph based on how a
template literal looks that's provided to a dynamic import:
```ts
const file = await import(`./dir/${expr}`);
```
In this case, it will search the `dir` directory and descendant
directories for any .js/jsx/etc modules and include them in the graph.
To opt out of this behaviour, move the template literal to a separate
line:
```ts
const specifier = `./dir/${expr}`
const file = await import(specifier);
```
Diffstat (limited to 'cli/module_loader.rs')
-rw-r--r-- | cli/module_loader.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/cli/module_loader.rs b/cli/module_loader.rs index d8ab2d8c9..8332ea4f9 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -9,6 +9,7 @@ use crate::emit::Emitter; use crate::graph_util::graph_lock_or_exit; use crate::graph_util::graph_valid_with_cli_options; use crate::graph_util::workspace_config_to_workspace_members; +use crate::graph_util::DenoGraphFsAdapter; use crate::graph_util::FileWatcherReporter; use crate::graph_util::ModuleGraphBuilder; use crate::graph_util::ModuleGraphContainer; @@ -64,6 +65,7 @@ use std::sync::Arc; pub struct ModuleLoadPreparer { options: Arc<CliOptions>, + fs: Arc<dyn deno_fs::FileSystem>, graph_container: Arc<ModuleGraphContainer>, lockfile: Option<Arc<Mutex<Lockfile>>>, maybe_file_watcher_reporter: Option<FileWatcherReporter>, @@ -79,6 +81,7 @@ impl ModuleLoadPreparer { #[allow(clippy::too_many_arguments)] pub fn new( options: Arc<CliOptions>, + fs: Arc<dyn deno_fs::FileSystem>, graph_container: Arc<ModuleGraphContainer>, lockfile: Option<Arc<Mutex<Lockfile>>>, maybe_file_watcher_reporter: Option<FileWatcherReporter>, @@ -91,6 +94,7 @@ impl ModuleLoadPreparer { ) -> Self { Self { options, + fs, graph_container, lockfile, maybe_file_watcher_reporter, @@ -155,6 +159,7 @@ impl ModuleLoadPreparer { deno_graph::BuildOptions { is_dynamic, imports: maybe_imports, + file_system: Some(&DenoGraphFsAdapter(self.fs.as_ref())), resolver: Some(graph_resolver), npm_resolver: Some(graph_npm_resolver), module_analyzer: Some(&analyzer), |