summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-02-21 08:35:25 -0500
committerGitHub <noreply@github.com>2024-02-21 08:35:25 -0500
commit9166d8a4e9b0f611b1e06c9e339b44f7c450d72e (patch)
tree1c4efed34b9c5bebc1f42fdaa8ad28dcca30896a /cli
parent061ee9d38cdf8ff0ade2373c1e075f841c534c47 (diff)
feat(publish): type check on publish (#22506)
Supersedes #22501 and also fixes that issue.
Diffstat (limited to 'cli')
-rw-r--r--cli/args/flags.rs28
-rw-r--r--cli/graph_util.rs35
-rw-r--r--cli/module_loader.rs1
-rw-r--r--cli/tools/check.rs13
-rw-r--r--cli/tools/registry/mod.rs3
5 files changed, 66 insertions, 14 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 0ce521296..44bb0dde1 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -2394,6 +2394,8 @@ fn publish_subcommand() -> Command {
.help("Allow publishing with slow types")
.action(ArgAction::SetTrue),
)
+ .arg(check_arg(/* type checks by default */ true))
+ .arg(no_check_arg())
})
}
@@ -3823,6 +3825,9 @@ fn vendor_parse(flags: &mut Flags, matches: &mut ArgMatches) {
}
fn publish_parse(flags: &mut Flags, matches: &mut ArgMatches) {
+ flags.type_check_mode = TypeCheckMode::Local; // local by default
+ no_check_arg_parse(flags, matches);
+ check_arg_parse(flags, matches);
config_args_parse(flags, matches);
flags.subcommand = DenoSubcommand::Publish(PublishFlags {
@@ -8542,4 +8547,27 @@ mod tests {
let r = flags_from_vec(svec!["deno", "jupyter", "--install", "--kernel",]);
r.unwrap_err();
}
+
+ #[test]
+ fn publish_args() {
+ let r = flags_from_vec(svec![
+ "deno",
+ "publish",
+ "--dry-run",
+ "--allow-slow-types",
+ "--token=asdf",
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Publish(PublishFlags {
+ token: Some("asdf".to_string()),
+ dry_run: true,
+ allow_slow_types: true,
+ }),
+ type_check_mode: TypeCheckMode::Local,
+ ..Flags::default()
+ }
+ );
+ }
}
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index de13f25ba..51f07af5e 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -281,6 +281,9 @@ impl ModuleGraphCreator {
loader: None,
})
.await?;
+ if self.options.type_check_mode().is_true() {
+ self.type_check_graph(graph.clone()).await?;
+ }
self.module_graph_builder.build_fast_check_graph(
&mut graph,
BuildFastCheckGraphOptions {
@@ -337,23 +340,31 @@ impl ModuleGraphCreator {
if self.options.type_check_mode().is_true() {
// provide the graph to the type checker, then get it back after it's done
- let graph = self
- .type_checker
- .check(
- graph,
- check::CheckOptions {
- build_fast_check_graph: true,
- lib: self.options.ts_type_lib_window(),
- log_ignored_options: true,
- reload: self.options.reload_flag(),
- },
- )
- .await?;
+ let graph = self.type_check_graph(graph).await?;
Ok(graph)
} else {
Ok(Arc::new(graph))
}
}
+
+ async fn type_check_graph(
+ &self,
+ graph: ModuleGraph,
+ ) -> Result<Arc<ModuleGraph>, AnyError> {
+ self
+ .type_checker
+ .check(
+ graph,
+ check::CheckOptions {
+ build_fast_check_graph: true,
+ lib: self.options.ts_type_lib_window(),
+ log_ignored_options: true,
+ reload: self.options.reload_flag(),
+ type_check_mode: self.options.type_check_mode(),
+ },
+ )
+ .await
+ }
}
pub struct BuildFastCheckGraphOptions {
diff --git a/cli/module_loader.rs b/cli/module_loader.rs
index d2742d1ba..ae7f8f349 100644
--- a/cli/module_loader.rs
+++ b/cli/module_loader.rs
@@ -167,6 +167,7 @@ impl ModuleLoadPreparer {
log_ignored_options: false,
reload: self.options.reload_flag()
&& !roots.iter().all(|r| reload_exclusions.contains(r)),
+ type_check_mode: self.options.type_check_mode(),
},
)
.await?;
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index 08fc6f087..68bf9716e 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -44,6 +44,8 @@ pub struct CheckOptions {
/// If true, valid `.tsbuildinfo` files will be ignored and type checking
/// will always occur.
pub reload: bool,
+ /// Mode to type check with.
+ pub type_check_mode: TypeCheckMode,
}
pub struct TypeChecker {
@@ -97,6 +99,7 @@ impl TypeChecker {
mut graph: ModuleGraph,
options: CheckOptions,
) -> Result<(Arc<ModuleGraph>, Diagnostics), AnyError> {
+ debug_assert_ne!(options.type_check_mode, TypeCheckMode::None);
if graph.roots.is_empty() {
return Ok((graph.into(), Default::default()));
}
@@ -120,8 +123,8 @@ impl TypeChecker {
}
}
+ let type_check_mode = options.type_check_mode;
let ts_config = ts_config_result.ts_config;
- let type_check_mode = self.cli_options.type_check_mode();
let maybe_check_hash = match self.npm_resolver.check_state_hash() {
Some(npm_check_hash) => {
match get_check_hash(
@@ -300,7 +303,13 @@ fn get_check_hash(
}
hasher.write_str(module.specifier.as_str());
- hasher.write_str(&module.source);
+ hasher.write_str(
+ // the fast check module will only be set when publishing
+ module
+ .fast_check_module()
+ .map(|s| s.source.as_ref())
+ .unwrap_or(&module.source),
+ );
}
Module::Node(_) => {
// the @types/node package will be in the resolved
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs
index 951ac4944..aea5dc634 100644
--- a/cli/tools/registry/mod.rs
+++ b/cli/tools/registry/mod.rs
@@ -28,6 +28,7 @@ use crate::args::jsr_url;
use crate::args::CliOptions;
use crate::args::Flags;
use crate::args::PublishFlags;
+use crate::args::TypeCheckMode;
use crate::cache::LazyGraphSourceParser;
use crate::cache::ParsedSourceCache;
use crate::factory::CliFactory;
@@ -768,6 +769,8 @@ async fn build_and_check_graph_for_publish(
lib: cli_options.ts_type_lib_window(),
log_ignored_options: false,
reload: cli_options.reload_flag(),
+ // force type checking this
+ type_check_mode: TypeCheckMode::Local,
},
)
.await?;