mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

require(esm) is relatively stable now and the experimental warning has run its course - it's now more troublesome than useful. This patch changes it to no longer emit a warning unless `--trace-require-module` is explicitly used. The flag supports two modes: - `--trace-require-module=all`: emit warnings for all usages - `--trace-require-module=no-node-modules`: emit warnings for usages that do not come from a `node_modules` folder. PR-URL: https://github.com/nodejs/node/pull/56194 Fixes: https://github.com/nodejs/node/issues/55417 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
// This checks the warning and the stack trace emitted by
|
|
// --trace-require-module=no-node-modules.
|
|
require('../common');
|
|
const { spawnSyncAndAssert } = require('../common/child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const warningRE = /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,
|
|
[
|
|
'--trace-require-module=no-node-modules',
|
|
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,
|
|
[
|
|
'--trace-require-module=no-node-modules',
|
|
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,
|
|
[
|
|
'--trace-require-module=no-node-modules',
|
|
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,
|
|
[
|
|
'--trace-require-module=no-node-modules',
|
|
fixtures.path('es-modules', 'test_node_modules', 'import-import-require-esm.mjs'),
|
|
],
|
|
{
|
|
trim: true,
|
|
stderr: '',
|
|
stdout: 'world',
|
|
}
|
|
);
|