mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
feat(node): add Module.runMain()
(#19080)
This PR adds the missing `Module.runMain()` function which is required for tools like `ts-node`. Fixes #19033
This commit is contained in:
parent
e72485fb17
commit
5fd74bfa1c
4 changed files with 22 additions and 0 deletions
|
@ -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",
|
||||
|
|
1
cli/tests/node_compat/test/fixtures/run-main.js
vendored
Normal file
1
cli/tests/node_compat/test/fixtures/run-main.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
globalThis.foo = 42;
|
15
cli/tests/node_compat/test/parallel/test-module-run-main.js
Normal file
15
cli/tests/node_compat/test/parallel/test-module-run-main.js
Normal file
|
@ -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);
|
|
@ -1108,6 +1108,11 @@ Module.syncBuiltinESMExports = function syncBuiltinESMExports() {
|
|||
throw new Error("not implemented");
|
||||
};
|
||||
|
||||
// Mostly used by tools like ts-node.
|
||||
Module.runMain = function () {
|
||||
Module._load(process.argv[1], null, true);
|
||||
};
|
||||
|
||||
Module.Module = Module;
|
||||
|
||||
nativeModuleExports.module = Module;
|
||||
|
|
Loading…
Reference in a new issue