aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/module_loader.zig13
-rw-r--r--src/options.zig4
-rw-r--r--src/resolver/resolver.zig30
3 files changed, 33 insertions, 14 deletions
diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig
index b7c5ea53e..be10b9722 100644
--- a/src/bun.js/module_loader.zig
+++ b/src/bun.js/module_loader.zig
@@ -2456,8 +2456,6 @@ pub const HardcodedModule = enum {
// It implements the same interface
.{ "sys", .{ .path = "node:util" } },
.{ "node:sys", .{ .path = "node:util" } },
- // .{ "inspector/promises", .{ .path = "node:inspector" } },
- .{ "node:inspector/promises", .{ .path = "node:inspector" } },
// These are returned in builtinModules, but probably not many packages use them
// so we will just alias them.
@@ -2501,9 +2499,18 @@ pub const HardcodedModule = enum {
.{ "utf-8-validate", .{ .path = "utf-8-validate" } },
.{ "ws", .{ .path = "ws" } },
.{ "ws/lib/websocket", .{ .path = "ws" } },
+
+ .{ "inspector/promises", .{ .path = "node:inspector" } },
+ .{ "node:inspector/promises", .{ .path = "node:inspector" } },
+ };
+
+ const node_alias_kvs = .{
+ .{ "inspector/promises", .{ .path = "node:inspector/promises" } },
+ .{ "node:inspector/promises", .{ .path = "node:inspector/promises" } },
+ .{ "node:test", .{ .path = "node:test" } },
};
- const NodeAliases = bun.ComptimeStringMap(Alias, common_alias_kvs);
+ const NodeAliases = bun.ComptimeStringMap(Alias, common_alias_kvs ++ node_alias_kvs);
const BunAliases = bun.ComptimeStringMap(Alias, common_alias_kvs ++ bun_extra_alias_kvs);
pub fn has(name: []const u8, target: options.Target) bool {
diff --git a/src/options.zig b/src/options.zig
index 51ee27dab..fec09405c 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -1417,7 +1417,7 @@ pub const BundleOptions = struct {
defines_loaded: bool = false,
env: Env = Env{},
transform_options: Api.TransformOptions,
- polyfill_node_globals: bool = true,
+ polyfill_node_globals: bool = false,
transform_only: bool = false,
rewrite_jest_for_tests: bool = false,
@@ -1844,7 +1844,7 @@ pub const BundleOptions = struct {
opts.output_dir = try fs.getFdPath(opts.output_dir_handle.?.fd);
}
- opts.polyfill_node_globals = opts.target != .node;
+ opts.polyfill_node_globals = opts.target == .browser;
Analytics.Features.framework = Analytics.Features.framework or opts.framework != null;
Analytics.Features.filesystem_router = Analytics.Features.filesystem_router or opts.routes.routes_enabled;
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 41b329734..2730daf42 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -1269,16 +1269,28 @@ pub const Resolver = struct {
result.package_json = @as(*PackageJSON, @ptrFromInt(@intFromPtr(fallback_module.package_json)));
result.is_from_node_modules = true;
return .{ .success = result };
- // "node:*
- // "fs"
- // "fs/*"
- // These are disabled!
- } else if (had_node_prefix and !JSC.HardcodedModule.Aliases.has(import_path_without_node_prefix, r.opts.target)) {
- return .{ .not_found = {} };
- } else if (had_node_prefix or
- (strings.hasPrefixComptime(import_path_without_node_prefix, "fs") and
+ }
+
+ if (had_node_prefix) {
+ // Module resolution fails automatically for unknown node builtins
+ if (!bun.JSC.HardcodedModule.Aliases.has(import_path_without_node_prefix, .node)) {
+ return .{ .not_found = {} };
+ }
+
+ // Valid node:* modules becomes {} in the output
+ result.path_pair.primary.namespace = "node";
+ result.path_pair.primary.text = import_path_without_node_prefix;
+ result.path_pair.primary.name = Fs.PathName.init(import_path_without_node_prefix);
+ result.module_type = .cjs;
+ result.path_pair.primary.is_disabled = true;
+ result.is_from_node_modules = true;
+ return .{ .success = result };
+ }
+
+ // Always mark "fs" as disabled, matching Webpack v4 behavior
+ if (strings.hasPrefixComptime(import_path_without_node_prefix, "fs") and
(import_path_without_node_prefix.len == 2 or
- import_path_without_node_prefix[2] == '/')))
+ import_path_without_node_prefix[2] == '/'))
{
result.path_pair.primary.namespace = "node";
result.path_pair.primary.text = import_path_without_node_prefix;