mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
parent
36e9e53b37
commit
97d5ef2950
2 changed files with 32 additions and 9 deletions
|
@ -34,9 +34,9 @@ impl fmt::Display for ImportMapError {
|
||||||
|
|
||||||
impl Error for ImportMapError {}
|
impl Error for ImportMapError {}
|
||||||
|
|
||||||
// NOTE: here is difference between deno and reference implementation - deno currently
|
// NOTE: here is difference between deno and reference implementation - Deno
|
||||||
// can't resolve URL with other schemes (eg. data:, about:, blob:)
|
// doesn't resolve URLs outside of the supported schemes.
|
||||||
const SUPPORTED_FETCH_SCHEMES: [&str; 3] = ["http", "https", "file"];
|
const SUPPORTED_FETCH_SCHEMES: [&str; 4] = ["http", "https", "file", "data"];
|
||||||
|
|
||||||
type SpecifierMap = IndexMap<String, Vec<ModuleSpecifier>>;
|
type SpecifierMap = IndexMap<String, Vec<ModuleSpecifier>>;
|
||||||
type ScopesMap = IndexMap<String, SpecifierMap>;
|
type ScopesMap = IndexMap<String, SpecifierMap>;
|
||||||
|
@ -863,9 +863,9 @@ mod tests {
|
||||||
"http://good/": {},
|
"http://good/": {},
|
||||||
"https://good/": {},
|
"https://good/": {},
|
||||||
"file:///good": {},
|
"file:///good": {},
|
||||||
|
"data:good": {},
|
||||||
"about:bad": {},
|
"about:bad": {},
|
||||||
"blob:bad": {},
|
"blob:bad": {},
|
||||||
"data:bad": {},
|
|
||||||
"filesystem:bad": {},
|
"filesystem:bad": {},
|
||||||
"ftp://bad/": {},
|
"ftp://bad/": {},
|
||||||
"import:bad": {},
|
"import:bad": {},
|
||||||
|
@ -880,7 +880,8 @@ mod tests {
|
||||||
assert!(import_map.scopes.contains_key("http://good/"));
|
assert!(import_map.scopes.contains_key("http://good/"));
|
||||||
assert!(import_map.scopes.contains_key("https://good/"));
|
assert!(import_map.scopes.contains_key("https://good/"));
|
||||||
assert!(import_map.scopes.contains_key("file:///good"));
|
assert!(import_map.scopes.contains_key("file:///good"));
|
||||||
assert_eq!(import_map.scopes.len(), 3);
|
assert!(import_map.scopes.contains_key("data:good"));
|
||||||
|
assert_eq!(import_map.scopes.len(), 4);
|
||||||
|
|
||||||
// Should parse absolute URL scope keys, ignoring unparseable ones..
|
// Should parse absolute URL scope keys, ignoring unparseable ones..
|
||||||
let json_map = r#"{
|
let json_map = r#"{
|
||||||
|
@ -994,9 +995,9 @@ mod tests {
|
||||||
"http": "http://good/",
|
"http": "http://good/",
|
||||||
"https": "https://good/",
|
"https": "https://good/",
|
||||||
"file": "file:///good",
|
"file": "file:///good",
|
||||||
|
"data": "data:good",
|
||||||
"about": "about:bad",
|
"about": "about:bad",
|
||||||
"blob": "blob:bad",
|
"blob": "blob:bad",
|
||||||
"data": "data:bad",
|
|
||||||
"filesystem": "filesystem:bad",
|
"filesystem": "filesystem:bad",
|
||||||
"ftp": "ftp://good/",
|
"ftp": "ftp://good/",
|
||||||
"import": "import:bad",
|
"import": "import:bad",
|
||||||
|
@ -1021,10 +1022,13 @@ mod tests {
|
||||||
import_map.imports.get("https").unwrap(),
|
import_map.imports.get("https").unwrap(),
|
||||||
&vec!["https://good/".to_string()]
|
&vec!["https://good/".to_string()]
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
import_map.imports.get("data").unwrap(),
|
||||||
|
&vec!["data:good".to_string()]
|
||||||
|
);
|
||||||
|
|
||||||
assert!(import_map.imports.get("about").unwrap().is_empty());
|
assert!(import_map.imports.get("about").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("blob").unwrap().is_empty());
|
assert!(import_map.imports.get("blob").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("data").unwrap().is_empty());
|
|
||||||
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
|
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("ftp").unwrap().is_empty());
|
assert!(import_map.imports.get("ftp").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("import").unwrap().is_empty());
|
assert!(import_map.imports.get("import").unwrap().is_empty());
|
||||||
|
@ -1041,9 +1045,9 @@ mod tests {
|
||||||
"http": ["http://good/"],
|
"http": ["http://good/"],
|
||||||
"https": ["https://good/"],
|
"https": ["https://good/"],
|
||||||
"file": ["file:///good"],
|
"file": ["file:///good"],
|
||||||
|
"data": ["data:good"],
|
||||||
"about": ["about:bad"],
|
"about": ["about:bad"],
|
||||||
"blob": ["blob:bad"],
|
"blob": ["blob:bad"],
|
||||||
"data": ["data:bad"],
|
|
||||||
"filesystem": ["filesystem:bad"],
|
"filesystem": ["filesystem:bad"],
|
||||||
"ftp": ["ftp://good/"],
|
"ftp": ["ftp://good/"],
|
||||||
"import": ["import:bad"],
|
"import": ["import:bad"],
|
||||||
|
@ -1068,10 +1072,13 @@ mod tests {
|
||||||
import_map.imports.get("https").unwrap(),
|
import_map.imports.get("https").unwrap(),
|
||||||
&vec!["https://good/".to_string()]
|
&vec!["https://good/".to_string()]
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
import_map.imports.get("data").unwrap(),
|
||||||
|
&vec!["data:good".to_string()]
|
||||||
|
);
|
||||||
|
|
||||||
assert!(import_map.imports.get("about").unwrap().is_empty());
|
assert!(import_map.imports.get("about").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("blob").unwrap().is_empty());
|
assert!(import_map.imports.get("blob").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("data").unwrap().is_empty());
|
|
||||||
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
|
assert!(import_map.imports.get("filesystem").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("ftp").unwrap().is_empty());
|
assert!(import_map.imports.get("ftp").unwrap().is_empty());
|
||||||
assert!(import_map.imports.get("import").unwrap().is_empty());
|
assert!(import_map.imports.get("import").unwrap().is_empty());
|
||||||
|
@ -2069,4 +2076,15 @@ mod tests {
|
||||||
"https://example.com/app/none.mjs",
|
"https://example.com/app/none.mjs",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn resolve_data_urls() {
|
||||||
|
let base_url = "https://example.com/app/main.ts";
|
||||||
|
let json_map = r#"{}"#;
|
||||||
|
let import_map = ImportMap::from_json(base_url, json_map).unwrap();
|
||||||
|
assert_resolve(
|
||||||
|
import_map.resolve("data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=", base_url),
|
||||||
|
"data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3577,6 +3577,11 @@ console.log("finish");
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(import_data_url_import_map {
|
||||||
|
args: "run --quiet --reload --unstable --import-map import_maps/import_map.json import_data_url.ts",
|
||||||
|
output: "import_data_url.ts.out",
|
||||||
|
});
|
||||||
|
|
||||||
itest!(import_data_url_imports {
|
itest!(import_data_url_imports {
|
||||||
args: "run --quiet --reload import_data_url_imports.ts",
|
args: "run --quiet --reload import_data_url_imports.ts",
|
||||||
output: "import_data_url_imports.ts.out",
|
output: "import_data_url_imports.ts.out",
|
||||||
|
|
Loading…
Reference in a new issue