From f1d3a170430501b4fab1a2d2abb5d77528251c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 5 Oct 2021 01:35:55 +0200 Subject: feat: add --compat flag to provide built-in Node modules (#12293) This commit adds "--compat" flag. When the flag is passed a set of mappings for built-in Node modules is injected into the import map. If user doesn't explicitly provide an import map (using "--import-map" flag) then a map is created on the fly. If there are already existing mappings in import map that would clash with built-in Node modules a set of diagnostics is printed to the terminal with suggestions how to proceed. --- cli/compat.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 cli/compat.rs (limited to 'cli/compat.rs') diff --git a/cli/compat.rs b/cli/compat.rs new file mode 100644 index 000000000..a3d16538d --- /dev/null +++ b/cli/compat.rs @@ -0,0 +1,60 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +use std::collections::HashMap; + +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", +]; + +pub fn get_mapped_node_builtins() -> HashMap { + let mut mappings = HashMap::new(); + + 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 +} -- cgit v1.2.3