mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix(info/doc): add missing --no-lock
and --lock
flags (#18166)
Closes #18159
This commit is contained in:
parent
3db03abf88
commit
a35c8e6588
18 changed files with 182 additions and 34 deletions
|
@ -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![]),
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
7
cli/tests/testdata/lockfile/basic/bench.nolock.out
vendored
Normal file
7
cli/tests/testdata/lockfile/basic/bench.nolock.out
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
Download http://localhost:4545/lockfile/basic/mod.ts
|
||||
Check file:///[WILDCARD]/main.bench.ts
|
||||
5
|
||||
cpu: [WILDCARD]
|
||||
runtime: [WILDCARD]
|
||||
|
||||
[WILDCARD]
|
5
cli/tests/testdata/lockfile/basic/deno.json
vendored
Normal file
5
cli/tests/testdata/lockfile/basic/deno.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"imports": {
|
||||
"mod": "http://localhost:4545/lockfile/basic/mod.ts"
|
||||
}
|
||||
}
|
6
cli/tests/testdata/lockfile/basic/deno.lock
vendored
Normal file
6
cli/tests/testdata/lockfile/basic/deno.lock
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"version": "2",
|
||||
"remote": {
|
||||
"http://localhost:4545/lockfile/basic/mod.ts": "invalid"
|
||||
}
|
||||
}
|
1
cli/tests/testdata/lockfile/basic/doc.nolock.out
vendored
Normal file
1
cli/tests/testdata/lockfile/basic/doc.nolock.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Download http://localhost:4545/lockfile/basic/mod.ts
|
4
cli/tests/testdata/lockfile/basic/fail.out
vendored
Normal file
4
cli/tests/testdata/lockfile/basic/fail.out
vendored
Normal file
|
@ -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
|
8
cli/tests/testdata/lockfile/basic/info.nolock.out
vendored
Normal file
8
cli/tests/testdata/lockfile/basic/info.nolock.out
vendored
Normal file
|
@ -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])
|
8
cli/tests/testdata/lockfile/basic/main.bench.ts
vendored
Normal file
8
cli/tests/testdata/lockfile/basic/main.bench.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
import "./main.ts";
|
||||
|
||||
Deno.bench("bench", () => {
|
||||
const testing = 1 + 2;
|
||||
if (testing !== 3) {
|
||||
throw "FAIL";
|
||||
}
|
||||
});
|
8
cli/tests/testdata/lockfile/basic/main.test.ts
vendored
Normal file
8
cli/tests/testdata/lockfile/basic/main.test.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
import "./main.ts";
|
||||
|
||||
Deno.test("test", () => {
|
||||
const testing = 1 + 2;
|
||||
if (testing !== 3) {
|
||||
throw "FAIL";
|
||||
}
|
||||
});
|
1
cli/tests/testdata/lockfile/basic/main.ts
vendored
Normal file
1
cli/tests/testdata/lockfile/basic/main.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
import "mod";
|
1
cli/tests/testdata/lockfile/basic/mod.ts
vendored
Normal file
1
cli/tests/testdata/lockfile/basic/mod.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log(5);
|
5
cli/tests/testdata/lockfile/basic/test.nolock.out
vendored
Normal file
5
cli/tests/testdata/lockfile/basic/test.nolock.out
vendored
Normal file
|
@ -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]
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue