From 5fd74bfa1c5ed514c3e19fdb2e8590fe251d3ee6 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 11 May 2023 00:13:45 +0200 Subject: feat(node): add `Module.runMain()` (#19080) This PR adds the missing `Module.runMain()` function which is required for tools like `ts-node`. Fixes #19033 --- cli/tests/node_compat/config.jsonc | 1 + cli/tests/node_compat/test/fixtures/run-main.js | 1 + .../node_compat/test/parallel/test-module-run-main.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 cli/tests/node_compat/test/fixtures/run-main.js create mode 100644 cli/tests/node_compat/test/parallel/test-module-run-main.js (limited to 'cli') diff --git a/cli/tests/node_compat/config.jsonc b/cli/tests/node_compat/config.jsonc index 81463bcaf..87530d4f5 100644 --- a/cli/tests/node_compat/config.jsonc +++ b/cli/tests/node_compat/config.jsonc @@ -366,6 +366,7 @@ "test-http-outgoing-message-inheritance.js", "test-http-outgoing-renderHeaders.js", "test-http-outgoing-settimeout.js", + "test-module-run-main.js", "test-net-access-byteswritten.js", "test-net-better-error-messages-listen-path.js", "test-net-better-error-messages-path.js", diff --git a/cli/tests/node_compat/test/fixtures/run-main.js b/cli/tests/node_compat/test/fixtures/run-main.js new file mode 100644 index 000000000..9a081cbba --- /dev/null +++ b/cli/tests/node_compat/test/fixtures/run-main.js @@ -0,0 +1 @@ +globalThis.foo = 42; diff --git a/cli/tests/node_compat/test/parallel/test-module-run-main.js b/cli/tests/node_compat/test/parallel/test-module-run-main.js new file mode 100644 index 000000000..8e30de267 --- /dev/null +++ b/cli/tests/node_compat/test/parallel/test-module-run-main.js @@ -0,0 +1,15 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +"use strict"; + +const Module = require("module"); +const assert = require("assert/strict"); +const path = require("path"); + +const file = path.join(__dirname, "..", "fixtures", "run-main.js"); +process.argv = [process.argv[0], file]; +Module.runMain(); + +// The required file via `Module.runMain()` sets this global +assert.equal(globalThis.foo, 42); -- cgit v1.2.3