1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

feat: stabilise import maps (#9526)

This commit stabilises import maps by removing requirement
on "--unstable" flag when "--import-map" flag is used.
This commit is contained in:
Bartek Iwańczuk 2021-03-01 12:41:22 +01:00 committed by GitHub
parent 7cd14f97c9
commit 0dc89c0a79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 41 deletions

View file

@ -1691,11 +1691,9 @@ fn import_map_arg<'a, 'b>() -> Arg<'a, 'b> {
.long("import-map") .long("import-map")
.alias("importmap") .alias("importmap")
.value_name("FILE") .value_name("FILE")
.requires("unstable") .help("Load import map file")
.help("UNSTABLE: Load import map file")
.long_help( .long_help(
"UNSTABLE: "Load import map file from local file or remote URL.
Load import map file
Docs: https://deno.land/manual/linking_to_external_code/import_maps Docs: https://deno.land/manual/linking_to_external_code/import_maps
Specification: https://wicg.github.io/import-maps/ Specification: https://wicg.github.io/import-maps/
Examples: https://github.com/WICG/import-maps#the-import-map", Examples: https://github.com/WICG/import-maps#the-import-map",
@ -2465,7 +2463,7 @@ mod tests {
#[test] #[test]
fn eval_with_flags() { fn eval_with_flags() {
#[rustfmt::skip] #[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "eval", "--unstable", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "42"]); let r = flags_from_vec(svec!["deno", "eval", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "42"]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
Flags { Flags {
@ -2474,7 +2472,6 @@ mod tests {
code: "42".to_string(), code: "42".to_string(),
ext: "js".to_string(), ext: "js".to_string(),
}, },
unstable: true,
import_map_path: Some("import_map.json".to_string()), import_map_path: Some("import_map.json".to_string()),
no_remote: true, no_remote: true,
config_path: Some("tsconfig.json".to_string()), config_path: Some("tsconfig.json".to_string()),
@ -2553,13 +2550,12 @@ mod tests {
#[test] #[test]
fn repl_with_flags() { fn repl_with_flags() {
#[rustfmt::skip] #[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "repl", "--unstable", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229"]); let r = flags_from_vec(svec!["deno", "repl", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229"]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
Flags { Flags {
repl: true, repl: true,
subcommand: DenoSubcommand::Repl, subcommand: DenoSubcommand::Repl,
unstable: true,
import_map_path: Some("import_map.json".to_string()), import_map_path: Some("import_map.json".to_string()),
no_remote: true, no_remote: true,
config_path: Some("tsconfig.json".to_string()), config_path: Some("tsconfig.json".to_string()),
@ -2792,7 +2788,6 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"run", "run",
"--unstable",
"--import-map=import_map.json", "--import-map=import_map.json",
"script.ts" "script.ts"
]); ]);
@ -2802,7 +2797,6 @@ mod tests {
subcommand: DenoSubcommand::Run { subcommand: DenoSubcommand::Run {
script: "script.ts".to_string(), script: "script.ts".to_string(),
}, },
unstable: true,
import_map_path: Some("import_map.json".to_owned()), import_map_path: Some("import_map.json".to_owned()),
..Flags::default() ..Flags::default()
} }
@ -2814,7 +2808,6 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"info", "info",
"--unstable",
"--import-map=import_map.json", "--import-map=import_map.json",
"script.ts" "script.ts"
]); ]);
@ -2825,7 +2818,6 @@ mod tests {
file: Some("script.ts".to_string()), file: Some("script.ts".to_string()),
json: false, json: false,
}, },
unstable: true,
import_map_path: Some("import_map.json".to_owned()), import_map_path: Some("import_map.json".to_owned()),
..Flags::default() ..Flags::default()
} }
@ -2837,7 +2829,6 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"cache", "cache",
"--unstable",
"--import-map=import_map.json", "--import-map=import_map.json",
"script.ts" "script.ts"
]); ]);
@ -2847,7 +2838,6 @@ mod tests {
subcommand: DenoSubcommand::Cache { subcommand: DenoSubcommand::Cache {
files: svec!["script.ts"], files: svec!["script.ts"],
}, },
unstable: true,
import_map_path: Some("import_map.json".to_owned()), import_map_path: Some("import_map.json".to_owned()),
..Flags::default() ..Flags::default()
} }
@ -2859,7 +2849,6 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"doc", "doc",
"--unstable",
"--import-map=import_map.json", "--import-map=import_map.json",
"script.ts" "script.ts"
]); ]);
@ -2872,7 +2861,6 @@ mod tests {
json: false, json: false,
filter: None, filter: None,
}, },
unstable: true,
import_map_path: Some("import_map.json".to_owned()), import_map_path: Some("import_map.json".to_owned()),
..Flags::default() ..Flags::default()
} }
@ -2958,7 +2946,7 @@ mod tests {
#[test] #[test]
fn install_with_flags() { fn install_with_flags() {
#[rustfmt::skip] #[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "install", "--unstable", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--name", "file_server", "--root", "/foo", "--force", "https://deno.land/std/http/file_server.ts", "foo", "bar"]); let r = flags_from_vec(svec!["deno", "install", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--inspect=127.0.0.1:9229", "--name", "file_server", "--root", "/foo", "--force", "https://deno.land/std/http/file_server.ts", "foo", "bar"]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
Flags { Flags {
@ -2969,7 +2957,6 @@ mod tests {
root: Some(PathBuf::from("/foo")), root: Some(PathBuf::from("/foo")),
force: true, force: true,
}, },
unstable: true,
import_map_path: Some("import_map.json".to_string()), import_map_path: Some("import_map.json".to_string()),
no_remote: true, no_remote: true,
config_path: Some("tsconfig.json".to_string()), config_path: Some("tsconfig.json".to_string()),
@ -3490,7 +3477,7 @@ mod tests {
#[test] #[test]
fn compile_with_flags() { fn compile_with_flags() {
#[rustfmt::skip] #[rustfmt::skip]
let r = flags_from_vec(svec!["deno", "compile", "--unstable", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--output", "colors", "https://deno.land/std/examples/colors.ts", "foo", "bar"]); let r = flags_from_vec(svec!["deno", "compile", "--import-map", "import_map.json", "--no-remote", "--config", "tsconfig.json", "--no-check", "--reload", "--lock", "lock.json", "--lock-write", "--cert", "example.crt", "--cached-only", "--location", "https:foo", "--allow-read", "--allow-net", "--v8-flags=--help", "--seed", "1", "--output", "colors", "https://deno.land/std/examples/colors.ts", "foo", "bar"]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
Flags { Flags {
@ -3501,7 +3488,6 @@ mod tests {
target: None, target: None,
lite: false, lite: false,
}, },
unstable: true,
import_map_path: Some("import_map.json".to_string()), import_map_path: Some("import_map.json".to_string()),
no_remote: true, no_remote: true,
config_path: Some("tsconfig.json".to_string()), config_path: Some("tsconfig.json".to_string()),

View file

@ -96,9 +96,6 @@ impl ProgramState {
match flags.import_map_path.as_ref() { match flags.import_map_path.as_ref() {
None => None, None => None,
Some(import_map_url) => { Some(import_map_url) => {
if !flags.unstable {
exit_unstable("--import-map")
}
let import_map_specifier = let import_map_specifier =
deno_core::resolve_url_or_path(&import_map_url).context( deno_core::resolve_url_or_path(&import_map_url).context(
format!("Bad URL (\"{}\") for import map.", import_map_url), format!("Bad URL (\"{}\") for import map.", import_map_url),

View file

@ -1 +0,0 @@
Unstable API '--import-map'. The --unstable flag must be provided.

View file

@ -1627,7 +1627,6 @@ mod integration {
.arg("bundle") .arg("bundle")
.arg("--import-map") .arg("--import-map")
.arg(import_map_path) .arg(import_map_path)
.arg("--unstable")
.arg(import) .arg(import)
.arg(&bundle) .arg(&bundle)
.spawn() .spawn()
@ -1673,7 +1672,6 @@ mod integration {
.arg("--no-check") .arg("--no-check")
.arg("--import-map") .arg("--import-map")
.arg(import_map_path) .arg(import_map_path)
.arg("--unstable")
.arg(import) .arg(import)
.arg(&bundle) .arg(&bundle)
.spawn() .spawn()
@ -2535,7 +2533,7 @@ console.log("finish");
itest!(_033_import_map { itest!(_033_import_map {
args: args:
"run --quiet --reload --import-map=import_maps/import_map.json --unstable import_maps/test.ts", "run --quiet --reload --import-map=import_maps/import_map.json import_maps/test.ts",
output: "033_import_map.out", output: "033_import_map.out",
}); });
@ -2561,7 +2559,7 @@ console.log("finish");
itest!(_036_import_map_fetch { itest!(_036_import_map_fetch {
args: args:
"cache --quiet --reload --import-map=import_maps/import_map.json --unstable import_maps/test.ts", "cache --quiet --reload --import-map=import_maps/import_map.json import_maps/test.ts",
output: "036_import_map_fetch.out", output: "036_import_map_fetch.out",
}); });
@ -2706,7 +2704,7 @@ console.log("finish");
itest!(_065_import_map_info { itest!(_065_import_map_info {
args: args:
"info --quiet --import-map=import_maps/import_map.json --unstable import_maps/test.ts", "info --quiet --import-map=import_maps/import_map.json import_maps/test.ts",
output: "065_import_map_info.out", output: "065_import_map_info.out",
}); });
@ -3688,7 +3686,7 @@ console.log("finish");
}); });
itest!(import_data_url_import_map { itest!(import_data_url_import_map {
args: "run --quiet --reload --unstable --import-map import_maps/import_map.json import_data_url.ts", args: "run --quiet --reload --import-map import_maps/import_map.json import_data_url.ts",
output: "import_data_url.ts.out", output: "import_data_url.ts.out",
}); });

View file

@ -1,19 +1,9 @@
## Import maps ## Import maps
> This is an unstable feature. Learn more about
> [unstable features](../runtime/stability.md).
Deno supports [import maps](https://github.com/WICG/import-maps). Deno supports [import maps](https://github.com/WICG/import-maps).
You can use import maps with the `--import-map=<FILE>` CLI flag. You can use import maps with the `--import-map=<FILE>` CLI flag.
Current limitations:
- single import map.
- no fallback URLs.
- Deno does not support `std:` namespace.
- supports only `file:`, `http:` and `https:` schemes.
Example: Example:
**import_map.json** **import_map.json**
@ -37,7 +27,7 @@ console.log(red("hello world"));
Then: Then:
```shell ```shell
$ deno run --import-map=import_map.json --unstable color.ts $ deno run --import-map=import_map.json color.ts
``` ```
To use starting directory for absolute imports: To use starting directory for absolute imports: