2021-10-04 19:35:55 -04:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2021-10-06 13:07:04 -04:00
|
|
|
use deno_core::url::Url;
|
2021-10-04 19:35:55 -04:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2021-10-11 17:14:46 -04:00
|
|
|
// TODO(bartlomieju): this needs to be bumped manually for
|
|
|
|
// each release, a better mechanism is preferable, but it's a quick and dirty
|
|
|
|
// solution to avoid printing `X-Deno-Warning` headers when the compat layer is
|
|
|
|
// downloaded
|
2021-10-12 13:57:07 -04:00
|
|
|
static STD_URL: &str = "https://deno.land/std@0.111.0/";
|
2021-10-10 17:26:22 -04:00
|
|
|
static GLOBAL_MODULE: &str = "global.ts";
|
2021-10-06 13:07:04 -04:00
|
|
|
|
2021-10-04 19:35:55 -04:00
|
|
|
static SUPPORTED_MODULES: &[&str] = &[
|
|
|
|
"assert",
|
|
|
|
"assert/strict",
|
|
|
|
"async_hooks",
|
|
|
|
"buffer",
|
|
|
|
"child_process",
|
|
|
|
"cluster",
|
|
|
|
"console",
|
|
|
|
"constants",
|
|
|
|
"crypto",
|
|
|
|
"dgram",
|
|
|
|
"dns",
|
|
|
|
"domain",
|
|
|
|
"events",
|
|
|
|
"fs",
|
|
|
|
"fs/promises",
|
|
|
|
"http",
|
|
|
|
"https",
|
|
|
|
"module",
|
|
|
|
"net",
|
|
|
|
"os",
|
|
|
|
"path",
|
|
|
|
"path/posix",
|
|
|
|
"path/win32",
|
|
|
|
"perf_hooks",
|
|
|
|
"process",
|
|
|
|
"querystring",
|
|
|
|
"readline",
|
|
|
|
"stream",
|
|
|
|
"stream/promises",
|
|
|
|
"stream/web",
|
|
|
|
"string_decoder",
|
|
|
|
"sys",
|
|
|
|
"timers",
|
|
|
|
"timers/promises",
|
|
|
|
"tls",
|
|
|
|
"tty",
|
|
|
|
"url",
|
|
|
|
"util",
|
|
|
|
"util/types",
|
|
|
|
"v8",
|
|
|
|
"vm",
|
|
|
|
"zlib",
|
|
|
|
];
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
lazy_static::lazy_static! {
|
2021-10-11 17:14:46 -04:00
|
|
|
static ref GLOBAL_URL_STR: String = format!("{}node/{}", STD_URL, GLOBAL_MODULE);
|
2021-10-10 17:26:22 -04:00
|
|
|
pub(crate) static ref GLOBAL_URL: Url = Url::parse(&GLOBAL_URL_STR).unwrap();
|
|
|
|
static ref COMPAT_IMPORT_URL: Url = Url::parse("flags:compat").unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Provide imports into a module graph when the compat flag is true.
|
|
|
|
pub(crate) fn get_node_imports() -> Vec<(Url, Vec<String>)> {
|
|
|
|
vec![(COMPAT_IMPORT_URL.clone(), vec![GLOBAL_URL_STR.clone()])]
|
2021-10-06 13:07:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a map that can be used to update import map.
|
|
|
|
///
|
|
|
|
/// Keys are built-in Node modules (and built-ins prefixed with "node:"), while
|
|
|
|
/// values are URLs pointing to relevant files in deno.land/std/node/ directory.
|
2021-10-04 19:35:55 -04:00
|
|
|
pub fn get_mapped_node_builtins() -> HashMap<String, String> {
|
|
|
|
let mut mappings = HashMap::new();
|
|
|
|
|
|
|
|
for module in SUPPORTED_MODULES {
|
|
|
|
// TODO(bartlomieju): this is unversioned, and should be fixed to use latest stable?
|
2021-10-11 17:14:46 -04:00
|
|
|
let module_url = format!("{}node/{}.ts", STD_URL, module);
|
2021-10-05 19:25:13 -04:00
|
|
|
mappings.insert(module.to_string(), module_url.clone());
|
|
|
|
|
|
|
|
// Support for `node:<module_name>`
|
|
|
|
// https://nodejs.org/api/esm.html#esm_node_imports
|
|
|
|
let node_prefixed = format!("node:{}", module);
|
|
|
|
mappings.insert(node_prefixed, module_url);
|
2021-10-04 19:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
mappings
|
|
|
|
}
|