1
0
Fork 0
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:
Bartek Iwańczuk 2021-10-06 01:25:13 +02:00 committed by GitHub
parent 3faf75aa88
commit 37a24c7bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -53,7 +53,12 @@ pub fn get_mapped_node_builtins() -> HashMap<String, String> {
for module in SUPPORTED_MODULES { for module in SUPPORTED_MODULES {
// TODO(bartlomieju): this is unversioned, and should be fixed to use latest stable? // TODO(bartlomieju): this is unversioned, and should be fixed to use latest stable?
let module_url = format!("https://deno.land/std/node/{}.ts", module); 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 mappings

View file

@ -7,6 +7,11 @@ itest!(fs_promises {
output: "compat/fs_promises.out", 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 { itest!(existing_import_map {
args: "run --compat --import-map compat/existing_import_map.json compat/fs_promises.js", args: "run --compat --import-map compat/existing_import_map.json compat/fs_promises.js",
output: "compat/existing_import_map.out", output: "compat/existing_import_map.out",

View file

@ -0,0 +1,3 @@
import fs from "node:fs/promises";
const data = await fs.readFile("compat/test.txt", "utf-8");
console.log(data);