1
0
Fork 0
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:
Marvin Hagemeister 2023-05-11 00:13:45 +02:00 committed by GitHub
parent e72485fb17
commit 5fd74bfa1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

View file

@ -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",

View file

@ -0,0 +1 @@
globalThis.foo = 42;

View 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);

View file

@ -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;