| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cf8701c commit 4fba019
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -318,6 +318,8 @@ experimental and can be disabled using `--no-experimental-require-module`. | |||
| 318 | 318 | When `require()` actually encounters an ES module for the | |
| 319 | 319 | first time in the process, it will emit an experimental warning. The | |
| 320 | 320 | warning is expected to be removed when this feature stablizes. | |
| 321 | + This feature can be detected by checking if | ||
| 322 | + [`process.features.require_module`][] is `true`. | ||
| 321 | 323 | ||
| 322 | 324 | ## All together | |
| 323 | 325 | ||
@@ -1280,6 +1282,7 @@ This section was moved to | |||
| 1280 | 1282 | [`node:test`]: test.md | |
| 1281 | 1283 | [`package.json`]: packages.md#nodejs-packagejson-field-definitions | |
| 1282 | 1284 | [`path.dirname()`]: path.md#pathdirnamepath | |
| 1285 | + [`process.features.require_module`]: process.md#processfeaturesrequire_module | ||
| 1283 | 1286 | [`require.main`]: #requiremain | |
| 1284 | 1287 | [exports shortcut]: #exports-shortcut | |
| 1285 | 1288 | [module resolution]: #all-together | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1917,6 +1917,17 @@ added: v0.5.3 | |||
| 1917 | 1917 | ||
| 1918 | 1918 | A boolean value that is `true` if the current Node.js build includes support for IPv6. | |
| 1919 | 1919 | ||
| 1920 | + ## `process.features.require_module` | ||
| 1921 | + | ||
| 1922 | + <!-- YAML | ||
| 1923 | + added: REPLACEME | ||
| 1924 | + --> | ||
| 1925 | + | ||
| 1926 | + * {boolean} | ||
| 1927 | + | ||
| 1928 | + A boolean value that is `true` if the current Node.js build supports | ||
| 1929 | + [loading ECMAScript modules using `require()`][]. | ||
| 1930 | + | ||
| 1920 | 1931 | ## `process.features.tls` | |
| 1921 | 1932 | ||
| 1922 | 1933 | <!-- YAML | |
@@ -4182,6 +4193,7 @@ cases: | |||
| 4182 | 4193 | [built-in modules with mandatory `node:` prefix]: modules.md#built-in-modules-with-mandatory-node-prefix | |
| 4183 | 4194 | [debugger]: debugger.md | |
| 4184 | 4195 | [deprecation code]: deprecations.md | |
| 4196 | + [loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require | ||
| 4185 | 4197 | [note on process I/O]: #a-note-on-process-io | |
| 4186 | 4198 | [process.cpuUsage]: #processcpuusagepreviousvalue | |
| 4187 | 4199 | [process_emit_warning]: #processemitwarningwarning-type-code-ctor | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -251,6 +251,8 @@ process.assert = deprecate( | |||
| 251 | 251 | 'process.assert() is deprecated. Please use the `assert` module instead.', | |
| 252 | 252 | 'DEP0100'); | |
| 253 | 253 | ||
| 254 | + const { getOptionValue } = require('internal/options'); | ||
| 255 | + | ||
| 254 | 256 | // TODO(joyeecheung): this property has not been well-maintained, should we | |
| 255 | 257 | // deprecate it in favor of a better API? | |
| 256 | 258 | const { isDebugBuild, hasOpenSSL, hasInspector } = config; | |
@@ -268,6 +270,9 @@ const features = { | |||
| 268 | 270 | get cached_builtins() { | |
| 269 | 271 | return binding.hasCachedBuiltins(); | |
| 270 | 272 | }, | |
| 273 | + get require_module() { | ||
| 274 | + return getOptionValue('--experimental-require-module'); | ||
| 275 | + }, | ||
| 271 | 276 | }; | |
| 272 | 277 | ||
| 273 | 278 | ObjectDefineProperty(process, 'features', { | |
@@ -299,6 +304,7 @@ ObjectDefineProperty(process, 'features', { | |||
| 299 | 304 | } | |
| 300 | 305 | ||
| 301 | 306 | const { emitWarning, emitWarningSync } = require('internal/process/warning'); | |
| 307 | + | ||
| 302 | 308 | process.emitWarning = emitWarning; | |
| 303 | 309 | internalBinding('process_methods').setEmitWarningSync(emitWarningSync); | |
| 304 | 310 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,37 @@ | |||
| 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 | + '--experimental-require-module', | ||
| 11 | + '-p', | ||
| 12 | + 'process.features.require_module', | ||
| 13 | + ], { | ||
| 14 | + trim: true, | ||
| 15 | + stdout: 'true', | ||
| 16 | + stderr: '', // Should not emit warnings. | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + // It is now enabled by default. | ||
| 20 | + spawnSyncAndAssert(process.execPath, [ | ||
| 21 | + '-p', | ||
| 22 | + 'process.features.require_module', | ||
| 23 | + ], { | ||
| 24 | + trim: true, | ||
| 25 | + stdout: 'true', | ||
| 26 | + stderr: '', // Should not emit warnings. | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + spawnSyncAndAssert(process.execPath, [ | ||
| 30 | + '--no-experimental-require-module', | ||
| 31 | + '-p', | ||
| 32 | + 'process.features.require_module', | ||
| 33 | + ], { | ||
| 34 | + trim: true, | ||
| 35 | + stdout: 'false', | ||
| 36 | + stderr: '', // Should not emit warnings. | ||
| 37 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ assert.deepStrictEqual(keys, new Set([ | |||
| 10 | 10 | 'debug', | |
| 11 | 11 | 'uv', | |
| 12 | 12 | 'ipv6', | |
| 13 | + 'require_module', | ||
| 13 | 14 | 'tls_alpn', | |
| 14 | 15 | 'tls_sni', | |
| 15 | 16 | 'tls_ocsp', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments