-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
Some packages have been using try-catch to load require(esm) in environments that are available. In 23, where require(esm) is unflagged, we emit an experimental warning when require() is used to load ESM. To backport require(esm) to older LTS releases, however, this could break existing CLI output. To reduce the disruption for LTS, on older release lines, this commit is applied to skip the warning if require(esm) comes from node_modules. This warning will be eventually removed when require(esm) becomes stable.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
// This checks the experimental warning for require(esm) is disabled when the | ||
// require() comes from node_modules. | ||
require('../common'); | ||
const { spawnSyncAndAssert } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const warningRE = /ExperimentalWarning: Support for loading ES Module in require\(\)/; | ||
|
||
// The fixtures are placed in a directory that includes "node_modules" in its name | ||
// to check false negatives. | ||
|
||
// require() in non-node_modules -> esm in node_modules should warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'require-esm.js')], | ||
{ | ||
trim: true, | ||
stderr: warningRE, | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// require() in non-node_modules -> require() in node_modules -> esm in node_modules | ||
// should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'require-require-esm.js')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// import in non-node_modules -> require() in node_modules -> esm in node_modules | ||
// should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'import-require-esm.mjs')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// import in non-node_modules -> import in node_modules -> | ||
// require() in node_modules -> esm in node_modules should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'import-import-require-esm.mjs')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.