mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 15:02:25 +00: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>
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
// Flags: --experimental-require-module
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
// Test named exports.
|
|
{
|
|
const mod = require('../fixtures/es-module-loaders/module-named-exports.mjs');
|
|
common.expectRequiredModule(mod, { foo: 'foo', bar: 'bar' });
|
|
}
|
|
|
|
// Test ESM that import ESM.
|
|
{
|
|
const mod = require('../fixtures/es-modules/import-esm.mjs');
|
|
common.expectRequiredModule(mod, { hello: 'world' });
|
|
}
|
|
|
|
// Test ESM that import CJS.
|
|
{
|
|
const mod = require('../fixtures/es-modules/cjs-exports.mjs');
|
|
common.expectRequiredModule(mod, { });
|
|
}
|
|
|
|
// Test ESM that require() CJS.
|
|
{
|
|
const mjs = require('../common/index.mjs');
|
|
// Only comparing a few properties because the ESM version of test/common doesn't
|
|
// re-export everything from the CJS version.
|
|
assert.strictEqual(common.mustCall, mjs.mustCall);
|
|
assert.strictEqual(common.localIPv6Hosts, mjs.localIPv6Hosts);
|
|
}
|
|
|
|
// Test "type": "module" and "main" field in package.json.
|
|
// Also, test default export.
|
|
{
|
|
const mod = require('../fixtures/es-modules/package-type-module');
|
|
common.expectRequiredModule(mod, { default: 'package-type-module' });
|
|
}
|
|
|
|
// Test data: import.
|
|
{
|
|
const mod = require('../fixtures/es-modules/data-import.mjs');
|
|
common.expectRequiredModule(mod, {
|
|
data: { hello: 'world' },
|
|
id: 'data:text/javascript,export default %7B%20hello%3A%20%22world%22%20%7D'
|
|
});
|
|
}
|