Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ff64a4c

Browse filesBrowse files
committed
node: allow preload modules with -i
This gives us the ability to preload when using the node repl. This can be useful for doing things like creating aliases. Fixes: #4661 PR-URL: #4696 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8d0ca10 commit ff64a4c
Copy full SHA for ff64a4c

File tree

Expand file treeCollapse file tree

3 files changed

+16
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+16
-1
lines changed
Open diff view settings
Collapse file

‎src/node.js‎

Copy file name to clipboardExpand all lines: src/node.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
}
141141

142142
} else {
143+
startup.preloadModules();
143144
// If -i or --interactive were passed, or stdin is a TTY.
144145
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
145146
// REPL
Collapse file

‎test/fixtures/define-global.js‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.a = 'test';
Collapse file

‎test/parallel/test-preload.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-preload.js
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const path = require('path');
55
const child_process = require('child_process');
@@ -21,6 +21,7 @@ var fixture = function(name) {
2121
var fixtureA = fixture('printA.js');
2222
var fixtureB = fixture('printB.js');
2323
var fixtureC = fixture('printC.js');
24+
const fixtureD = fixture('define-global.js');
2425
var fixtureThrows = fixture('throws_error4.js');
2526

2627
// test preloading a single module works
@@ -73,6 +74,18 @@ child_process.exec(nodeBinary + ' '
7374
assert.equal(stdout, 'A\nB\nhello\n');
7475
});
7576

77+
// test that preload works with -i
78+
const interactive = child_process.exec(nodeBinary + ' '
79+
+ preloadOption([fixtureD])
80+
+ '-i',
81+
common.mustCall(function(err, stdout, stderr) {
82+
assert.ifError(err);
83+
assert.strictEqual(stdout, `> 'test'\n> `);
84+
}));
85+
86+
interactive.stdin.write('a\n');
87+
interactive.stdin.write('process.exit()\n');
88+
7689
child_process.exec(nodeBinary + ' '
7790
+ '--require ' + fixture('cluster-preload.js') + ' '
7891
+ fixture('cluster-preload-test.js'),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.