summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-03-13 17:04:00 -0400
committerGitHub <noreply@github.com>2023-03-13 17:04:00 -0400
commita35c8e6588fec21586bcb19146cad19fa01f4f23 (patch)
tree9960d58720a25263ca3ee8baca0966f2727b0f37 /cli
parent3db03abf880ae1217d49d8a530a9dfa3f3760e51 (diff)
fix(info/doc): add missing `--no-lock` and `--lock` flags (#18166)
Closes #18159
Diffstat (limited to 'cli')
-rw-r--r--cli/args/flags.rs91
-rw-r--r--cli/tests/integration/bench_tests.rs15
-rw-r--r--cli/tests/integration/doc_tests.rs15
-rw-r--r--cli/tests/integration/info_tests.rs15
-rw-r--r--cli/tests/integration/test_tests.rs15
-rw-r--r--cli/tests/testdata/lockfile/basic/bench.nolock.out7
-rw-r--r--cli/tests/testdata/lockfile/basic/deno.json5
-rw-r--r--cli/tests/testdata/lockfile/basic/deno.lock6
-rw-r--r--cli/tests/testdata/lockfile/basic/doc.nolock.out1
-rw-r--r--cli/tests/testdata/lockfile/basic/fail.out4
-rw-r--r--cli/tests/testdata/lockfile/basic/info.nolock.out8
-rw-r--r--cli/tests/testdata/lockfile/basic/main.bench.ts8
-rw-r--r--cli/tests/testdata/lockfile/basic/main.test.ts8
-rw-r--r--cli/tests/testdata/lockfile/basic/main.ts1
-rw-r--r--cli/tests/testdata/lockfile/basic/mod.ts1
-rw-r--r--cli/tests/testdata/lockfile/basic/test.nolock.out5
-rw-r--r--cli/tools/doc.rs6
-rw-r--r--cli/tools/info.rs5
18 files changed, 182 insertions, 34 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index f78938869..26cf497f6 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -1092,6 +1092,10 @@ Show documentation for runtime built-ins:
)
.arg(import_map_arg())
.arg(reload_arg())
+ .arg(lock_arg())
+ .arg(no_lock_arg())
+ .arg(no_npm_arg())
+ .arg(no_remote_arg())
.arg(
Arg::new("json")
.long("json")
@@ -1339,9 +1343,12 @@ 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>'")
)
- // TODO(lucacasonato): remove for 2.0
- .arg(no_check_arg().hide(true))
+ .arg(no_check_arg().hide(true)) // TODO(lucacasonato): remove for 2.0
.arg(no_config_arg())
+ .arg(no_remote_arg())
+ .arg(no_npm_arg())
+ .arg(no_lock_arg())
+ .arg(lock_arg())
.arg(config_arg())
.arg(import_map_arg())
.arg(local_npm_arg())
@@ -1890,20 +1897,7 @@ Remote modules and multiple modules may also be specified:
}
fn compile_args(app: Command) -> Command {
- app
- .arg(import_map_arg())
- .arg(no_remote_arg())
- .arg(no_npm_arg())
- .arg(local_npm_arg())
- .arg(no_config_arg())
- .arg(config_arg())
- .arg(no_check_arg())
- .arg(check_arg())
- .arg(reload_arg())
- .arg(lock_arg())
- .arg(lock_write_arg())
- .arg(no_lock_arg())
- .arg(ca_file_arg())
+ compile_args_without_check_args(app.arg(no_check_arg()).arg(check_arg()))
}
fn compile_args_without_check_args(app: Command) -> Command {
@@ -2304,6 +2298,7 @@ fn lock_write_arg<'a>() -> Arg<'a> {
Arg::new("lock-write")
.long("lock-write")
.help("Force overwriting the lock file.")
+ .conflicts_with("no-lock")
}
fn no_lock_arg<'a>() -> Arg<'a> {
@@ -2311,7 +2306,6 @@ fn no_lock_arg<'a>() -> Arg<'a> {
.long("no-lock")
.help("Disable auto discovery of the lock file.")
.conflicts_with("lock")
- .conflicts_with("lock-write")
}
static CONFIG_HELP: Lazy<String> = Lazy::new(|| {
@@ -2461,7 +2455,7 @@ fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn check_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.type_check_mode = TypeCheckMode::Local;
- compile_args_without_no_check_parse(flags, matches);
+ compile_args_without_check_parse(flags, matches);
let files = matches
.values_of("file")
.unwrap()
@@ -2559,6 +2553,10 @@ fn coverage_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn doc_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
import_map_arg_parse(flags, matches);
reload_arg_parse(flags, matches);
+ lock_arg_parse(flags, matches);
+ no_lock_arg_parse(flags, matches);
+ no_npm_arg_parse(flags, matches);
+ no_remote_arg_parse(flags, matches);
let source_file = matches
.value_of("source_file")
@@ -2683,6 +2681,10 @@ fn info_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
location_arg_parse(flags, matches);
ca_file_arg_parse(flags, matches);
local_npm_args_parse(flags, matches);
+ lock_arg_parse(flags, matches);
+ no_lock_arg_parse(flags, matches);
+ no_remote_arg_parse(flags, matches);
+ no_npm_arg_parse(flags, matches);
let json = matches.is_present("json");
flags.subcommand = DenoSubcommand::Info(InfoFlags {
file: matches.value_of("file").map(|f| f.to_string()),
@@ -3011,19 +3013,12 @@ fn vendor_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}
fn compile_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
- import_map_arg_parse(flags, matches);
- no_remote_arg_parse(flags, matches);
- no_npm_arg_parse(flags, matches);
- local_npm_args_parse(flags, matches);
- config_args_parse(flags, matches);
+ compile_args_without_check_parse(flags, matches);
no_check_arg_parse(flags, matches);
check_arg_parse(flags, matches);
- reload_arg_parse(flags, matches);
- lock_args_parse(flags, matches);
- ca_file_arg_parse(flags, matches);
}
-fn compile_args_without_no_check_parse(
+fn compile_args_without_check_parse(
flags: &mut Flags,
matches: &clap::ArgMatches,
) {
@@ -3116,6 +3111,7 @@ fn unsafely_ignore_certificate_errors_parse(
flags.unsafely_ignore_certificate_errors = Some(ic_allowlist);
}
}
+
fn runtime_args_parse(
flags: &mut Flags,
matches: &clap::ArgMatches,
@@ -3259,12 +3255,10 @@ fn check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn lock_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
lock_arg_parse(flags, matches);
+ no_lock_arg_parse(flags, matches);
if matches.is_present("lock-write") {
flags.lock_write = true;
}
- if matches.is_present("no-lock") {
- flags.no_lock = true;
- }
}
fn lock_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
@@ -3278,6 +3272,12 @@ fn lock_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}
}
+fn no_lock_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
+ if matches.is_present("no-lock") {
+ flags.no_lock = true;
+ }
+}
+
fn config_args_parse(flags: &mut Flags, matches: &ArgMatches) {
flags.config_flag = if matches.is_present("no-config") {
ConfigFlag::Disabled
@@ -4289,7 +4289,14 @@ mod tests {
}
);
- let r = flags_from_vec(svec!["deno", "info", "--config", "tsconfig.json"]);
+ let r = flags_from_vec(svec![
+ "deno",
+ "info",
+ "--no-npm",
+ "--no-remote",
+ "--config",
+ "tsconfig.json"
+ ]);
assert_eq!(
r.unwrap(),
Flags {
@@ -4298,6 +4305,8 @@ mod tests {
file: None
}),
config_flag: ConfigFlag::Path("tsconfig.json".to_owned()),
+ no_npm: true,
+ no_remote: true,
..Flags::default()
}
);
@@ -5715,7 +5724,7 @@ mod tests {
#[test]
fn test_with_flags() {
#[rustfmt::skip]
- let r = flags_from_vec(svec!["deno", "test", "--unstable", "--trace-ops", "--no-run", "--filter", "- foo", "--coverage=cov", "--location", "https:foo", "--allow-net", "--allow-none", "dir1/", "dir2/", "--", "arg1", "arg2"]);
+ let r = flags_from_vec(svec!["deno", "test", "--unstable", "--no-npm", "--no-remote", "--trace-ops", "--no-run", "--filter", "- foo", "--coverage=cov", "--location", "https:foo", "--allow-net", "--allow-none", "dir1/", "dir2/", "--", "arg1", "arg2"]);
assert_eq!(
r.unwrap(),
Flags {
@@ -5735,6 +5744,8 @@ mod tests {
}),
unstable: true,
no_prompt: true,
+ no_npm: true,
+ no_remote: true,
coverage_dir: Some("cov".to_string()),
location: Some(Url::parse("https://foo/").unwrap()),
type_check_mode: TypeCheckMode::Local,
@@ -6140,8 +6151,14 @@ mod tests {
}
);
- let r =
- flags_from_vec(svec!["deno", "doc", "--private", "path/to/module.js"]);
+ let r = flags_from_vec(svec![
+ "deno",
+ "doc",
+ "--no-npm",
+ "--no-remote",
+ "--private",
+ "path/to/module.js"
+ ]);
assert_eq!(
r.unwrap(),
Flags {
@@ -6151,6 +6168,8 @@ mod tests {
source_file: DocSourceFileFlag::Path("path/to/module.js".to_string()),
filter: None,
}),
+ no_npm: true,
+ no_remote: true,
..Flags::default()
}
);
@@ -6617,6 +6636,8 @@ mod tests {
"bench",
"--json",
"--unstable",
+ "--no-npm",
+ "--no-remote",
"--filter",
"- foo",
"--location",
@@ -6640,6 +6661,8 @@ mod tests {
},
}),
unstable: true,
+ no_npm: true,
+ no_remote: true,
type_check_mode: TypeCheckMode::Local,
location: Some(Url::parse("https://foo/").unwrap()),
allow_net: Some(vec![]),
diff --git a/cli/tests/integration/bench_tests.rs b/cli/tests/integration/bench_tests.rs
index b2cd38475..e5174025e 100644
--- a/cli/tests/integration/bench_tests.rs
+++ b/cli/tests/integration/bench_tests.rs
@@ -224,3 +224,18 @@ itest!(package_json_basic {
copy_temp_dir: Some("package_json/basic"),
exit_code: 0,
});
+
+itest!(bench_lock {
+ args: "bench",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ exit_code: 10,
+ output: "lockfile/basic/fail.out",
+});
+
+itest!(bench_no_lock {
+ args: "bench --no-lock",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ output: "lockfile/basic/bench.nolock.out",
+});
diff --git a/cli/tests/integration/doc_tests.rs b/cli/tests/integration/doc_tests.rs
index de611d405..72f5f4314 100644
--- a/cli/tests/integration/doc_tests.rs
+++ b/cli/tests/integration/doc_tests.rs
@@ -64,3 +64,18 @@ itest!(deno_doc_invalid_url {
output: "doc/invalid_url.out",
exit_code: 1,
});
+
+itest!(doc_lock {
+ args: "doc main.ts",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ exit_code: 10,
+ output: "lockfile/basic/fail.out",
+});
+
+itest!(doc_no_lock {
+ args: "doc --no-lock main.ts",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ output: "lockfile/basic/doc.nolock.out",
+});
diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs
index 704aaa7af..5b2f2d740 100644
--- a/cli/tests/integration/info_tests.rs
+++ b/cli/tests/integration/info_tests.rs
@@ -94,6 +94,21 @@ itest!(info_missing_module {
output: "info/info_missing_module.out",
});
+itest!(info_lock {
+ args: "info main.ts",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ exit_code: 10,
+ output: "lockfile/basic/fail.out",
+});
+
+itest!(info_no_lock {
+ args: "info --no-lock main.ts",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ output: "lockfile/basic/info.nolock.out",
+});
+
itest!(info_recursive_modules {
args: "info --quiet info/info_recursive_imports_test.ts",
output: "info/info_recursive_imports_test.out",
diff --git a/cli/tests/integration/test_tests.rs b/cli/tests/integration/test_tests.rs
index de7bc5fed..047dcbc7e 100644
--- a/cli/tests/integration/test_tests.rs
+++ b/cli/tests/integration/test_tests.rs
@@ -453,3 +453,18 @@ itest!(package_json_basic {
copy_temp_dir: Some("package_json/basic"),
exit_code: 0,
});
+
+itest!(test_lock {
+ args: "test",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ exit_code: 10,
+ output: "lockfile/basic/fail.out",
+});
+
+itest!(test_no_lock {
+ args: "test --no-lock",
+ http_server: true,
+ cwd: Some("lockfile/basic"),
+ output: "lockfile/basic/test.nolock.out",
+});
diff --git a/cli/tests/testdata/lockfile/basic/bench.nolock.out b/cli/tests/testdata/lockfile/basic/bench.nolock.out
new file mode 100644
index 000000000..e81474f2a
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/bench.nolock.out
@@ -0,0 +1,7 @@
+Download http://localhost:4545/lockfile/basic/mod.ts
+Check file:///[WILDCARD]/main.bench.ts
+5
+cpu: [WILDCARD]
+runtime: [WILDCARD]
+
+[WILDCARD]
diff --git a/cli/tests/testdata/lockfile/basic/deno.json b/cli/tests/testdata/lockfile/basic/deno.json
new file mode 100644
index 000000000..d6541b78e
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/deno.json
@@ -0,0 +1,5 @@
+{
+ "imports": {
+ "mod": "http://localhost:4545/lockfile/basic/mod.ts"
+ }
+}
diff --git a/cli/tests/testdata/lockfile/basic/deno.lock b/cli/tests/testdata/lockfile/basic/deno.lock
new file mode 100644
index 000000000..42ab94f9b
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/deno.lock
@@ -0,0 +1,6 @@
+{
+ "version": "2",
+ "remote": {
+ "http://localhost:4545/lockfile/basic/mod.ts": "invalid"
+ }
+}
diff --git a/cli/tests/testdata/lockfile/basic/doc.nolock.out b/cli/tests/testdata/lockfile/basic/doc.nolock.out
new file mode 100644
index 000000000..e2d66c027
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/doc.nolock.out
@@ -0,0 +1 @@
+Download http://localhost:4545/lockfile/basic/mod.ts
diff --git a/cli/tests/testdata/lockfile/basic/fail.out b/cli/tests/testdata/lockfile/basic/fail.out
new file mode 100644
index 000000000..6a808c0a5
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/fail.out
@@ -0,0 +1,4 @@
+Download http://localhost:4545/lockfile/basic/mod.ts
+error: The source code is invalid, as it does not match the expected hash in the lock file.
+ Specifier: [WILDCARD]mod.ts
+ Lock file: [WILDCARD]deno.lock
diff --git a/cli/tests/testdata/lockfile/basic/info.nolock.out b/cli/tests/testdata/lockfile/basic/info.nolock.out
new file mode 100644
index 000000000..d1ef82e49
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/info.nolock.out
@@ -0,0 +1,8 @@
+Download http://localhost:4545/lockfile/basic/mod.ts
+local: [WILDCARD]main.ts
+type: TypeScript
+dependencies: 1 unique
+size: [WILDCARD]
+
+file:///[WILDCARD]/main.ts ([WILDCARD])
+└── http://localhost:4545/lockfile/basic/mod.ts ([WILDCARD])
diff --git a/cli/tests/testdata/lockfile/basic/main.bench.ts b/cli/tests/testdata/lockfile/basic/main.bench.ts
new file mode 100644
index 000000000..2a7457680
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/main.bench.ts
@@ -0,0 +1,8 @@
+import "./main.ts";
+
+Deno.bench("bench", () => {
+ const testing = 1 + 2;
+ if (testing !== 3) {
+ throw "FAIL";
+ }
+});
diff --git a/cli/tests/testdata/lockfile/basic/main.test.ts b/cli/tests/testdata/lockfile/basic/main.test.ts
new file mode 100644
index 000000000..bb757de23
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/main.test.ts
@@ -0,0 +1,8 @@
+import "./main.ts";
+
+Deno.test("test", () => {
+ const testing = 1 + 2;
+ if (testing !== 3) {
+ throw "FAIL";
+ }
+});
diff --git a/cli/tests/testdata/lockfile/basic/main.ts b/cli/tests/testdata/lockfile/basic/main.ts
new file mode 100644
index 000000000..5eed100f5
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/main.ts
@@ -0,0 +1 @@
+import "mod";
diff --git a/cli/tests/testdata/lockfile/basic/mod.ts b/cli/tests/testdata/lockfile/basic/mod.ts
new file mode 100644
index 000000000..0f3785f91
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/mod.ts
@@ -0,0 +1 @@
+console.log(5);
diff --git a/cli/tests/testdata/lockfile/basic/test.nolock.out b/cli/tests/testdata/lockfile/basic/test.nolock.out
new file mode 100644
index 000000000..3b5999513
--- /dev/null
+++ b/cli/tests/testdata/lockfile/basic/test.nolock.out
@@ -0,0 +1,5 @@
+Download http://localhost:4545/lockfile/basic/mod.ts
+Check file:///[WILDCARD]/main.test.ts
+5
+running 1 test from ./main.test.ts
+[WILDCARD]
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index e0413ab79..1f8bfad7a 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -7,6 +7,7 @@ use crate::colors;
use crate::display::write_json_to_stdout;
use crate::display::write_to_stdout_ignore_sigpipe;
use crate::file_fetcher::File;
+use crate::graph_util::graph_lock_or_exit;
use crate::proc_state::ProcState;
use crate::tsc::get_types_declaration_file_text;
use deno_ast::MediaType;
@@ -77,6 +78,11 @@ pub async fn print_docs(
ps.file_fetcher.insert_cached(root);
let graph = ps.create_graph(vec![root_specifier.clone()]).await?;
+
+ if let Some(lockfile) = &ps.lockfile {
+ graph_lock_or_exit(&graph, &mut lockfile.lock());
+ }
+
let doc_parser = doc::DocParser::new(
graph,
doc_flags.private,
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index 8a7f4b6b9..f7284154a 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -23,6 +23,7 @@ use deno_runtime::colors;
use crate::args::Flags;
use crate::args::InfoFlags;
use crate::display;
+use crate::graph_util::graph_lock_or_exit;
use crate::npm::NpmPackageId;
use crate::npm::NpmPackageResolver;
use crate::npm::NpmResolutionPackage;
@@ -40,6 +41,10 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
.create_graph_with_loader(vec![specifier], &mut loader)
.await?;
+ if let Some(lockfile) = &ps.lockfile {
+ graph_lock_or_exit(&graph, &mut lockfile.lock());
+ }
+
if info_flags.json {
let mut json_graph = json!(graph);
add_npm_packages_to_json(&mut json_graph, &ps.npm_resolver);