summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2020-04-28 01:12:38 +0200
committerGitHub <noreply@github.com>2020-04-28 01:12:38 +0200
commite6f70c77ee675848b084e6c5e6342ad516293d39 (patch)
treef7a8868721dbb6c9c15726587ed180a7af0f7b0c
parent4041a7b8576047021c2eec711f013c6f01e471e0 (diff)
Make import maps unstable (#4934)
-rw-r--r--cli/flags.rs32
-rw-r--r--cli/state.rs21
-rw-r--r--cli/tests/import_map_no_unstable.out0
-rw-r--r--cli/tests/integration_tests.rs12
4 files changed, 46 insertions, 19 deletions
diff --git a/cli/flags.rs b/cli/flags.rs
index b06637057..eac617c44 100644
--- a/cli/flags.rs
+++ b/cli/flags.rs
@@ -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();
@@ -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()
@@ -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();
@@ -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.
@@ -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(
@@ -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())
@@ -928,11 +930,6 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.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")
.value_name("NUMBER")
@@ -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(
@@ -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",
diff --git a/cli/state.rs b/cli/state.rs
index 40662b563..32c027c03 100644
--- a/cli/state.rs
+++ b/cli/state.rs
@@ -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,
@@ -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 {
diff --git a/cli/tests/import_map_no_unstable.out b/cli/tests/import_map_no_unstable.out
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/cli/tests/import_map_no_unstable.out
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 68b69c97f..abf7ba372 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -540,6 +540,7 @@ fn bundle_import_map() {
.arg("bundle")
.arg("--importmap")
.arg(import_map_path)
+ .arg("--unstable")
.arg(import)
.arg(&bundle)
.spawn()
@@ -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",
@@ -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",
});