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 e6397aa

Browse filesBrowse files
devsnektargos
authored andcommitted
repl: check for NODE_REPL_EXTERNAL_MODULE
PR-URL: #29778 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
1 parent a0494cf commit e6397aa
Copy full SHA for e6397aa

File tree

Expand file treeCollapse file tree

5 files changed

+62
-30
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+62
-30
lines changed
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+8Lines changed: 8 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,14 @@ Path to the file used to store the persistent REPL history. The default path is
11671167
`~/.node_repl_history`, which is overridden by this variable. Setting the value
11681168
to an empty string (`''` or `' '`) disables persistent REPL history.
11691169

1170+
### `NODE_REPL_EXTERNAL_MODULE=file`
1171+
<!-- YAML
1172+
added: REPLACEME
1173+
-->
1174+
1175+
Path to a Node.js module which will be loaded in place of the built-in REPL.
1176+
Overriding this value to an empty string (`''`) will use the built-in REPL.
1177+
11701178
### `NODE_TLS_REJECT_UNAUTHORIZED=value`
11711179

11721180
If `value` equals `'0'`, certificate validation is disabled for TLS connections.
Collapse file

‎lib/internal/main/repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/repl.js
+36-30Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,44 @@ prepareMainThreadExecution();
1919

2020
markBootstrapComplete();
2121

22-
// --input-type flag not supported in REPL
23-
if (getOptionValue('--input-type')) {
24-
// If we can't write to stderr, we'd like to make this a noop,
25-
// so use console.error.
26-
console.error('Cannot specify --input-type for REPL');
27-
process.exit(1);
28-
}
22+
if (process.env.NODE_REPL_EXTERNAL_MODULE) {
23+
require('internal/modules/cjs/loader')
24+
.Module
25+
._load(process.env.NODE_REPL_EXTERNAL_MODULE, undefined, true);
26+
} else {
27+
// --input-type flag not supported in REPL
28+
if (getOptionValue('--input-type')) {
29+
// If we can't write to stderr, we'd like to make this a noop,
30+
// so use console.error.
31+
console.error('Cannot specify --input-type for REPL');
32+
process.exit(1);
33+
}
2934

30-
console.log(`Welcome to Node.js ${process.version}.\n` +
31-
'Type ".help" for more information.');
35+
console.log(`Welcome to Node.js ${process.version}.\n` +
36+
'Type ".help" for more information.');
3237

33-
const cliRepl = require('internal/repl');
34-
cliRepl.createInternalRepl(process.env, (err, repl) => {
35-
if (err) {
36-
throw err;
37-
}
38-
repl.on('exit', () => {
39-
if (repl._flushing) {
40-
repl.pause();
41-
return repl.once('flushHistory', () => {
42-
process.exit();
43-
});
38+
const cliRepl = require('internal/repl');
39+
cliRepl.createInternalRepl(process.env, (err, repl) => {
40+
if (err) {
41+
throw err;
4442
}
45-
process.exit();
43+
repl.on('exit', () => {
44+
if (repl._flushing) {
45+
repl.pause();
46+
return repl.once('flushHistory', () => {
47+
process.exit();
48+
});
49+
}
50+
process.exit();
51+
});
4652
});
47-
});
48-
49-
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
50-
// evaluate the code in the current context.
51-
if (getOptionValue('[has_eval_string]')) {
52-
evalScript('[eval]',
53-
getOptionValue('--eval'),
54-
getOptionValue('--inspect-brk'),
55-
getOptionValue('--print'));
53+
54+
// If user passed '-e' or '--eval' along with `-i` or `--interactive`,
55+
// evaluate the code in the current context.
56+
if (getOptionValue('[has_eval_string]')) {
57+
evalScript('[eval]',
58+
getOptionValue('--eval'),
59+
getOptionValue('--inspect-brk'),
60+
getOptionValue('--print'));
61+
}
5662
}
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log('42');
Collapse file
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
require('../common');
4+
const fixtures = require('../common/fixtures');
5+
const { execSync } = require('child_process');
6+
7+
execSync(process.execPath, {
8+
encoding: 'utf8',
9+
stdio: 'inherit',
10+
env: {
11+
...process.env,
12+
NODE_REPL_EXTERNAL_MODULE: fixtures.path('external-repl-module.js'),
13+
},
14+
});
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42

0 commit comments

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