Skip to content

Commit a109793

Browse files
authoredMar 26, 2025··
feat(allow-modules): include virtual: in the modules pattern (#425)
1 parent 8e3c290 commit a109793

7 files changed

+90
-1
lines changed
 

‎lib/util/get-allow-modules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports.schema = {
5353
type: "array",
5454
items: {
5555
type: "string",
56-
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
56+
pattern: "^(?:virtual:)?(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
5757
},
5858
uniqueItems: true,
5959
}

‎tests/lib/rules/no-extraneous-import.js

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ ruleTester.run("no-extraneous-import", rule, {
9898
filename: fixture("tsconfig-paths/index.ts"),
9999
code: "import foo from '#configurations/foo'",
100100
},
101+
102+
// virtual modules
103+
{
104+
filename: fixture("test.js"),
105+
code: "import a from 'virtual:package-name';",
106+
},
107+
{
108+
filename: fixture("test.js"),
109+
code: "import a from 'virtual:package-scope/name';",
110+
},
101111
],
102112
invalid: [
103113
{

‎tests/lib/rules/no-extraneous-require.js

+10
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ tester.run("no-extraneous-require", rule, {
6767
filename: fixture("dependencies/a.js"),
6868
code: "require('ccc')",
6969
},
70+
71+
// virtual modules
72+
{
73+
filename: fixture("test.js"),
74+
code: "require('virtual:package-name');",
75+
},
76+
{
77+
filename: fixture("test.js"),
78+
code: "require('virtual:package-scope/name');",
79+
},
7080
],
7181
invalid: [
7282
{

‎tests/lib/rules/no-missing-import.js

+23
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ ruleTester.run("no-missing-import", rule, {
167167
code: "import electron from 'electron';",
168168
options: [{ allowModules: ["electron"] }],
169169
},
170+
// allow virtual modules
171+
{
172+
filename: fixture("test.js"),
173+
code: "import a from 'virtual:package-name';",
174+
options: [{ allowModules: ["virtual:package-name"] }],
175+
},
176+
{
177+
filename: fixture("test.js"),
178+
code: "import a from 'virtual:package-scope/name';",
179+
options: [{ allowModules: ["virtual:package-scope"] }],
180+
},
170181

171182
// resolvePaths
172183
{
@@ -480,5 +491,17 @@ ruleTester.run("no-missing-import", rule, {
480491
},
481492
]
482493
: []),
494+
495+
// virtual modules
496+
{
497+
filename: fixture("test.js"),
498+
code: "import a from 'virtual:package-name';",
499+
errors: cantResolve("virtual:package-name"),
500+
},
501+
{
502+
filename: fixture("test.js"),
503+
code: "import a from 'virtual:package-scope/name';",
504+
errors: cantResolve("virtual:package-scope/name"),
505+
},
483506
],
484507
})

‎tests/lib/rules/no-missing-require.js

+23
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ ruleTester.run("no-missing-require", rule, {
240240
code: "require('jquery.cookie');",
241241
options: [{ allowModules: ["jquery.cookie"] }],
242242
},
243+
// allow virtual modules
244+
{
245+
filename: fixture("test.js"),
246+
code: "require('virtual:package-name');",
247+
options: [{ allowModules: ["virtual:package-name"] }],
248+
},
249+
{
250+
filename: fixture("test.js"),
251+
code: "require('virtual:package-scope/name');",
252+
options: [{ allowModules: ["virtual:package-scope"] }],
253+
},
243254

244255
// typescriptExtensionMap
245256
{
@@ -440,6 +451,18 @@ ruleTester.run("no-missing-require", rule, {
440451
code: "require.resolve('no-exist-package-0');",
441452
errors: cantResolve("no-exist-package-0"),
442453
},
454+
455+
// Virtual modules
456+
{
457+
filename: fixture("test.js"),
458+
code: "require('virtual:package-name');",
459+
errors: cantResolve("virtual:package-name"),
460+
},
461+
{
462+
filename: fixture("test.js"),
463+
code: "require('virtual:package-scope/name');",
464+
errors: cantResolve("virtual:package-scope/name"),
465+
},
443466
],
444467
})
445468

‎tests/lib/rules/no-unpublished-import.js

+12
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,23 @@ ruleTester.run("no-unpublished-import", rule, {
123123
code: "import a from './a';",
124124
},
125125

126+
// allow module
126127
{
127128
filename: fixture("1/test.js"),
128129
code: "import electron from 'electron';",
129130
options: [{ allowModules: ["electron"] }],
130131
},
132+
// allow virtual modules
133+
{
134+
filename: fixture("test.js"),
135+
code: "import a from 'virtual:package-name';",
136+
options: [{ allowModules: ["virtual:package-name"] }],
137+
},
138+
{
139+
filename: fixture("test.js"),
140+
code: "import a from 'virtual:package-scope/name';",
141+
options: [{ allowModules: ["virtual:package-scope"] }],
142+
},
131143

132144
// Auto-published files only apply to root package directory
133145
{

‎tests/lib/rules/no-unpublished-require.js

+11
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ ruleTester.run("no-unpublished-require", rule, {
224224
code: "require('electron');",
225225
options: [{ allowModules: ["electron"] }],
226226
},
227+
// allow virtual modules
228+
{
229+
filename: fixture("test.js"),
230+
code: "require('virtual:package-name');",
231+
options: [{ allowModules: ["virtual:package-name"] }],
232+
},
233+
{
234+
filename: fixture("test.js"),
235+
code: "require('virtual:package-scope/name');",
236+
options: [{ allowModules: ["virtual:package-scope"] }],
237+
},
227238

228239
// Auto-published files only apply to root package directory
229240
{

0 commit comments

Comments
 (0)
Please sign in to comment.