mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
db1746182b
This patch disallows CJS <-> ESM edges when they come from require(esm) requested in ESM evalaution. Drive-by: don't reuse the cache for imported CJS modules to stash source code of required ESM because the former is also used for cycle detection. PR-URL: https://github.com/nodejs/node/pull/52264 Fixes: https://github.com/nodejs/node/issues/52145 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const { spawnSyncAndExit, spawnSyncAndAssert } = require('../common/child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
// require-a.cjs -> a.mjs -> b.cjs -> a.mjs.
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-cjs-esm-cycle/require-a.cjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stderr: /Cannot require\(\) ES Module .*a\.mjs in a cycle\. \(from .*require-a\.cjs\)/,
|
|
}
|
|
);
|
|
}
|
|
|
|
// require-b.cjs -> b.cjs -> a.mjs -> b.cjs.
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-cjs-esm-cycle/require-b.cjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stderr: /Cannot import CommonJS Module \.\/b\.cjs in a cycle\. \(from .*a\.mjs\)/,
|
|
}
|
|
);
|
|
}
|
|
|
|
// a.mjs -> b.cjs -> a.mjs
|
|
{
|
|
spawnSyncAndExit(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-cjs-esm-cycle/a.mjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
stderr: /Cannot require\(\) ES Module .*a\.mjs in a cycle\. \(from .*b\.cjs\)/,
|
|
}
|
|
);
|
|
}
|
|
|
|
// b.cjs -> a.mjs -> b.cjs
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-cjs-esm-cycle/b.cjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stderr: /Cannot import CommonJS Module \.\/b\.cjs in a cycle\. \(from .*a\.mjs\)/,
|
|
}
|
|
);
|
|
}
|