Skip to content

Commit

Permalink
fix(node): assert/strict, fs/promises, perf_hooks modules could not b…
Browse files Browse the repository at this point in the history
…e required (#1107)
  • Loading branch information
uki00a authored Aug 7, 2021
1 parent 7348d13 commit ba773ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import "./global.ts";

import nodeAssert from "./assert.ts";
import nodeAssertStrict from "./assert/strict.ts";
import nodeBuffer from "./buffer.ts";
import nodeCrypto from "./crypto.ts";
import nodeConsole from "./console.ts";
import nodeConstants from "./constants.ts";
import nodeChildProcess from "./child_process.ts";
import nodeEvents from "./events.ts";
import nodeFS from "./fs.ts";
import nodeFSPromises from "./fs/promises.ts";
import nodeOs from "./os.ts";
import nodePath from "./path.ts";
import nodePerfHooks from "./perf_hooks.ts";
import nodeQueryString from "./querystring.ts";
import nodeStream from "./stream.ts";
import nodeStringDecoder from "./string_decoder.ts";
Expand Down Expand Up @@ -618,6 +621,10 @@ function createNativeModule(id: string, exports: any): Module {
}

nativeModulePolyfill.set("assert", createNativeModule("assert", nodeAssert));
nativeModulePolyfill.set(
"assert/strict",
createNativeModule("assert/strict", nodeAssertStrict),
);
nativeModulePolyfill.set("buffer", createNativeModule("buffer", nodeBuffer));
nativeModulePolyfill.set(
"constants",
Expand All @@ -633,9 +640,17 @@ nativeModulePolyfill.set(
createNativeModule("events", nodeEvents),
);
nativeModulePolyfill.set("fs", createNativeModule("fs", nodeFS));
nativeModulePolyfill.set(
"fs/promises",
createNativeModule("fs/promises", nodeFSPromises),
);
nativeModulePolyfill.set("module", createNativeModule("module", Module));
nativeModulePolyfill.set("os", createNativeModule("os", nodeOs));
nativeModulePolyfill.set("path", createNativeModule("path", nodePath));
nativeModulePolyfill.set(
"perf_hooks",
createNativeModule("perf_hooks", nodePerfHooks),
);
nativeModulePolyfill.set(
"querystring",
createNativeModule("querystring", nodeQueryString),
Expand Down
6 changes: 4 additions & 2 deletions node/module_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ Deno.test("requireModuleWithConditionalExports", () => {
Deno.test("requireNodeJsNativeModules", () => {
// Checks these exist and don't throw.
require("assert");
require("assert/strict");
require("buffer");
require("child_process");
require("console");
require("constants");
require("crypto");
require("events");
require("fs");
require("fs/promises");
require("module");
require("os");
require("path");
require("perf_hooks");
require("querystring");
require("stream");
require("string_decoder");
Expand All @@ -105,14 +109,12 @@ Deno.test("requireNodeJsNativeModules", () => {

// TODO(kt3k): add these modules when implemented
// require("cluster");
// require("console");
// require("dgram");
// require("dns");
// require("http");
// require("http2");
// require("https");
// require("net");
// require("perf_hooks");
// require("readline");
// require("repl");
// require("sys");
Expand Down

0 comments on commit ba773ee

Please sign in to comment.