| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 39c7a9e commit e95163b
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -250,6 +250,9 @@ If `--experimental-print-required-tla` is enabled, instead of throwing | |||
| 250 | 250 | module, try to locate the top-level awaits, and print their location to | |
| 251 | 251 | help users fix them. | |
| 252 | 252 | ||
| 253 | + This feature can be detected by checking if | ||
| 254 | + [`process.features.require_module`][] is `true`. | ||
| 255 | + | ||
| 253 | 256 | ## All together | |
| 254 | 257 | ||
| 255 | 258 | <!-- type=misc --> | |
@@ -1214,6 +1217,7 @@ This section was moved to | |||
| 1214 | 1217 | [`node:test`]: test.md | |
| 1215 | 1218 | [`package.json`]: packages.md#nodejs-packagejson-field-definitions | |
| 1216 | 1219 | [`path.dirname()`]: path.md#pathdirnamepath | |
| 1220 | + [`process.features.require_module`]: process.md#processfeaturesrequire_module | ||
| 1217 | 1221 | [`require.main`]: #requiremain | |
| 1218 | 1222 | [exports shortcut]: #exports-shortcut | |
| 1219 | 1223 | [module resolution]: #all-together | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1928,6 +1928,17 @@ added: v0.5.3 | |||
| 1928 | 1928 | ||
| 1929 | 1929 | A boolean value that is `true` if the current Node.js build includes support for IPv6. | |
| 1930 | 1930 | ||
| 1931 | + ## `process.features.require_module` | ||
| 1932 | + | ||
| 1933 | + <!-- YAML | ||
| 1934 | + added: REPLACEME | ||
| 1935 | + --> | ||
| 1936 | + | ||
| 1937 | + * {boolean} | ||
| 1938 | + | ||
| 1939 | + A boolean value that is `true` if the current Node.js build supports | ||
| 1940 | + [loading ECMAScript modules using `require()`][]. | ||
| 1941 | + | ||
| 1931 | 1942 | ## `process.features.tls` | |
| 1932 | 1943 | ||
| 1933 | 1944 | <!-- YAML | |
@@ -4419,6 +4430,7 @@ cases: | |||
| 4419 | 4430 | [built-in modules with mandatory `node:` prefix]: modules.md#built-in-modules-with-mandatory-node-prefix | |
| 4420 | 4431 | [debugger]: debugger.md | |
| 4421 | 4432 | [deprecation code]: deprecations.md | |
| 4433 | + [loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require | ||
| 4422 | 4434 | [note on process I/O]: #a-note-on-process-io | |
| 4423 | 4435 | [process.cpuUsage]: #processcpuusagepreviousvalue | |
| 4424 | 4436 | [process_emit_warning]: #processemitwarningwarning-type-code-ctor | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -288,6 +288,9 @@ const features = { | |||
| 288 | 288 | get cached_builtins() { | |
| 289 | 289 | return binding.hasCachedBuiltins(); | |
| 290 | 290 | }, | |
| 291 | + get require_module() { | ||
| 292 | + return getOptionValue('--experimental-require-module'); | ||
| 293 | + }, | ||
| 291 | 294 | }; | |
| 292 | 295 | ||
| 293 | 296 | ObjectDefineProperty(process, 'features', { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,38 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests that process.features.require_module can be used to feature-detect | ||
| 4 | + // require(esm) without triggering a warning. | ||
| 5 | + | ||
| 6 | + require('../common'); | ||
| 7 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 8 | + | ||
| 9 | + spawnSyncAndAssert(process.execPath, [ | ||
| 10 | + '--no-warnings', | ||
| 11 | + '--experimental-require-module', | ||
| 12 | + '-p', | ||
| 13 | + 'process.features.require_module', | ||
| 14 | + ], { | ||
| 15 | + trim: true, | ||
| 16 | + stdout: 'true', | ||
| 17 | + stderr: '', // Should not emit warnings. | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + // It is not enabled by default. | ||
| 21 | + spawnSyncAndAssert(process.execPath, [ | ||
| 22 | + '-p', | ||
| 23 | + 'process.features.require_module', | ||
| 24 | + ], { | ||
| 25 | + trim: true, | ||
| 26 | + stdout: 'false', | ||
| 27 | + stderr: '', // Should not emit warnings. | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + spawnSyncAndAssert(process.execPath, [ | ||
| 31 | + '--no-experimental-require-module', | ||
| 32 | + '-p', | ||
| 33 | + 'process.features.require_module', | ||
| 34 | + ], { | ||
| 35 | + trim: true, | ||
| 36 | + stdout: 'false', | ||
| 37 | + stderr: '', // Should not emit warnings. | ||
| 38 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ const expectedKeys = new Map([ | |||
| 14 | 14 | ['tls_ocsp', ['boolean']], | |
| 15 | 15 | ['tls', ['boolean']], | |
| 16 | 16 | ['cached_builtins', ['boolean']], | |
| 17 | + ['require_module', ['boolean']], | ||
| 17 | 18 | ['typescript', ['boolean', 'string']], | |
| 18 | 19 | ]); | |
| 19 | 20 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments