aboutsummaryrefslogtreecommitdiff
path: root/src/linker.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-11 00:56:35 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-05-11 00:56:35 -0700
commit3c87fbfd37f36a409c704ea3f5e2701eb0126c44 (patch)
tree0f89aa932a7a15b12cf239895194990c6d898cff /src/linker.zig
parentfd00950852c3f3bf49d9ce8f6a175753ad0167fd (diff)
downloadbun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.gz
bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.tar.zst
bun-3c87fbfd37f36a409c704ea3f5e2701eb0126c44.zip
[bun.js] Implement `import.meta.require`
This allows synchronous dynamic loading of `.node`, `.json`, and `.toml` files. It is not a CommonJS require, but it can be used that way so long as the content is not JavaScript.
Diffstat (limited to 'src/linker.zig')
-rw-r--r--src/linker.zig29
1 files changed, 3 insertions, 26 deletions
diff --git a/src/linker.zig b/src/linker.zig
index 099cf5e72..f2698b622 100644
--- a/src/linker.zig
+++ b/src/linker.zig
@@ -36,6 +36,7 @@ const ResolveQueue = _bundler.ResolveQueue;
const ResolverType = Resolver.Resolver;
const Runtime = @import("./runtime.zig").Runtime;
const URL = @import("url.zig").URL;
+const JSC = @import("javascript_core");
pub const CSSResolveError = error{ResolveError};
pub const OnImportCallback = fn (resolve_result: *const Resolver.Result, import_record: *ImportRecord, origin: URL) void;
@@ -261,26 +262,8 @@ pub const Linker = struct {
}
if (comptime is_bun) {
- if (import_record.path.text.len > 5 and strings.eqlComptime(import_record.path.text[0.."node:".len], "node:")) {
- const is_fs = strings.eqlComptime(import_record.path.text[5..], "fs");
-
- if (is_fs) {
- import_record.path.text = "node:fs";
- externals.append(record_index) catch unreachable;
- continue;
- }
-
- const is_path = strings.eqlComptime(import_record.path.text[5..], "path");
-
- if (is_path) {
- import_record.path.text = "node:path";
- externals.append(record_index) catch unreachable;
- continue;
- }
- }
-
- if (strings.eqlComptime(import_record.path.text, "fs")) {
- import_record.path.text = "node:fs";
+ if (JSC.HardcodedModule.LinkerMap.get(import_record.path.text)) |replacement| {
+ import_record.path.text = replacement;
externals.append(record_index) catch unreachable;
continue;
}
@@ -290,12 +273,6 @@ pub const Linker = struct {
continue;
}
- if (strings.eqlComptime(import_record.path.text, "path")) {
- import_record.path.text = "node:path";
- externals.append(record_index) catch unreachable;
- continue;
- }
-
// if (strings.eqlComptime(import_record.path.text, "process")) {
// import_record.path.text = "node:process";
// externals.append(record_index) catch unreachable;