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

[DRAFT] feat: skip type checking by default #11810

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub struct Flags {
/// the language server is configured with an explicit cache option.
pub cache_path: Option<PathBuf>,
pub cached_only: bool,
pub check: bool,
pub config_path: Option<String>,
pub coverage_dir: Option<String>,
pub enable_testing_features: bool,
Expand Down Expand Up @@ -829,6 +830,7 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",
.conflicts_with("file")
.help("Show files used for origin bound APIs like the Web Storage API when running a script with '--location=<HREF>'")
)
.arg(check_arg())
// TODO(lucacasonato): remove for 2.0
.arg(no_check_arg().hidden(true))
.arg(import_map_arg())
Expand Down Expand Up @@ -1200,6 +1202,7 @@ fn compile_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.arg(import_map_arg())
.arg(no_remote_arg())
.arg(config_arg())
.arg(check_arg())
.arg(no_check_arg())
.arg(reload_arg())
.arg(lock_arg())
Expand Down Expand Up @@ -1462,10 +1465,24 @@ Only local files from entry point module graph are watched.",
)
}

fn check_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("check")
.long("check")
.help("Type check modules")
.long_help(
"Type check modules.
If there are type checking diagnostics they are displayed and the command line exits."
)
}

fn no_check_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("no-check")
.long("no-check")
.help("Skip type checking modules")
.help("DEPRECATED: Skip type checking modules")
.long_help(
"DEPRECATED: Skip type checking modules.
This is now the default behavior and the flag is no longer needed.",
)
}

fn script_arg<'a, 'b>() -> Arg<'a, 'b> {
Expand Down Expand Up @@ -1884,6 +1901,7 @@ fn compile_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
import_map_arg_parse(flags, matches);
no_remote_arg_parse(flags, matches);
config_arg_parse(flags, matches);
check_arg_parse(flags, matches);
no_check_arg_parse(flags, matches);
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
Expand Down Expand Up @@ -2060,9 +2078,20 @@ fn seed_arg_parse(flags: &mut Flags, matches: &ArgMatches) {
}
}

fn check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("check") {
flags.check = true;
}
}

fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("no-check") {
flags.no_check = true;
// the logger is not setup at this point, so we will just print to stderr
eprintln!(
"{}: The flag --no-check is deprecated and will be removed in the future.",
crate::colors::yellow("warning")
);
}
}

