GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: replace hard coded core module list with actual list · nodejs/node@69061dc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • internal/modules/cjs
      • helpers.js
    • repl.js
  • test/parallel
    • test-bootstrap-modules.js
    • test-module-cjs-helpers.js
    • test-repl-mode.js
    • test-repl-tab-complete.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/helpers.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/helpers.js
+10-48Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {
44
ObjectDefineProperty,
5+
ObjectPrototypeHasOwnProperty,
56
SafeMap,
67
} = primordials;
78
const {
@@ -109,55 +110,17 @@ function stripBOM(content) {
109110
return content;
110111
}
111112

112-
const builtinLibs = [
113-
'assert',
114-
'async_hooks',
115-
'buffer',
116-
'child_process',
117-
'cluster',
118-
'crypto',
119-
'dgram',
120-
'dns',
121-
'domain',
122-
'events',
123-
'fs',
124-
'http',
125-
'http2',
126-
'https',
127-
'net',
128-
'os',
129-
'path',
130-
'perf_hooks',
131-
'punycode',
132-
'querystring',
133-
'readline',
134-
'repl',
135-
'stream',
136-
'string_decoder',
137-
'tls',
138-
'trace_events',
139-
'tty',
140-
'url',
141-
'util',
142-
'v8',
143-
'vm',
144-
'worker_threads',
145-
'zlib',
146-
];
147-
148-
if (internalBinding('config').experimentalWasi) {
149-
builtinLibs.push('wasi');
150-
builtinLibs.sort();
151-
}
152-
153-
if (typeof internalBinding('inspector').open === 'function') {
154-
builtinLibs.push('inspector');
155-
builtinLibs.sort();
156-
}
157-
158113
function addBuiltinLibsToObject(object) {
159114
// Make built-in modules available directly (loaded lazily).
160-
builtinLibs.forEach((name) => {
115+
const { builtinModules } = require('internal/modules/cjs/loader').Module;
116+
builtinModules.forEach((name) => {
117+
// Neither add underscored modules, nor ones that contain slashes (e.g.,
118+
// 'fs/promises') or ones that are already defined.
119+
if (name.startsWith('_') ||
120+
name.includes('/') ||
121+
ObjectPrototypeHasOwnProperty(object, name)) {
122+
return;
123+
}
161124
// Goals of this mechanism are:
162125
// - Lazy loading of built-in modules
163126
// - Having all built-in modules available as non-enumerable properties
@@ -203,7 +166,6 @@ function normalizeReferrerURL(referrer) {
203166

204167
module.exports = {
205168
addBuiltinLibsToObject,
206-
builtinLibs,
207169
loadNativeModule,
208170
makeRequireFunction,
209171
normalizeReferrerURL,
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const {
6363
} = primordials;
6464

6565
const {
66-
builtinLibs,
6766
makeRequireFunction,
6867
addBuiltinLibsToObject
6968
} = require('internal/modules/cjs/helpers');
@@ -86,6 +85,8 @@ const {
8685
} = require('internal/readline/utils');
8786
const { Console } = require('console');
8887
const CJSModule = require('internal/modules/cjs/loader').Module;
88+
const builtinModules = [...CJSModule.builtinModules]
89+
.filter((e) => !e.startsWith('_'));
8990
const domain = require('domain');
9091
const debug = require('internal/util/debuglog').debuglog('repl');
9192
const {
@@ -158,7 +159,7 @@ module.paths = CJSModule._nodeModulePaths(module.filename);
158159
const writer = exports.writer = (obj) => inspect(obj, writer.options);
159160
writer.options = { ...inspect.defaultOptions, showProxy: true };
160161

161-
exports._builtinLibs = builtinLibs;
162+
exports._builtinLibs = builtinModules;
162163

163164
function REPLServer(prompt,
164165
stream,
Collapse file

‎test/parallel/test-bootstrap-modules.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const expectedModules = new Set([
1717
'Internal Binding credentials',
1818
'Internal Binding fs',
1919
'Internal Binding fs_dir',
20-
'Internal Binding inspector',
2120
'Internal Binding module_wrap',
2221
'Internal Binding native_module',
2322
'Internal Binding options',
@@ -116,6 +115,7 @@ if (common.hasIntl) {
116115
}
117116

118117
if (process.features.inspector) {
118+
expectedModules.add('Internal Binding inspector');
119119
expectedModules.add('NativeModule internal/inspector_async_hook');
120120
expectedModules.add('NativeModule internal/util/inspector');
121121
}
Collapse file

‎test/parallel/test-module-cjs-helpers.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-module-cjs-helpers.js
-9Lines changed: 0 additions & 9 deletions
This file was deleted.
Collapse file

‎test/parallel/test-repl-mode.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-mode.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function testStrictMode() {
3939
}
4040

4141
function testStrictModeTerminal() {
42+
if (!process.features.inspector) {
43+
console.warn('Test skipped: V8 inspector is disabled');
44+
return;
45+
}
4246
// Verify that ReferenceErrors are reported in strict mode previews.
4347
const cli = initRepl(repl.REPL_MODE_STRICT, {
4448
terminal: true
Collapse file

‎test/parallel/test-repl-tab-complete.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const {
3030
const assert = require('assert');
3131
const path = require('path');
3232
const fixtures = require('../common/fixtures');
33+
const { builtinModules } = require('module');
3334
const hasInspector = process.features.inspector;
3435

3536
if (!common.isMainThread)
@@ -222,8 +223,9 @@ putIn.run(['.clear']);
222223

223224
testMe.complete('require(\'', common.mustCall(function(error, data) {
224225
assert.strictEqual(error, null);
225-
repl._builtinLibs.forEach(function(lib) {
226-
assert(data[0].includes(lib), `${lib} not found`);
226+
builtinModules.forEach((lib) => {
227+
if (!lib.startsWith('_'))
228+
assert(data[0].includes(lib), `${lib} not found`);
227229
});
228230
}));
229231

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.