diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-10-05 01:35:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 01:35:55 +0200 |
commit | f1d3a170430501b4fab1a2d2abb5d77528251c77 (patch) | |
tree | 4951edeccc1ef25e4dc2703a6a8e2b38a33fbb20 /cli/flags.rs | |
parent | 64a7187238c4f291f254bd6eb58138a3a6534898 (diff) |
feat: add --compat flag to provide built-in Node modules (#12293)
This commit adds "--compat" flag. When the flag is passed a set of mappings for
built-in Node modules is injected into the import map. If user doesn't
explicitly provide an import map (using "--import-map" flag) then a map is
created on the fly. If there are already existing mappings in import map that
would clash with built-in Node modules a set of diagnostics is printed to the
terminal with suggestions how to proceed.
Diffstat (limited to 'cli/flags.rs')
-rw-r--r-- | cli/flags.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index aaff45388..dc0e932ef 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -222,6 +222,9 @@ pub struct Flags { pub log_level: Option<Level>, pub no_check: bool, pub no_remote: bool, + /// If true, a list of Node built-in modules will be injected into + /// the import map. + pub compat: bool, pub prompt: bool, pub reload: bool, pub repl: bool, @@ -1490,6 +1493,7 @@ fn runtime_args<'a, 'b>( .arg(v8_flags_arg()) .arg(seed_arg()) .arg(enable_testing_features_arg()) + .arg(compat_arg()) } fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { @@ -1619,6 +1623,12 @@ fn seed_arg<'a, 'b>() -> Arg<'a, 'b> { }) } +fn compat_arg<'a, 'b>() -> Arg<'a, 'b> { + Arg::with_name("compat") + .long("compat") + .help("Node compatibility mode. Currently only enables built-in node modules like 'fs'.") +} + fn watch_arg<'a, 'b>() -> Arg<'a, 'b> { Arg::with_name("watch") .long("watch") @@ -2228,6 +2238,7 @@ fn runtime_args_parse( location_arg_parse(flags, matches); v8_flags_arg_parse(flags, matches); seed_arg_parse(flags, matches); + compat_arg_parse(flags, matches); inspect_arg_parse(flags, matches); enable_testing_features_arg_parse(flags, matches); } @@ -2313,6 +2324,12 @@ fn seed_arg_parse(flags: &mut Flags, matches: &ArgMatches) { } } +fn compat_arg_parse(flags: &mut Flags, matches: &ArgMatches) { + if matches.is_present("compat") { + flags.compat = true; + } +} + fn no_check_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) { if matches.is_present("no-check") { flags.no_check = true; @@ -4431,4 +4448,19 @@ mod tests { .to_string() .contains("Expected protocol \"http\" or \"https\"")); } + + #[test] + fn compat() { + let r = flags_from_vec(svec!["deno", "run", "--compat", "foo.js"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Run(RunFlags { + script: "foo.js".to_string(), + }), + compat: true, + ..Flags::default() + } + ); + } } |