Expand Down Expand Up @@ -2683,7 +2712,7 @@ mod tests {
#[test]
fn eval_with_flags() {
#[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "eval", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "42"]);
let r = flags_from_vec(svec!["deno", "eval", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--check", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "42"]);
assert_eq!(
r.unwrap(),
Flags {
Expand All @@ -2695,6 +2724,7 @@ mod tests {
import_map_path: Some("import_map.json".to_string()),
no_remote: true,
config_path: Some("tsconfig.json".to_string()),
check: true,
no_check: true,
reload: true,
lock: Some(PathBuf::from("lock.json")),
Expand Down Expand Up @@ -2771,7 +2801,7 @@ mod tests {
#[test]
fn repl_with_flags() {
#[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "repl", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229"]);
let r = flags_from_vec(svec!["deno", "repl", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--check", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229"]);
assert_eq!(
r.unwrap(),
Flags {
Expand All @@ -2780,6 +2810,7 @@ mod tests {
import_map_path: Some("import_map.json".to_string()),
no_remote: true,
config_path: Some("tsconfig.json".to_string()),
check: true,
no_check: true,
reload: true,
lock: Some(PathBuf::from("lock.json")),
Expand Down Expand Up @@ -3036,6 +3067,23 @@ mod tests {
);
}

#[test]
fn bundle_check() {
let r =
flags_from_vec(svec!["deno", "bundle", "--check", "script.ts"]).unwrap();
assert_eq!(
r,
Flags {
subcommand: DenoSubcommand::Bundle {
source_file: "script.ts".to_string(),
out_file: None,
},
check: true,
..Flags::default()
}
);
}

#[test]
fn bundle_nocheck() {
let r = flags_from_vec(svec!["deno", "bundle", "--no-check", "script.ts"])
Expand Down Expand Up @@ -3232,7 +3280,7 @@ mod tests {
#[test]
fn install_with_flags() {
#[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "install", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--name", "file_server", "--root", "/foo", "--force", "https://deno.land/std/http/file_server.ts", "foo", "bar"]);
let r = flags_from_vec(svec!["deno", "install", "--import-map", "import_map.json", "--check", "--no-remote", "--config", "tsconfig.json", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--name", "file_server", "--root", "/foo", "--force", "https://deno.land/std/http/file_server.ts", "foo", "bar"]);
assert_eq!(
r.unwrap(),
Flags {
Expand All @@ -3246,6 +3294,7 @@ mod tests {
import_map_path: Some("import_map.json".to_string()),
no_remote: true,
config_path: Some("tsconfig.json".to_string()),
check: true,
no_check: true,
reload: true,
lock: Some(PathBuf::from("lock.json")),
Expand Down Expand Up @@ -3386,6 +3435,21 @@ mod tests {
);
}

#[test]
fn check() {
let r = flags_from_vec(svec!["deno", "run", "--check", "script.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(),
},
check: true,
..Flags::default()
}
)
}

#[test]
fn no_check() {
let r = flags_from_vec(svec!["deno", "run", "--no-check", "script.ts"]);
Expand Down Expand Up @@ -3927,7 +3991,7 @@ mod tests {
#[test]
fn compile_with_flags() {
#[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "compile", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--output", "colors", "https://deno.land/std/examples/colors.ts", "foo", "bar"]);
let r = flags_from_vec(svec!["deno", "compile", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--check", "--no-check", "--unsafely-ignore-certificate-errors", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--output", "colors", "https://deno.land/std/examples/colors.ts", "foo", "bar"]);
assert_eq!(
r.unwrap(),
Flags {
Expand All @@ -3940,6 +4004,7 @@ mod tests {
import_map_path: Some("import_map.json".to_string()),
no_remote: true,
config_path: Some("tsconfig.json".to_string()),
check: true,
no_check: true,
reload: true,
lock: Some(PathBuf::from("lock.json")),
Expand Down
21 changes: 10 additions & 11 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use deno_runtime::worker::MainWorker;
use deno_runtime::worker::WorkerOptions;
use log::debug;
use log::info;
use log::warn;
use std::collections::HashSet;
use std::env;
use std::io::Read;
Expand Down Expand Up @@ -403,7 +404,7 @@ async fn compile_command(
module_specifier.to_string()
);
let bundle_str =
bundle_module_graph(module_graph, program_state.clone(), flags, debug)?;
bundle_module_graph(module_graph, program_state.clone(), debug)?;

info!(
"{} {}",
Expand Down Expand Up @@ -613,7 +614,11 @@ async fn create_module_graph_and_maybe_check(
.await?;
let module_graph = builder.get_graph();

if !program_state.flags.no_check {
if !program_state.flags.check && !program_state.flags.no_check {
warn!("{}: type checking is no longer the default behavior, use the --check flag to type check.", colors::yellow("warning"));
}

if program_state.flags.check {
// TODO(@kitsonk) support bundling for workers
let lib = if program_state.flags.unstable {
module_graph::TypeLib::UnstableDenoWindow
Expand Down Expand Up @@ -645,19 +650,15 @@ async fn create_module_graph_and_maybe_check(
fn bundle_module_graph(
module_graph: module_graph::Graph,
program_state: Arc<ProgramState>,
flags: Flags,
debug: bool,
) -> Result<String, AnyError> {
let (bundle, stats, maybe_ignored_options) =
module_graph.bundle(module_graph::BundleOptions {
debug,
maybe_config_file: program_state.maybe_config_file.clone(),
})?;
match maybe_ignored_options {
Some(ignored_options) if flags.no_check => {
eprintln!("{}", ignored_options);
}
_ => {}
if let Some(ignored_options) = maybe_ignored_options {
eprintln!("{}", ignored_options);
}
debug!("{}", stats);
Ok(bundle)
Expand Down Expand Up @@ -718,13 +719,11 @@ async fn bundle_command(
Arc<ProgramState>,
module_graph::Graph,
)| {
let flags = flags.clone();
let out_file = out_file.clone();
async move {
info!("{} {}", colors::green("Bundle"), module_graph.info()?.root);

let output =
bundle_module_graph(module_graph, program_state, flags, debug)?;
let output = bundle_module_graph(module_graph, program_state, debug)?;

debug!(">>>>> bundle END");

Expand Down
58 changes: 36 additions & 22 deletions cli/program_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub struct ProgramState {
pub maybe_import_map: Option<ImportMap>,
pub maybe_inspector_server: Option<Arc<InspectorServer>>,
pub root_cert_store: Option<RootCertStore>,
/// A flag indicating if the user has been warned about the change in type
/// checking default behavior.
warn_check: Arc<Mutex<bool>>,
pub blob_store: BlobStore,
pub broadcast_channel: InMemoryBroadcastChannel,
pub shared_array_buffer_store: SharedArrayBufferStore,
Expand Down Expand Up @@ -211,6 +214,7 @@ impl ProgramState {
maybe_import_map,
maybe_inspector_server,
root_cert_store: Some(root_cert_store.clone()),
warn_check: Arc::new(Mutex::new(false)),
blob_store,
broadcast_channel,
shared_array_buffer_store,
Expand Down Expand Up @@ -250,34 +254,39 @@ impl ProgramState {
modules.keys().cloned().collect::<HashSet<_>>()
};

let result_modules = if self.flags.no_check {
let result_info = graph.transpile(TranspileOptions {
let result_modules = if self.flags.check {
let result_info = graph.check(CheckOptions {
debug,
emit: true,
lib,
maybe_config_file,
reload: self.flags.reload,
reload_exclusions,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
warn!("{}", ignored_options);
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(anyhow!(result_info.diagnostics));
}
result_info.loadable_modules
} else {
let result_info = graph.check(CheckOptions {
let mut warn_check = self.warn_check.lock();
if warn_check.eq(&false) && !self.flags.no_check {
*warn_check = true;
warn!("{}: type checking is no longer the default behavior, use the --check flag to type check.", colors::yellow("warning"));
}
let result_info = graph.transpile(TranspileOptions {
debug,
emit: true,
lib,
maybe_config_file,
reload: self.flags.reload,
reload_exclusions,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(anyhow!(result_info.diagnostics));
warn!("{}", ignored_options);
}
result_info.loadable_modules
};
Expand Down Expand Up @@ -324,34 +333,39 @@ impl ProgramState {
modules.keys().cloned().collect::<HashSet<_>>()
};

let result_modules = if self.flags.no_check {
let result_info = graph.transpile(TranspileOptions {
let result_modules = if self.flags.check {
let result_info = graph.check(CheckOptions {
debug,
emit: true,
lib,
maybe_config_file,
reload: self.flags.reload,
reload_exclusions,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
warn!("{}", ignored_options);
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(anyhow!(result_info.diagnostics));
}
result_info.loadable_modules
} else {
let result_info = graph.check(CheckOptions {
let mut warn_check = self.warn_check.lock();
if warn_check.eq(&false) && !self.flags.no_check {
*warn_check = true;
warn!("{}: type checking is no longer the default behavior, use the --check flag to type check.", colors::yellow("warning"));
}
let result_info = graph.transpile(TranspileOptions {
debug,
emit: true,
lib,
maybe_config_file,
reload: self.flags.reload,
reload_exclusions,
})?;

debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
eprintln!("{}", ignored_options);
}
if !result_info.diagnostics.is_empty() {
return Err(anyhow!(result_info.diagnostics));
warn!("{}", ignored_options);
}
result_info.loadable_modules
};
Expand Down
Loading