Skip to content

Commit

Permalink
Make import maps unstable (denoland#4934)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored and SASUKE40 committed May 7, 2020
1 parent fb27eb0 commit 9c527c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
32 changes: 21 additions & 11 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ fn install_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
ca_file_arg_parse(flags, matches);
importmap_arg_parse(flags, matches);
unstable_arg_parse(flags, matches);

let source_file = matches.value_of("source_file").unwrap().to_string();

Expand Down Expand Up @@ -459,6 +460,7 @@ fn cache_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
config_arg_parse(flags, matches);
no_remote_arg_parse(flags, matches);
ca_file_arg_parse(flags, matches);
unstable_arg_parse(flags, matches);
let files = matches
.values_of("file")
.unwrap()
Expand Down Expand Up @@ -495,15 +497,12 @@ fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
permission_args_parse(flags, matches);
ca_file_arg_parse(flags, matches);
inspect_arg_parse(flags, matches);
unstable_arg_parse(flags, matches);

if matches.is_present("cached-only") {
flags.cached_only = true;
}

if matches.is_present("unstable") {
flags.unstable = true;
}

if matches.is_present("seed") {
let seed_string = matches.value_of("seed").unwrap();
let seed = seed_string.parse::<u64>().unwrap();
Expand Down Expand Up @@ -684,6 +683,7 @@ fn bundle_subcommand<'a, 'b>() -> App<'a, 'b> {
.arg(Arg::with_name("out_file").takes_value(true).required(false))
.arg(ca_file_arg())
.arg(importmap_arg())
.arg(unstable_arg())
.about("Bundle module and dependencies into single file")
.long_about(
"Output a single JavaScript file with all dependencies.
Expand Down Expand Up @@ -768,6 +768,7 @@ fn cache_subcommand<'a, 'b>() -> App<'a, 'b> {
.arg(lock_arg())
.arg(lock_write_arg())
.arg(importmap_arg())
.arg(unstable_arg())
.arg(config_arg())
.arg(no_remote_arg())
.arg(
Expand Down Expand Up @@ -915,6 +916,7 @@ fn permission_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
permission_args(inspect_args(app))
.arg(importmap_arg())
.arg(unstable_arg())
.arg(reload_arg())
.arg(config_arg())
.arg(lock_arg())
Expand All @@ -927,11 +929,6 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.long("cached-only")
.help("Require that remote dependencies are already cached"),
)
.arg(
Arg::with_name("unstable")
.long("unstable")
.help("Enable unstable APIs"),
)
.arg(
Arg::with_name("seed")
.long("seed")
Expand Down Expand Up @@ -1055,6 +1052,18 @@ fn ca_file_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.ca_file = matches.value_of("cert").map(ToOwned::to_owned);
}

fn unstable_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("unstable")
.long("unstable")
.help("Enable unstable APIs")
}

fn unstable_arg_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
if matches.is_present("unstable") {
flags.unstable = true;
}
}

fn inspect_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
app
.arg(
Expand Down Expand Up @@ -1152,9 +1161,10 @@ fn importmap_arg<'a, 'b>() -> Arg<'a, 'b> {
Arg::with_name("importmap")
.long("importmap")
.value_name("FILE")
.help("Load import map file")
.help("UNSTABLE: Load import map file")
.long_help(
"Load import map file
"UNSTABLE:
Load import map file
Docs: https://deno.land/std/manual.md#import-maps
Specification: https://wicg.github.io/import-maps/
Examples: https://github.com/WICG/import-maps#the-import-map",
Expand Down
21 changes: 15 additions & 6 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,19 @@ impl State {
// stack trace in JS.
let s = self.0.borrow();
if !s.global_state.flags.unstable {
eprintln!(
"Unstable API '{}'. The --unstable flag must be provided.",
api_name
);
std::process::exit(70);
exit_unstable(api_name);
}
}
}

fn exit_unstable(api_name: &str) {
eprintln!(
"Unstable API '{}'. The --unstable flag must be provided.",
api_name
);
std::process::exit(70);
}

impl ModuleLoader for State {
fn resolve(
&self,
Expand Down Expand Up @@ -318,7 +322,12 @@ impl State {
let import_map: Option<ImportMap> =
match global_state.flags.import_map_path.as_ref() {
None => None,
Some(file_path) => Some(ImportMap::load(file_path)?),
Some(file_path) => {
if !global_state.flags.unstable {
exit_unstable("--importmap")
}
Some(ImportMap::load(file_path)?)
}
};

let seeded_rng = match global_state.flags.seed {
Expand Down
Empty file.
12 changes: 10 additions & 2 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ fn bundle_import_map() {
.arg("bundle")
.arg("--importmap")
.arg(import_map_path)
.arg("--unstable")
.arg(import)
.arg(&bundle)
.spawn()
Expand Down Expand Up @@ -1014,10 +1015,17 @@ itest!(_030_eval_ts {

itest!(_033_import_map {
args:
"run --reload --importmap=importmaps/import_map.json importmaps/test.ts",
"run --reload --importmap=importmaps/import_map.json --unstable importmaps/test.ts",
output: "033_import_map.out",
});

itest!(import_map_no_unstable {
args:
"run --reload --importmap=importmaps/import_map.json importmaps/test.ts",
output: "import_map_no_unstable.out",
exit_code: 70,
});

itest!(_034_onload {
args: "run --reload 034_onload/main.ts",
output: "034_onload.out",
Expand All @@ -1035,7 +1043,7 @@ itest_ignore!(_035_cached_only_flag {

itest!(_036_import_map_fetch {
args:
"cache --reload --importmap=importmaps/import_map.json importmaps/test.ts",
"cache --reload --importmap=importmaps/import_map.json --unstable importmaps/test.ts",
output: "036_import_map_fetch.out",
});

Expand Down

0 comments on commit 9c527c4

Please sign in to comment.