summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/main.rs1
-rw-r--r--cli/module_graph.rs39
-rw-r--r--cli/program_state.rs13
-rw-r--r--cli/tests/single_compile_with_reload.ts14
-rw-r--r--cli/tests/single_compile_with_reload.ts.out5
-rw-r--r--cli/tests/single_compile_with_reload_worker.ts3
6 files changed, 65 insertions, 10 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 9941d737a..950234a72 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -598,6 +598,7 @@ async fn create_module_graph_and_maybe_check(
lib,
maybe_config_file: program_state.maybe_config_file.clone(),
reload: program_state.flags.reload,
+ ..Default::default()
})?;
debug!("{}", result_info.stats);
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!(
diff --git a/cli/program_state.rs b/cli/program_state.rs
index 95362165f..668c73058 100644
--- a/cli/program_state.rs
+++ b/cli/program_state.rs
@@ -31,6 +31,7 @@ use deno_core::ModuleSpecifier;
use log::debug;
use log::warn;
use std::collections::HashMap;
+use std::collections::HashSet;
use std::env;
use std::fs::read;
use std::sync::Arc;
@@ -177,12 +178,17 @@ impl ProgramState {
let mut graph = builder.get_graph();
let debug = self.flags.log_level == Some(log::Level::Debug);
let maybe_config_file = self.maybe_config_file.clone();
+ let reload_exclusions = {
+ let modules = self.modules.lock().unwrap();
+ modules.keys().cloned().collect::<HashSet<_>>()
+ };
let result_modules = if self.flags.no_check {
let result_info = graph.transpile(TranspileOptions {
debug,
maybe_config_file,
reload: self.flags.reload,
+ reload_exclusions,
})?;
debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
@@ -196,6 +202,7 @@ impl ProgramState {
lib,
maybe_config_file,
reload: self.flags.reload,
+ reload_exclusions,
})?;
debug!("{}", result_info.stats);
@@ -244,12 +251,17 @@ impl ProgramState {
let mut graph = builder.get_graph();
let debug = self.flags.log_level == Some(log::Level::Debug);
let maybe_config_file = self.maybe_config_file.clone();
+ let reload_exclusions = {
+ let modules = self.modules.lock().unwrap();
+ modules.keys().cloned().collect::<HashSet<_>>()
+ };
let result_modules = if self.flags.no_check {
let result_info = graph.transpile(TranspileOptions {
debug,
maybe_config_file,
reload: self.flags.reload,
+ reload_exclusions,
})?;
debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
@@ -263,6 +275,7 @@ impl ProgramState {
lib,
maybe_config_file,
reload: self.flags.reload,
+ reload_exclusions,
})?;
debug!("{}", result_info.stats);
diff --git a/cli/tests/single_compile_with_reload.ts b/cli/tests/single_compile_with_reload.ts
index a4d6d0341..f84e91f2f 100644
--- a/cli/tests/single_compile_with_reload.ts
+++ b/cli/tests/single_compile_with_reload.ts
@@ -2,3 +2,17 @@ await import("./single_compile_with_reload_dyn.ts");
console.log("1");
await import("./single_compile_with_reload_dyn.ts");
console.log("2");
+await new Promise((r) =>
+ new Worker(
+ new URL("single_compile_with_reload_worker.ts", import.meta.url).href,
+ { type: "module" },
+ ).onmessage = r
+);
+console.log("3");
+await new Promise((r) =>
+ new Worker(
+ new URL("single_compile_with_reload_worker.ts", import.meta.url).href,
+ { type: "module" },
+ ).onmessage = r
+);
+console.log("4");
diff --git a/cli/tests/single_compile_with_reload.ts.out b/cli/tests/single_compile_with_reload.ts.out
index 4ffaa6e77..b0b2fcaf1 100644
--- a/cli/tests/single_compile_with_reload.ts.out
+++ b/cli/tests/single_compile_with_reload.ts.out
@@ -2,3 +2,8 @@ Check [WILDCARD]single_compile_with_reload.ts
Hello
1
2
+Check [WILDCARD]single_compile_with_reload_worker.ts
+Hello from worker
+3
+Hello from worker
+4
diff --git a/cli/tests/single_compile_with_reload_worker.ts b/cli/tests/single_compile_with_reload_worker.ts
new file mode 100644
index 000000000..103cafe20
--- /dev/null
+++ b/cli/tests/single_compile_with_reload_worker.ts
@@ -0,0 +1,3 @@
+console.log("Hello from worker");
+postMessage(null);
+close();