11import { describe , expect , it } from 'vitest' ;
2- import type { BuiltLayout , BuiltRoute , BuiltServerPlugin , RoutingContext } from '../types' ;
3- import { collectServerFnModuleIds } from './server-fns' ;
2+ import type { BuiltLayout , BuiltRoute , BuiltServerPlugin } from '../types' ;
3+ import { collectServerFnModuleIds , type ServerFnRoutingContext } from './server-fns' ;
44
55describe ( 'collectServerFnModuleIds' , ( ) => {
66 it ( 'walks the reachable module graph and collects modules containing serverQrl' , async ( ) => {
@@ -12,59 +12,53 @@ describe('collectServerFnModuleIds', () => {
1212 {
1313 id : '/app/routes/index.tsx' ,
1414 code : 'export default component$(() => null);' ,
15- importedIdResolutions : [
16- { id : '/app/shared.ts' , external : false } ,
17- { id : '/node_modules/@qwik.dev/core/index.mjs' , external : false } ,
18- ] ,
19- dynamicallyImportedIdResolutions : [ { id : '/app/lazy.ts' , external : false } ] ,
15+ importedIds : [ '/app/shared.ts' , '/node_modules/@qwik.dev/core/index.mjs' ] ,
16+ dynamicallyImportedIds : [ '/app/lazy.ts' ] ,
2017 } ,
2118 ] ,
2219 [
2320 '/app/layout.tsx' ,
2421 {
2522 id : '/app/layout.tsx' ,
2623 code : 'export default component$(() => null);' ,
27- importedIdResolutions : [ { id : '/app/shared.ts' , external : false } ] ,
28- dynamicallyImportedIdResolutions : [ ] ,
24+ importedIds : [ '/app/shared.ts' ] ,
25+ dynamicallyImportedIds : [ ] ,
2926 } ,
3027 ] ,
3128 [
3229 '/app/shared.ts' ,
3330 {
3431 id : '/app/shared.ts' ,
3532 code : 'export const shared = true;' ,
36- importedIdResolutions : [
37- { id : resolvedVirtualId , external : false } ,
38- { id : 'node:fs' , external : true } ,
39- ] ,
40- dynamicallyImportedIdResolutions : [ ] ,
33+ importedIds : [ resolvedVirtualId ] ,
34+ dynamicallyImportedIds : [ ] ,
4135 } ,
4236 ] ,
4337 [
4438 '/app/lazy.ts' ,
4539 {
4640 id : '/app/lazy.ts' ,
4741 code : 'export const fn = serverQrl(() => null);' ,
48- importedIdResolutions : [ ] ,
49- dynamicallyImportedIdResolutions : [ ] ,
42+ importedIds : [ ] ,
43+ dynamicallyImportedIds : [ ] ,
5044 } ,
5145 ] ,
5246 [
5347 '/node_modules/@qwik.dev/core/index.mjs' ,
5448 {
5549 id : '/node_modules/@qwik.dev/core/index.mjs' ,
5650 code : 'export {};' ,
57- importedIdResolutions : [ ] ,
58- dynamicallyImportedIdResolutions : [ ] ,
51+ importedIds : [ ] ,
52+ dynamicallyImportedIds : [ ] ,
5953 } ,
6054 ] ,
6155 [
6256 '/app/plugin.ts' ,
6357 {
6458 id : '/app/plugin.ts' ,
6559 code : 'export const pluginFn = serverQrl(() => null);' ,
66- importedIdResolutions : [ ] ,
67- dynamicallyImportedIdResolutions : [ ] ,
60+ importedIds : [ ] ,
61+ dynamicallyImportedIds : [ ] ,
6862 } ,
6963 ] ,
7064 ] ) ;
@@ -92,20 +86,25 @@ describe('collectServerFnModuleIds', () => {
9286 filePath : '/app/plugin.ts' ,
9387 ext : 'ts' ,
9488 } ;
95- const ctx : Pick < RoutingContext , 'layouts' | 'routes' | 'serverPlugins' > = {
89+ const ctx : ServerFnRoutingContext = {
9690 routes : [ route ] ,
9791 layouts : [ layout ] ,
9892 serverPlugins : [ serverPlugin ] ,
9993 } ;
10094
101- const serverFnModules = await collectServerFnModuleIds ( ctx , resolvedVirtualId , async ( id ) => {
102- loads . push ( id ) ;
103- const moduleInfo = modules . get ( id ) ;
104- if ( ! moduleInfo ) {
105- throw new Error ( `Unexpected module load: ${ id } ` ) ;
106- }
107- return moduleInfo as any ;
108- } ) ;
95+ const pluginContext = {
96+ resolve : async ( id : string ) => ( { id, external : false } ) as any ,
97+ load : async ( { id } : { id : string } ) => {
98+ loads . push ( id ) ;
99+ const moduleInfo = modules . get ( id ) ;
100+ if ( ! moduleInfo ) {
101+ throw new Error ( `Unexpected module load: ${ id } ` ) ;
102+ }
103+ return moduleInfo as any ;
104+ } ,
105+ } ;
106+
107+ const serverFnModules = await collectServerFnModuleIds ( ctx , resolvedVirtualId , pluginContext ) ;
109108
110109 expect ( serverFnModules . sort ( ) ) . toEqual ( [ '/app/lazy.ts' , '/app/plugin.ts' ] ) ;
111110 expect ( loads ) . toEqual ( [
0 commit comments