mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
ce75e31625
This commit changes "include_js_files!" macro from "deno_core" in a way that "dir" option doesn't cause specifiers to be rewritten to include it. Example: ``` include_js_files! { dir "js", "hello.js", } ``` The above definition required embedders to use: `import ... from "internal:<ext_name>/js/hello.js"`. But with this change, the "js" directory in which the files are stored is an implementation detail, which for embedders results in: `import ... from "internal:<ext_name>/hello.js"`. The directory the files are stored in, is an implementation detail and in some cases might result in a significant size difference for the snapshot. As an example, in "deno_node" extension, we store the source code in "polyfills" directory; which resulted in each specifier to look like "internal:deno_node/polyfills/<module_name>", but with this change it's "internal:deno_node/<module_name>". Given that "deno_node" has over 100 files, many of them having several import specifiers to the same extension, this change removes 10 characters from each import specifier.
202 lines
4.9 KiB
Rust
202 lines
4.9 KiB
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
pub fn find_builtin_node_module(
|
|
module_name: &str,
|
|
) -> Option<&NodeModulePolyfill> {
|
|
SUPPORTED_BUILTIN_NODE_MODULES
|
|
.iter()
|
|
.find(|m| m.name == module_name)
|
|
}
|
|
|
|
pub fn is_builtin_node_module(module_name: &str) -> bool {
|
|
find_builtin_node_module(module_name).is_some()
|
|
}
|
|
|
|
pub struct NodeModulePolyfill {
|
|
/// Name of the module like "assert" or "timers/promises"
|
|
pub name: &'static str,
|
|
pub specifier: &'static str,
|
|
}
|
|
|
|
pub static SUPPORTED_BUILTIN_NODE_MODULES: &[NodeModulePolyfill] = &[
|
|
NodeModulePolyfill {
|
|
name: "assert",
|
|
specifier: "internal:deno_node/assert.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "assert/strict",
|
|
specifier: "internal:deno_node/assert/strict.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "async_hooks",
|
|
specifier: "internal:deno_node/async_hooks.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "buffer",
|
|
specifier: "internal:deno_node/buffer.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "child_process",
|
|
specifier: "internal:deno_node/child_process.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "cluster",
|
|
specifier: "internal:deno_node/cluster.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "console",
|
|
specifier: "internal:deno_node/console.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "constants",
|
|
specifier: "internal:deno_node/constants.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "crypto",
|
|
specifier: "internal:deno_node/crypto.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "dgram",
|
|
specifier: "internal:deno_node/dgram.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "dns",
|
|
specifier: "internal:deno_node/dns.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "dns/promises",
|
|
specifier: "internal:deno_node/dns/promises.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "domain",
|
|
specifier: "internal:deno_node/domain.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "events",
|
|
specifier: "internal:deno_node/events.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "fs",
|
|
specifier: "internal:deno_node/fs.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "fs/promises",
|
|
specifier: "internal:deno_node/fs/promises.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "http",
|
|
specifier: "internal:deno_node/http.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "https",
|
|
specifier: "internal:deno_node/https.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "module",
|
|
specifier: "internal:deno_node_loading/module_es_shim.js",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "net",
|
|
specifier: "internal:deno_node/net.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "os",
|
|
specifier: "internal:deno_node/os.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "path",
|
|
specifier: "internal:deno_node/path.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "path/posix",
|
|
specifier: "internal:deno_node/path/posix.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "path/win32",
|
|
specifier: "internal:deno_node/path/win32.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "perf_hooks",
|
|
specifier: "internal:deno_node/perf_hooks.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "process",
|
|
specifier: "internal:deno_node/process.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "querystring",
|
|
specifier: "internal:deno_node/querystring.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "readline",
|
|
specifier: "internal:deno_node/readline.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "stream",
|
|
specifier: "internal:deno_node/stream.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "stream/consumers",
|
|
specifier: "internal:deno_node/stream/consumers.mjs",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "stream/promises",
|
|
specifier: "internal:deno_node/stream/promises.mjs",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "stream/web",
|
|
specifier: "internal:deno_node/stream/web.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "string_decoder",
|
|
specifier: "internal:deno_node/string_decoder.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "sys",
|
|
specifier: "internal:deno_node/sys.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "timers",
|
|
specifier: "internal:deno_node/timers.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "timers/promises",
|
|
specifier: "internal:deno_node/timers/promises.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "tls",
|
|
specifier: "internal:deno_node/tls.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "tty",
|
|
specifier: "internal:deno_node/tty.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "url",
|
|
specifier: "internal:deno_node/url.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "util",
|
|
specifier: "internal:deno_node/util.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "util/types",
|
|
specifier: "internal:deno_node/util/types.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "v8",
|
|
specifier: "internal:deno_node/v8.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "vm",
|
|
specifier: "internal:deno_node/vm.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "worker_threads",
|
|
specifier: "internal:deno_node/worker_threads.ts",
|
|
},
|
|
NodeModulePolyfill {
|
|
name: "zlib",
|
|
specifier: "internal:deno_node/zlib.ts",
|
|
},
|
|
];
|