Skip to content

Commit 88b4d00

Browse files
addaleaxtargos
authored andcommitted
lib: restore global.module after --eval code is run
PR-URL: #27587 Fixes: #27575 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 688a0bd commit 88b4d00

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/internal/process/execution.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function evalScript(name, body, breakFirstLine, printResult) {
5555
const { kVmBreakFirstLineSymbol } = require('internal/util');
5656

5757
const cwd = tryGetCwd();
58+
const origModule = global.module; // Set e.g. when called from the REPL.
5859

5960
const module = new CJSModule(name);
6061
module.filename = path.join(cwd, name);
@@ -79,6 +80,9 @@ function evalScript(name, body, breakFirstLine, printResult) {
7980
const { kStdout, print } = require('internal/util/print');
8081
print(kStdout, result);
8182
}
83+
84+
if (origModule !== undefined)
85+
global.module = origModule;
8286
}
8387

8488
const exceptionHandlerState = { captureFn: null };

0 commit comments

Comments
 (0)