summaryrefslogtreecommitdiff
path: root/cli/module_graph.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-06-19 15:14:43 +0100
committerGitHub <noreply@github.com>2021-06-19 16:14:43 +0200
commit2ea41d3ac159e4c2e998d13412dc19680b01a6ca (patch)
treec771d33f481c1bbc1b82f758ec96bfa5c342389c /cli/module_graph.rs
parentb0c04a7941bb1bab0f135c39d484ac47dae14300 (diff)
fix(core/modules): Prepare modules only once per runtime (#11015)
This commit changes module loading implementation in "deno_core" to call "ModuleLoader::prepare" hook only once per entry point. This is done to avoid multiple type checking of the same code in case of duplicated dynamic imports. Relevant code in "cli/module_graph.rs" was updated as well.
Diffstat (limited to 'cli/module_graph.rs')
-rw-r--r--cli/module_graph.rs39
1 files changed, 29 insertions, 10 deletions
diff --git a/cli/module_graph.rs b/cli/module_graph.rs
index 3a135b166..770f8b872 100644
--- a/cli/module_graph.rs
+++ b/cli/module_graph.rs
@@ -624,6 +624,10 @@ pub struct CheckOptions {
/// Ignore any previously emits and ensure that all files are emitted from
/// source.
pub reload: bool,
+ /// A set of module specifiers to be excluded from the effect of
+ /// `CheckOptions::reload` if it is `true`. Perhaps because they have already
+ /// reloaded once in this process.
+ pub reload_exclusions: HashSet<ModuleSpecifier>,
}
#[derive(Debug, Eq, PartialEq)]
@@ -673,6 +677,10 @@ pub struct TranspileOptions {
/// Ignore any previously emits and ensure that all files are emitted from
/// source.
pub reload: bool,
+ /// A set of module specifiers to be excluded from the effect of
+ /// `CheckOptions::reload` if it is `true`. Perhaps because they have already
+ /// reloaded once in this process.
+ pub reload_exclusions: HashSet<ModuleSpecifier>,
}
#[derive(Debug, Clone)]
@@ -851,15 +859,14 @@ impl Graph {
let maybe_ignored_options = config
.merge_tsconfig_from_config_file(options.maybe_config_file.as_ref())?;
+ let needs_reload = options.reload
+ && !self
+ .roots
+ .iter()
+ .all(|u| options.reload_exclusions.contains(u));
// Short circuit if none of the modules require an emit, or all of the
- // modules that require an emit have a valid emit. There is also an edge
- // case where there are multiple imports of a dynamic module during a
- // single invocation, if that is the case, even if there is a reload, we
- // will simply look at if the emit is invalid, to avoid two checks for the
- // same programme.
- if !self.needs_emit(&config)
- || (self.is_emit_valid(&config)
- && (!options.reload || self.roots_dynamic))
+ // modules that require an emit have a valid emit.
+ if !self.needs_emit(&config) || self.is_emit_valid(&config) && !needs_reload
{
debug!("graph does not need to be checked or emitted.");
return Ok(ResultInfo {
@@ -1673,7 +1680,7 @@ impl Graph {
let check_js = ts_config.get_check_js();
let emit_options: ast::EmitOptions = ts_config.into();
let mut emit_count = 0_u32;
- for (_, module_slot) in self.modules.iter_mut() {
+ for (specifier, module_slot) in self.modules.iter_mut() {
if let ModuleSlot::Module(module) = module_slot {
// TODO(kitsonk) a lot of this logic should be refactored into `Module` as
// we start to support other methods on the graph. Especially managing
@@ -1692,8 +1699,11 @@ impl Graph {
{
continue;
}
+
+ let needs_reload =
+ options.reload && !options.reload_exclusions.contains(specifier);
// skip modules that already have a valid emit
- if !options.reload && module.is_emit_valid(&config) {
+ if module.is_emit_valid(&config) && !needs_reload {
continue;
}
let parsed_module = module.parse()?;
@@ -2255,6 +2265,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2277,6 +2288,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.diagnostics.is_empty());
@@ -2294,6 +2306,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2318,6 +2331,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2340,6 +2354,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2361,6 +2376,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: None,
reload: false,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.diagnostics.is_empty());
@@ -2380,6 +2396,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: Some(config_file),
reload: true,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2401,6 +2418,7 @@ pub mod tests {
lib: TypeLib::DenoWindow,
maybe_config_file: Some(config_file),
reload: true,
+ ..Default::default()
})
.expect("should have checked");
assert!(result_info.maybe_ignored_options.is_none());
@@ -2628,6 +2646,7 @@ pub mod tests {
debug: false,
maybe_config_file: Some(config_file),
reload: false,
+ ..Default::default()
})
.unwrap();
assert_eq!(