File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,10 @@ test('plugin resolved virtual file', async () => {
161161 expect ( await page . textContent ( '.virtual' ) ) . toMatch ( '[success]' )
162162} )
163163
164+ test ( 'plugin resolved virtual file that has import' , async ( ) => {
165+ expect ( await page . textContent ( '.virtual-has-import' ) ) . toMatch ( '[success]' )
166+ } )
167+
164168test ( 'plugin resolved custom virtual file' , async ( ) => {
165169 expect ( await page . textContent ( '.custom-virtual' ) ) . toMatch ( '[success]' )
166170} )
Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ <h2>Plugin resolved virtual file</h2>
158158< h2 > Plugin resolved virtual file (#9036)</ h2 >
159159< p class ="virtual-9036 "> </ p >
160160
161+ < h2 > Plugin resolved virtual file that has import</ h2 >
162+ < p class ="virtual-has-import "> </ p >
163+
161164< h2 > Plugin resolved custom virtual file</ h2 >
162165< p class ="custom-virtual "> </ p >
163166
@@ -402,6 +405,9 @@ <h2>utf8-bom-package</h2>
402405 import { msg as virtualMsg9036 } from 'virtual:file-9036.js'
403406 text ( '.virtual-9036' , virtualMsg9036 )
404407
408+ import { msg as virtualMsgHasImport } from 'virtual:file-has-import.js'
409+ text ( '.virtual-has-import' , virtualMsgHasImport )
410+
405411 import { msg as customVirtualMsg } from '@custom-virtual-file'
406412 text ( '.custom-virtual' , customVirtualMsg )
407413
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ const virtualId = '\0' + virtualFile
88const virtualFile9036 = 'virtual:file-9036.js'
99const virtualId9036 = '\0' + virtualFile9036
1010
11+ const virtualFileHasImport = 'virtual:file-has-import.js'
12+ const virtualIdHasImport = '/file-has-import.js'
13+
1114const customVirtualFile = '@custom-virtual-file'
1215
1316const virtualFileWithScheme = 'virtual-with-scheme'
@@ -67,6 +70,30 @@ export default defineConfig({
6770 }
6871 } ,
6972 } ,
73+ {
74+ name : 'virtual-module-has-import' ,
75+ enforce : 'pre' ,
76+ resolveId ( id , _importer , opts ) {
77+ if ( id === virtualFileHasImport ) {
78+ // make scanner happy
79+ // @ts -expect-error -- opts.scan is internal
80+ if ( opts ?. scan ) {
81+ return normalizePath (
82+ path . resolve ( import . meta. dirname , './exports-path/main.js' ) ,
83+ )
84+ }
85+ return virtualIdHasImport
86+ }
87+ } ,
88+ load ( id ) {
89+ if ( id === virtualIdHasImport ) {
90+ return (
91+ 'import { msg as importedMsg } from "@vitejs/test-resolve-exports-path"\n' +
92+ 'export const msg = importedMsg.includes("[success]") ? "[success] from virtual file that has import" : "[failure]"'
93+ )
94+ }
95+ } ,
96+ } ,
7097 {
7198 name : 'custom-resolve' ,
7299 resolveId ( id ) {
You can’t perform that action at this time.
0 commit comments