Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make import maps unstable #4934

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - thanks!


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