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: https://github.com/nodejs/node/issues/4661 PR-URL: https://github.com/nodejs/node/pull/4696 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
8d0ca10752
commit
ff64a4c395
@ -140,6 +140,7 @@
|
||||
}
|
||||
|
||||
} else {
|
||||
startup.preloadModules();
|
||||
// If -i or --interactive were passed, or stdin is a TTY.
|
||||
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
|
||||
// REPL
|
||||
|
1
test/fixtures/define-global.js
vendored
Normal file
1
test/fixtures/define-global.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
global.a = 'test';
|
@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
require('../common');
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const child_process = require('child_process');
|
||||
@ -21,6 +21,7 @@ var fixture = function(name) {
|
||||
var fixtureA = fixture('printA.js');
|
||||
var fixtureB = fixture('printB.js');
|
||||
var fixtureC = fixture('printC.js');
|
||||
const fixtureD = fixture('define-global.js');
|
||||
var fixtureThrows = fixture('throws_error4.js');
|
||||
|
||||
// test preloading a single module works
|
||||
@ -73,6 +74,18 @@ child_process.exec(nodeBinary + ' '
|
||||
assert.equal(stdout, 'A\nB\nhello\n');
|
||||
});
|
||||
|
||||
// test that preload works with -i
|
||||
const interactive = child_process.exec(nodeBinary + ' '
|
||||
+ preloadOption([fixtureD])
|
||||
+ '-i',
|
||||
common.mustCall(function(err, stdout, stderr) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(stdout, `> 'test'\n> `);
|
||||
}));
|
||||
|
||||
interactive.stdin.write('a\n');
|
||||
interactive.stdin.write('process.exit()\n');
|
||||
|
||||
child_process.exec(nodeBinary + ' '
|
||||
+ '--require ' + fixture('cluster-preload.js') + ' '
|
||||
+ fixture('cluster-preload-test.js'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user