Skip to content

Commit

Permalink
Fix require("console") oven-sh#3820 (oven-sh#4073)
Browse files Browse the repository at this point in the history
* Fix oven-sh#3820

* Add Module (oven-sh#4074)
  • Loading branch information
paperdave authored and trnxdev committed Aug 9, 2023
1 parent b902693 commit acfd36a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,7 @@ pub const HardcodedModule = enum {
.{ "node:child_process", .{ .path = "node:child_process" } },
.{ "node:constants", .{ .path = "node:constants" } },
.{ "node:console", .{ .path = "node:console" } },
.{ "console", .{ .path = "node:console" } },
.{ "node:querystring", .{ .path = "node:querystring" } },
.{ "querystring", .{ .path = "node:querystring" } },
.{ "node:domain", .{ .path = "node:domain" } },
Expand Down
6 changes: 4 additions & 2 deletions src/bun.js/modules/NodeModuleModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ DEFINE_NATIVE_MODULE(NodeModule) {
exportNames.append(name);
exportValues.append(value);
};
exportNames.reserveCapacity(14);
exportValues.ensureCapacity(14);
exportNames.reserveCapacity(15);
exportValues.ensureCapacity(15);
exportNames.append(vm.propertyNames->defaultKeyword);
exportValues.append(defaultObject);

put(Identifier::fromString(vm, "Module"_s), defaultObject);

putNativeFn(Identifier::fromString(vm, "createRequire"_s),
jsFunctionNodeModuleCreateRequire);
putNativeFn(Identifier::fromString(vm, "paths"_s),
Expand Down
4 changes: 4 additions & 0 deletions test/js/node/module/node-module-module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ test("Module exists", () => {
expect(Module).toBeDefined();
});

test("module.Module exists", () => {
expect(Module.Module === Module).toBeTrue();
});

test("_nodeModulePaths() works", () => {
expect(() => {
_nodeModulePaths();
Expand Down

0 comments on commit acfd36a

Please sign in to comment.