2023-02-10 10:26:39 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2023-04-21 21:02:46 -04:00
|
|
|
use deno_core::error::generic_error;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::url::Url;
|
|
|
|
use deno_core::ModuleSpecifier;
|
|
|
|
|
|
|
|
// TODO(bartlomieju): seems super wasteful to parse the specifier each time
|
|
|
|
pub fn resolve_builtin_node_module(module_name: &str) -> Result<Url, AnyError> {
|
|
|
|
if let Some(module) = find_builtin_node_module(module_name) {
|
|
|
|
return Ok(ModuleSpecifier::parse(module.specifier).unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(generic_error(format!(
|
|
|
|
"Unknown built-in \"node:\" module: {module_name}"
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_builtin_node_module(module_name: &str) -> Option<&NodeModulePolyfill> {
|
2023-02-10 10:26:39 -05:00
|
|
|
SUPPORTED_BUILTIN_NODE_MODULES
|
|
|
|
.iter()
|
2023-02-22 14:15:25 -05:00
|
|
|
.find(|m| m.name == module_name)
|
2023-02-10 10:26:39 -05:00
|
|
|
}
|
|
|
|
|
2023-02-22 14:15:25 -05:00
|
|
|
pub fn is_builtin_node_module(module_name: &str) -> bool {
|
|
|
|
find_builtin_node_module(module_name).is_some()
|
2023-02-10 10:26:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct NodeModulePolyfill {
|
|
|
|
/// Name of the module like "assert" or "timers/promises"
|
|
|
|
pub name: &'static str,
|
2023-02-15 13:44:52 -05:00
|
|
|
pub specifier: &'static str,
|
2023-02-10 10:26:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub static SUPPORTED_BUILTIN_NODE_MODULES: &[NodeModulePolyfill] = &[
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "assert",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/assert.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "assert/strict",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/assert/strict.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "async_hooks",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/async_hooks.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "buffer",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/buffer.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "child_process",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/child_process.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "cluster",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/cluster.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "console",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/console.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "constants",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/constants.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "crypto",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/crypto.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "dgram",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/dgram.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "dns",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/dns.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "dns/promises",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/dns/promises.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "domain",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/domain.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "events",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/events.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "fs",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/fs.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "fs/promises",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/fs/promises.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "http",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/http.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "https",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/https.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "module",
|
2023-03-20 14:05:13 -04:00
|
|
|
specifier: "ext:deno_node/01_require.js",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "net",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/net.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "os",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/os.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "path",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/path.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "path/posix",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/path/posix.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "path/win32",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/path/win32.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "perf_hooks",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/perf_hooks.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "process",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/process.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "querystring",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/querystring.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "readline",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/readline.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "stream",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/stream.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "stream/consumers",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/stream/consumers.mjs",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "stream/promises",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/stream/promises.mjs",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "stream/web",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/stream/web.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "string_decoder",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/string_decoder.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "sys",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/sys.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "timers",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/timers.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "timers/promises",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/timers/promises.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "tls",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/tls.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "tty",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/tty.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "url",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/url.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "util",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/util.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "util/types",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/util/types.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "v8",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/v8.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "vm",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/vm.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "worker_threads",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/worker_threads.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
NodeModulePolyfill {
|
|
|
|
name: "zlib",
|
2023-03-08 06:44:54 -05:00
|
|
|
specifier: "ext:deno_node/zlib.ts",
|
2023-02-10 10:26:39 -05:00
|
|
|
},
|
|
|
|
];
|