GeezerVison is showing github.com — repl: replace hard coded core module list with actual list · nodejs/node@69061dc
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/helpers.js +10-48Lines changed: 10 additions & 48 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | ObjectDefineProperty, | | 5 | + ObjectPrototypeHasOwnProperty, | 5 | 6 | SafeMap, | 6 | 7 | } = primordials; | 7 | 8 | const { | @@ -109,55 +110,17 @@ function stripBOM(content) { | 109 | 110 | return content; | 110 | 111 | } | 111 | 112 |
| 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 | | - | 158 | 113 | function addBuiltinLibsToObject(object) { | 159 | 114 | // 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 | + } | 161 | 124 | // Goals of this mechanism are: | 162 | 125 | // - Lazy loading of built-in modules | 163 | 126 | // - Having all built-in modules available as non-enumerable properties | @@ -203,7 +166,6 @@ function normalizeReferrerURL(referrer) { | 203 | 166 |
| 204 | 167 | module.exports = { | 205 | 168 | addBuiltinLibsToObject, | 206 | | - builtinLibs, | 207 | 169 | loadNativeModule, | 208 | 170 | makeRequireFunction, | 209 | 171 | normalizeReferrerURL, | |
Collapse file Copy file name to clipboardExpand all lines: lib/repl.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,7 +63,6 @@ const { | 63 | 63 | } = primordials; | 64 | 64 |
| 65 | 65 | const { | 66 | | - builtinLibs, | 67 | 66 | makeRequireFunction, | 68 | 67 | addBuiltinLibsToObject | 69 | 68 | } = require('internal/modules/cjs/helpers'); | @@ -86,6 +85,8 @@ const { | 86 | 85 | } = require('internal/readline/utils'); | 87 | 86 | const { Console } = require('console'); | 88 | 87 | const CJSModule = require('internal/modules/cjs/loader').Module; | | 88 | +const builtinModules = [...CJSModule.builtinModules] | | 89 | + .filter((e) => !e.startsWith('_')); | 89 | 90 | const domain = require('domain'); | 90 | 91 | const debug = require('internal/util/debuglog').debuglog('repl'); | 91 | 92 | const { | @@ -158,7 +159,7 @@ module.paths = CJSModule._nodeModulePaths(module.filename); | 158 | 159 | const writer = exports.writer = (obj) => inspect(obj, writer.options); | 159 | 160 | writer.options = { ...inspect.defaultOptions, showProxy: true }; | 160 | 161 |
| 161 | | -exports._builtinLibs = builtinLibs; | | 162 | +exports._builtinLibs = builtinModules; | 162 | 163 |
| 163 | 164 | function REPLServer(prompt, | 164 | 165 | stream, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,6 @@ const expectedModules = new Set([ | 17 | 17 | 'Internal Binding credentials', | 18 | 18 | 'Internal Binding fs', | 19 | 19 | 'Internal Binding fs_dir', | 20 | | - 'Internal Binding inspector', | 21 | 20 | 'Internal Binding module_wrap', | 22 | 21 | 'Internal Binding native_module', | 23 | 22 | 'Internal Binding options', | @@ -116,6 +115,7 @@ if (common.hasIntl) { | 116 | 115 | } | 117 | 116 |
| 118 | 117 | if (process.features.inspector) { | | 118 | + expectedModules.add('Internal Binding inspector'); | 119 | 119 | expectedModules.add('NativeModule internal/inspector_async_hook'); | 120 | 120 | expectedModules.add('NativeModule internal/util/inspector'); | 121 | 121 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-module-cjs-helpers.js -9Lines changed: 0 additions & 9 deletions Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl-mode.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,10 @@ function testStrictMode() { | 39 | 39 | } | 40 | 40 |
| 41 | 41 | function testStrictModeTerminal() { | | 42 | + if (!process.features.inspector) { | | 43 | + console.warn('Test skipped: V8 inspector is disabled'); | | 44 | + return; | | 45 | + } | 42 | 46 | // Verify that ReferenceErrors are reported in strict mode previews. | 43 | 47 | const cli = initRepl(repl.REPL_MODE_STRICT, { | 44 | 48 | terminal: true | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,6 +30,7 @@ const { | 30 | 30 | const assert = require('assert'); | 31 | 31 | const path = require('path'); | 32 | 32 | const fixtures = require('../common/fixtures'); | | 33 | +const { builtinModules } = require('module'); | 33 | 34 | const hasInspector = process.features.inspector; | 34 | 35 |
| 35 | 36 | if (!common.isMainThread) | @@ -222,8 +223,9 @@ putIn.run(['.clear']); | 222 | 223 |
| 223 | 224 | testMe.complete('require(\'', common.mustCall(function(error, data) { | 224 | 225 | 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`); | 227 | 229 | }); | 228 | 230 | })); | 229 | 231 |
| |
|