repl: check for NODE_REPL_EXTERNAL_MODULE
PR-URL: https://github.com/nodejs/node/pull/29778 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
parent
06f6d662f6
commit
c0305af2c4
@ -1121,6 +1121,14 @@ Path to the file used to store the persistent REPL history. The default path is
|
|||||||
`~/.node_repl_history`, which is overridden by this variable. Setting the value
|
`~/.node_repl_history`, which is overridden by this variable. Setting the value
|
||||||
to an empty string (`''` or `' '`) disables persistent REPL history.
|
to an empty string (`''` or `' '`) disables persistent REPL history.
|
||||||
|
|
||||||
|
### `NODE_REPL_EXTERNAL_MODULE=file`
|
||||||
|
<!-- YAML
|
||||||
|
added: REPLACEME
|
||||||
|
-->
|
||||||
|
|
||||||
|
Path to a Node.js module which will be loaded in place of the built-in REPL.
|
||||||
|
Overriding this value to an empty string (`''`) will use the built-in REPL.
|
||||||
|
|
||||||
### `NODE_TLS_REJECT_UNAUTHORIZED=value`
|
### `NODE_TLS_REJECT_UNAUTHORIZED=value`
|
||||||
|
|
||||||
If `value` equals `'0'`, certificate validation is disabled for TLS connections.
|
If `value` equals `'0'`, certificate validation is disabled for TLS connections.
|
||||||
|
@ -19,19 +19,24 @@ prepareMainThreadExecution();
|
|||||||
|
|
||||||
markBootstrapComplete();
|
markBootstrapComplete();
|
||||||
|
|
||||||
// --input-type flag not supported in REPL
|
if (process.env.NODE_REPL_EXTERNAL_MODULE) {
|
||||||
if (getOptionValue('--input-type')) {
|
require('internal/modules/cjs/loader')
|
||||||
|
.Module
|
||||||
|
._load(process.env.NODE_REPL_EXTERNAL_MODULE, undefined, true);
|
||||||
|
} else {
|
||||||
|
// --input-type flag not supported in REPL
|
||||||
|
if (getOptionValue('--input-type')) {
|
||||||
// If we can't write to stderr, we'd like to make this a noop,
|
// If we can't write to stderr, we'd like to make this a noop,
|
||||||
// so use console.error.
|
// so use console.error.
|
||||||
console.error('Cannot specify --input-type for REPL');
|
console.error('Cannot specify --input-type for REPL');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Welcome to Node.js ${process.version}.\n` +
|
console.log(`Welcome to Node.js ${process.version}.\n` +
|
||||||
'Type ".help" for more information.');
|
'Type ".help" for more information.');
|
||||||
|
|
||||||
const cliRepl = require('internal/repl');
|
const cliRepl = require('internal/repl');
|
||||||
cliRepl.createInternalRepl(process.env, (err, repl) => {
|
cliRepl.createInternalRepl(process.env, (err, repl) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -44,13 +49,14 @@ cliRepl.createInternalRepl(process.env, (err, repl) => {
|
|||||||
}
|
}
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
|
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
|
||||||
// evaluate the code in the current context.
|
// evaluate the code in the current context.
|
||||||
if (getOptionValue('[has_eval_string]')) {
|
if (getOptionValue('[has_eval_string]')) {
|
||||||
evalScript('[eval]',
|
evalScript('[eval]',
|
||||||
getOptionValue('--eval'),
|
getOptionValue('--eval'),
|
||||||
getOptionValue('--inspect-brk'),
|
getOptionValue('--inspect-brk'),
|
||||||
getOptionValue('--print'));
|
getOptionValue('--print'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
3
test/fixtures/external-repl-module.js
vendored
Normal file
3
test/fixtures/external-repl-module.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
console.log('42');
|
14
test/pseudo-tty/test-repl-external-module.js
Normal file
14
test/pseudo-tty/test-repl-external-module.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
require('../common');
|
||||||
|
const fixtures = require('../common/fixtures');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
execSync(process.execPath, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
stdio: 'inherit',
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
NODE_REPL_EXTERNAL_MODULE: fixtures.path('external-repl-module.js'),
|
||||||
|
},
|
||||||
|
});
|
1
test/pseudo-tty/test-repl-external-module.out
Normal file
1
test/pseudo-tty/test-repl-external-module.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
42
|
Loading…
x
Reference in New Issue
Block a user