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>
83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const { spawnSyncAndAssert } = require('../common/child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
const assert = require('assert');
|
|
|
|
// a.mjs -> b.mjs -> c.mjs -> d.mjs -> c.mjs
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-esm-cjs-esm-cycle/a.mjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 0,
|
|
trim: true,
|
|
stdout(output) {
|
|
assert.match(output, /Start c/);
|
|
assert.match(output, /dynamic import b\.mjs failed.*ERR_REQUIRE_CYCLE_MODULE/);
|
|
assert.match(output, /dynamic import d\.mjs failed.*ERR_REQUIRE_CYCLE_MODULE/);
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
// b.mjs -> c.mjs -> d.mjs -> c.mjs
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-esm-cjs-esm-cycle/b.mjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stdout: /Start c/,
|
|
stderr: /Cannot import Module \.\/c\.mjs in a cycle\. \(from .*d\.mjs\)/,
|
|
}
|
|
);
|
|
}
|
|
|
|
// c.mjs -> d.mjs -> c.mjs
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-esm-cjs-esm-cycle/c.mjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stdout: /Start c/,
|
|
stderr: /Cannot import Module \.\/c\.mjs in a cycle\. \(from .*d\.mjs\)/,
|
|
}
|
|
);
|
|
}
|
|
|
|
|
|
// d.mjs -> c.mjs -> d.mjs
|
|
{
|
|
spawnSyncAndAssert(
|
|
process.execPath,
|
|
[
|
|
'--experimental-require-module',
|
|
fixtures.path('es-modules/esm-esm-cjs-esm-cycle/d.mjs'),
|
|
],
|
|
{
|
|
signal: null,
|
|
status: 1,
|
|
trim: true,
|
|
stdout: /Start c/,
|
|
stderr: /Cannot require\(\) ES Module .*d\.mjs in a cycle\. \(from .*c\.mjs\)/,
|
|
}
|
|
);
|
|
}
|