mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
feat(compat): add support for node: prefixed built-ins (#12337)
Adds support for "node:" prefix for Node built-ins in "--compat" mode. As per https://nodejs.org/api/esm.html#esm_node_imports
This commit is contained in:
parent
3faf75aa88
commit
37a24c7bdf
3 changed files with 14 additions and 1 deletions
|
@ -53,7 +53,12 @@ pub fn get_mapped_node_builtins() -> HashMap<String, String> {
|
|||
for module in SUPPORTED_MODULES {
|
||||
// TODO(bartlomieju): this is unversioned, and should be fixed to use latest stable?
|
||||
let module_url = format!("https://deno.land/std/node/{}.ts", module);
|
||||
mappings.insert(module.to_string(), module_url);
|
||||
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);
|
||||
}
|
||||
|
||||
mappings
|
||||
|
|
|
@ -7,6 +7,11 @@ itest!(fs_promises {
|
|||
output: "compat/fs_promises.out",
|
||||
});
|
||||
|
||||
itest!(node_prefix_fs_promises {
|
||||
args: "run --compat --unstable -A compat/node_fs_promises.js",
|
||||
output: "compat/fs_promises.out",
|
||||
});
|
||||
|
||||
itest!(existing_import_map {
|
||||
args: "run --compat --import-map compat/existing_import_map.json compat/fs_promises.js",
|
||||
output: "compat/existing_import_map.out",
|
||||
|
|
3
cli/tests/testdata/compat/node_fs_promises.js
vendored
Normal file
3
cli/tests/testdata/compat/node_fs_promises.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import fs from "node:fs/promises";
|
||||
const data = await fs.readFile("compat/test.txt", "utf-8");
|
||||
console.log(data);
|
Loading…
Reference in a new issue