summaryrefslogtreecommitdiff
path: root/cli/args/flags.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-09-22 11:17:02 -0400
committerGitHub <noreply@github.com>2022-09-22 11:17:02 -0400
commit716005a0d4afd1042fa75d8bdc32fd13e9ebe95f (patch)
tree4c417eb7b91d6203aacba7dcd81bee3f13c0cfd3 /cli/args/flags.rs
parent9a216806d514b5f41c73c777010572cdf3c51eab (diff)
feat(npm): add flag for creating and resolving npm packages to a local node_modules folder (#15971)
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r--cli/args/flags.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 7922a3c19..513307e92 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -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(()),
@@ -5035,6 +5052,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"]);
assert_eq!(