Skip to content

Commit 971affd

Browse files
committed
fixup! module: disallow CJS <-> ESM edges in a cycle from require(esm)
1 parent dc62194 commit 971affd

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict';
2+
3+
require('../common');
4+
const { spawnSyncAndAssert } = require('../common/child_process');
5+
const fixtures = require('../common/fixtures');
6+
7+
// a.mjs -> b.mjs -> c.cjs -> z.mjs -> a.mjs
8+
{
9+
spawnSyncAndAssert(
10+
process.execPath,
11+
[
12+
'--experimental-require-module',
13+
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/a.mjs'),
14+
],
15+
{
16+
signal: null,
17+
status: 1,
18+
stderr: /Cannot import Module \.\/a\.mjs in a cycle\. \(from .*z\.mjs\)/,
19+
}
20+
);
21+
}
22+
23+
// b.mjs -> c.cjs -> z.mjs -> a.mjs -> b.mjs
24+
{
25+
spawnSyncAndAssert(
26+
process.execPath,
27+
[
28+
'--experimental-require-module',
29+
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/b.mjs'),
30+
],
31+
{
32+
signal: null,
33+
status: 1,
34+
stderr: /Cannot import Module \.\/b\.mjs in a cycle\. \(from .*a\.mjs\)/,
35+
}
36+
);
37+
}
38+
39+
// c.cjs -> z.mjs -> a.mjs -> b.mjs -> c.cjs
40+
{
41+
spawnSyncAndAssert(
42+
process.execPath,
43+
[
44+
'--experimental-require-module',
45+
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/c.cjs'),
46+
],
47+
{
48+
signal: null,
49+
status: 1,
50+
stderr: /Cannot import CommonJS Module \.\/c\.cjs in a cycle\. \(from .*b\.mjs\)/,
51+
}
52+
);
53+
}
54+
55+
56+
// z.mjs -> a.mjs -> b.mjs -> c.cjs -> z.mjs
57+
{
58+
spawnSyncAndAssert(
59+
process.execPath,
60+
[
61+
'--experimental-require-module',
62+
fixtures.path('es-modules/esm-esm-cjs-esm-esm-cycle/z.mjs'),
63+
],
64+
{
65+
signal: null,
66+
status: 1,
67+
stderr: /Cannot require\(\) ES Module .*z\.mjs in a cycle\. \(from .*c\.cjs\)/,
68+
}
69+
);
70+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './b.mjs'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './c.cjs'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./z.mjs')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './a.mjs'

0 commit comments

Comments
Β (0)