@@ -296,7 +296,6 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
296
296
} else {
297
297
opts . lint = updatedOpts . buildMode === 'development' ;
298
298
}
299
- console . dir ( opts ) ;
300
299
return { ...opts } ;
301
300
} ;
302
301
@@ -326,14 +325,9 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
326
325
} ;
327
326
328
327
let didAddQwikEntries = false ;
329
- const jsPacketIdSource = new Map < string , string > ( ) ;
330
328
const buildStart = async ( ctx : Rollup . PluginContext ) => {
331
329
debug ( `buildStart()` , opts . buildMode , opts . scope , opts . target ) ;
332
330
const optimizer = getOptimizer ( ) ;
333
- // hmm
334
- // transformedOutputs.clear();
335
- // ssrTransformedOutputs.clear();
336
-
337
331
if ( optimizer . sys . env === 'node' && opts . target === 'ssr' && opts . lint ) {
338
332
try {
339
333
linter = await createLinter ( optimizer . sys , opts . rootDir , opts . tsconfigFileNames ) ;
@@ -388,38 +382,29 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
388
382
moduleSideEffects : false ,
389
383
} ;
390
384
}
391
- let firstInput : string ;
392
- if ( Array . isArray ( opts . input ) ) {
393
- firstInput = opts . input [ 0 ] ;
394
- } else {
395
- firstInput = Object . values ( opts . input ) [ 0 ] ;
396
- }
385
+
386
+ const firstInput = Object . values ( opts . input ) [ 0 ] ;
397
387
return {
398
388
id : normalizePath ( getPath ( ) . resolve ( firstInput , QWIK_CLIENT_MANIFEST_ID ) ) ,
399
389
moduleSideEffects : false ,
400
390
} ;
401
391
}
402
392
403
393
const path = getPath ( ) ;
404
- const isSSR = resolveOpts ?. ssr ?? opts . target === 'ssr' ;
394
+ const isSSR = ! ! resolveOpts ?. ssr ;
405
395
406
396
if ( importer ) {
407
- if ( ! isSSR && importer . endsWith ( '.html' ) ) {
408
- const match = id . match ( / .j s ? q r l = ( .* ) $ / ) ;
409
- console . log ( 'dev server asking for jsPacket' , path . isAbsolute ( id ) , match ) ;
410
- if ( match ) {
411
- const jsPacketId = match [ 1 ] ;
412
- const sourceId = jsPacketIdSource . get ( jsPacketId ) ;
413
- if ( sourceId ) {
414
- await ctx . load ( { id : sourceId } ) ;
415
- // Now all jsPackets exist in the cache
416
- }
417
- }
418
- }
419
- // Only process relative links
420
- if ( ! id . startsWith ( '.' ) && ( ! path . isAbsolute ( id ) || ! importer . endsWith ( '.html' ) ) ) {
397
+ // Only process real files
398
+ if ( ! ( id . startsWith ( '.' ) || path . isAbsolute ( id ) ) ) {
421
399
return ;
422
400
}
401
+ const match = / ^ ( [ ^ ? ] * ) \? _ q r l _ p a r e n t = / . exec ( id ) ;
402
+ if ( match ) {
403
+ // ssr mode asking for a client jsPacket, fall through to the devserver
404
+ // building via ctx.load doesn't seem to work
405
+ const packetId = `${ opts . rootDir } ${ match [ 1 ] } ` ;
406
+ return { id : packetId } ;
407
+ }
423
408
const parsedId = parseId ( id ) ;
424
409
let importeePathId = normalizePath ( parsedId . pathId ) ;
425
410
const ext = path . extname ( importeePathId ) . toLowerCase ( ) ;
@@ -462,6 +447,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
462
447
}
463
448
}
464
449
}
450
+ // we don't know what this is
465
451
return null ;
466
452
} ;
467
453
const load = async (
@@ -518,7 +504,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
518
504
return generateQwikEntries ( transformedOutputs ) ;
519
505
}
520
506
521
- const isSSR = loadOpts ?. ssr ?? opts . target === 'ssr' ;
507
+ const isSSR = ! ! loadOpts ?. ssr ;
522
508
if ( opts . resolveQwikBuild && id . endsWith ( QWIK_BUILD_ID ) ) {
523
509
debug ( `load()` , QWIK_BUILD_ID , opts . buildMode ) ;
524
510
return {
@@ -542,31 +528,22 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
542
528
543
529
if ( transformedModule ) {
544
530
debug ( `load()` , 'Found' , id ) ;
531
+ let { code } = transformedModule [ 0 ] ;
532
+ const { map, hook } = transformedModule [ 0 ] ;
545
533
546
- let code = transformedModule [ 0 ] . code ;
547
- let firstInput : string ;
548
- if ( Array . isArray ( opts . input ) ) {
549
- firstInput = opts . input [ 0 ] ;
550
- } else {
551
- firstInput = Object . values ( opts . input ) [ 0 ] ;
552
- }
553
534
if ( opts . target === 'ssr' ) {
535
+ const firstInput = Object . values ( opts . input ) [ 0 ] ;
554
536
// doing this because vite will not use resolveId() when "noExternal" is false
555
537
// so we need to turn the @qwik -client-manifest import into a relative import
556
538
code = code . replace (
557
539
/ @ q w i k - c l i e n t - m a n i f e s t / g,
558
540
normalizePath ( path . resolve ( firstInput , QWIK_CLIENT_MANIFEST_ID ) )
559
541
) ;
560
542
}
561
- return {
562
- code,
563
- map : transformedModule [ 0 ] . map ,
564
- meta : {
565
- hook : transformedModule [ 0 ] . hook ,
566
- } ,
567
- } ;
543
+ return { code, map, meta : { hook } } ;
568
544
}
569
545
546
+ debug ( 'load()' , 'Not found' , id ) ;
570
547
return null ;
571
548
} ;
572
549
@@ -579,7 +556,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
579
556
if ( id . startsWith ( '\0' ) || id . startsWith ( '/@fs/' ) ) {
580
557
return ;
581
558
}
582
- const isSSR = transformOpts . ssr ?? opts . target === 'ssr' ;
559
+ const isSSR = ! ! transformOpts . ssr ;
583
560
const currentOutputs = isSSR ? ssrTransformedOutputs : transformedOutputs ;
584
561
if ( currentOutputs . has ( id ) ) {
585
562
return ;
@@ -600,7 +577,17 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
600
577
/** Strip client|server code from server|client */
601
578
const strip = opts . target === 'client' || opts . target === 'ssr' ;
602
579
const normalizedID = normalizePath ( pathId ) ;
603
- debug ( `transform()` , 'Transforming' , pathId ) ;
580
+ debug (
581
+ `transform()` ,
582
+ 'Transforming' ,
583
+ pathId ,
584
+ id ,
585
+ parsedPathId ,
586
+ strip ,
587
+ isSSR ,
588
+ opts . srcDir ,
589
+ dir
590
+ ) ;
604
591
605
592
let filePath = base ;
606
593
if ( opts . srcDir ) {
@@ -663,47 +650,6 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
663
650
ctx . addWatchFile ( key ) ;
664
651
}
665
652
}
666
- if ( isSSR && strip ) {
667
- // We also need a client build with the server code stripped
668
- // so that we know all the possible jsPackets that are used
669
- const clientTransformOpts : TransformModulesOptions = {
670
- input : [ { code, path : filePath } ] ,
671
- entryStrategy : opts . entryStrategy ,
672
- minify : 'simplify' ,
673
- sourceMaps : opts . sourcemap || 'development' === opts . buildMode ,
674
- transpileTs : true ,
675
- transpileJsx : true ,
676
- explicitExtensions : true ,
677
- preserveFilenames : true ,
678
- srcDir : srcDir ,
679
- rootDir : opts . rootDir ,
680
- mode : mode ,
681
- scope : opts . scope ? opts . scope : void 0 ,
682
- stripCtxName : SERVER_STRIP_CTX_NAME ,
683
- stripExports : SERVER_STRIP_EXPORTS ,
684
- isServer : false ,
685
- } ;
686
- const clientNewOutput = optimizer . transformModulesSync ( clientTransformOpts ) ;
687
- debug ( 'client build' , transformOpts , newOutput ) ;
688
-
689
- diagnosticsCallback ( clientNewOutput . diagnostics , optimizer , srcDir ) ;
690
-
691
- results . set ( normalizedID , clientNewOutput ) ;
692
- for ( const mod of clientNewOutput . modules ) {
693
- if ( isAdditionalFile ( mod ) ) {
694
- const key = normalizePath ( path . join ( srcDir , mod . path ) ) ;
695
- transformedOutputs . set ( key , [ mod , id ] ) ;
696
- // these are in ssr context and should be in client context
697
- // deps.add(key);
698
- // ctx.addWatchFile(key);
699
- if ( mod . hook ) {
700
- currentOutputs . set ( mod . hook . name , [ mod , id ] ) ;
701
- jsPacketIdSource . set ( mod . hook . name , id ) ;
702
- console . log ( 'hook' , mod . hook . name . toLowerCase ( ) , id ) ;
703
- }
704
- }
705
- }
706
- }
707
653
708
654
// Force loading generated submodules into Rollup cache so later
709
655
// unchanged imports are not missing in our internal transform cache
@@ -778,7 +724,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
778
724
} ;
779
725
780
726
const debug = ( ...str : any [ ] ) => {
781
- if ( true || opts . debug ) {
727
+ if ( opts . debug ) {
782
728
// eslint-disable-next-line no-console
783
729
console . debug ( `[QWIK PLUGIN: ${ id } ]` , ...str ) ;
784
730
}
0 commit comments