feat(npm): add flag for creating and resolving npm packages to a local node_modules folder (#15971)

This commit is contained in:
David Sherret 2022-09-22 11:17:02 -04:00 committed by GitHub
parent 9a216806d5
commit 716005a0d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 744 additions and 126 deletions

View file

@ -301,6 +301,7 @@ pub struct Flags {
pub cached_only: bool,
pub type_check_mode: TypeCheckMode,
pub config_flag: ConfigFlag,
pub node_modules_dir: bool,
pub coverage_dir: Option<String>,
pub enable_testing_features: bool,
pub ignore: Vec<PathBuf>,
@ -1734,6 +1735,7 @@ fn compile_args(app: Command) -> Command {
.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())
@ -1749,6 +1751,7 @@ fn compile_args_without_check_args(app: Command) -> Command {
.arg(import_map_arg())
.arg(no_remote_arg())
.arg(no_npm_arg())
.arg(local_npm_arg())
.arg(config_arg())
.arg(no_config_arg())
.arg(reload_arg())
@ -2153,6 +2156,12 @@ fn no_npm_arg<'a>() -> Arg<'a> {
.help("Do not resolve npm modules")
}
fn local_npm_arg<'a>() -> Arg<'a> {
Arg::new("node-modules-dir")
.long("node-modules-dir")
.help("Creates a local node_modules folder")
}
fn unsafely_ignore_certificate_errors_arg<'a>() -> Arg<'a> {
Arg::new("unsafely-ignore-certificate-errors")
.long("unsafely-ignore-certificate-errors")
@ -2799,6 +2808,7 @@ 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);
no_check_arg_parse(flags, matches);
check_arg_parse(flags, matches);
@ -2814,6 +2824,7 @@ fn compile_args_without_no_check_parse(
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);
reload_arg_parse(flags, matches);
lock_args_parse(flags, matches);
@ -3061,6 +3072,12 @@ fn no_npm_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}
}
fn local_npm_args_parse(flags: &mut Flags, matches: &ArgMatches) {
if matches.is_present("node-modules-dir") {
flags.node_modules_dir = true;
}
}
fn inspect_arg_validate(val: &str) -> Result<(), String> {
match val.parse::<SocketAddr>() {
Ok(_) => Ok(()),
@ -5034,6 +5051,22 @@ mod tests {
);
}
#[test]
fn local_npm() {
let r =
flags_from_vec(svec!["deno", "run", "--node-modules-dir", "script.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run(RunFlags {
script: "script.ts".to_string(),
}),
node_modules_dir: true,
..Flags::default()
}
);
}
#[test]
fn cached_only() {
let r = flags_from_vec(svec!["deno", "run", "--cached-only", "script.ts"]);