@@ -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,7 +325,6 @@ 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 ( ) ;
@@ -388,36 +386,20 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
388
386
moduleSideEffects : false ,
389
387
} ;
390
388
}
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
- }
389
+
390
+ const firstInput = Object . values ( opts . input ) [ 0 ] ;
397
391
return {
398
392
id : normalizePath ( getPath ( ) . resolve ( firstInput , QWIK_CLIENT_MANIFEST_ID ) ) ,
399
393
moduleSideEffects : false ,
400
394
} ;
401
395
}
402
396
403
397
const path = getPath ( ) ;
404
- const isSSR = resolveOpts ?. ssr ?? opts . target === 'ssr' ;
398
+ const isSSR = ! ! resolveOpts ?. ssr ;
405
399
406
400
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' ) ) ) {
401
+ // Only process real files
402
+ if ( ! ( id . startsWith ( '.' ) || path . isAbsolute ( id ) ) ) {
421
403
return ;
422
404
}
423
405
const parsedId = parseId ( id ) ;
@@ -462,6 +444,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
462
444
}
463
445
}
464
446
}
447
+ // we don't know what this is
465
448
return null ;
466
449
} ;
467
450
const load = async (
@@ -519,7 +502,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
519
502
return generateQwikEntries ( transformedOutputs ) ;
520
503
}
521
504
522
- const isSSR = loadOpts ?. ssr ?? opts . target === 'ssr' ;
505
+ const isSSR = ! ! loadOpts ?. ssr ;
523
506
if ( opts . resolveQwikBuild && id . endsWith ( QWIK_BUILD_ID ) ) {
524
507
debug ( `load()` , QWIK_BUILD_ID , opts . buildMode ) ;
525
508
return {
@@ -543,31 +526,22 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
543
526
544
527
if ( transformedModule ) {
545
528
debug ( `load()` , 'Found' , id ) ;
529
+ let { code } = transformedModule [ 0 ] ;
530
+ const { map, hook } = transformedModule [ 0 ] ;
546
531
547
- let code = transformedModule [ 0 ] . code ;
548
- let firstInput : string ;
549
- if ( Array . isArray ( opts . input ) ) {
550
- firstInput = opts . input [ 0 ] ;
551
- } else {
552
- firstInput = Object . values ( opts . input ) [ 0 ] ;
553
- }
554
532
if ( opts . target === 'ssr' ) {
533
+ const firstInput = Object . values ( opts . input ) [ 0 ] ;
555
534
// doing this because vite will not use resolveId() when "noExternal" is false
556
535
// so we need to turn the @qwik -client-manifest import into a relative import
557
536
code = code . replace (
558
537
/ @ q w i k - c l i e n t - m a n i f e s t / g,
559
538
normalizePath ( path . resolve ( firstInput , QWIK_CLIENT_MANIFEST_ID ) )
560
539
) ;
561
540
}
562
- return {
563
- code,
564
- map : transformedModule [ 0 ] . map ,
565
- meta : {
566
- hook : transformedModule [ 0 ] . hook ,
567
- } ,
568
- } ;
541
+ return { code, map, meta : { hook } } ;
569
542
}
570
543
544
+ debug ( 'load()' , 'Not found' , id ) ;
571
545
return null ;
572
546
} ;
573
547
@@ -580,7 +554,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
580
554
if ( id . startsWith ( '\0' ) || id . startsWith ( '/@fs/' ) ) {
581
555
return ;
582
556
}
583
- const isSSR = transformOpts . ssr ?? opts . target === 'ssr' ;
557
+ const isSSR = transformOpts . ssr ;
584
558
const currentOutputs = isSSR ? ssrTransformedOutputs : transformedOutputs ;
585
559
if ( currentOutputs . has ( id ) ) {
586
560
return ;
@@ -644,7 +618,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
644
618
645
619
const newOutput = optimizer . transformModulesSync ( transformOpts ) ;
646
620
// uncomment to show transform results
647
- debug ( { isSSR, strip } , transformOpts , newOutput ) ;
621
+ // debug({ isSSR, strip }, transformOpts, newOutput);
648
622
diagnosticsCallback ( newOutput . diagnostics , optimizer , srcDir ) ;
649
623
650
624
if ( isSSR ) {
@@ -664,47 +638,6 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
664
638
ctx . addWatchFile ( key ) ;
665
639
}
666
640
}
667
- if ( isSSR && strip ) {
668
- // We also need a client build with the server code stripped
669
- // so that we know all the possible jsPackets that are used
670
- const clientTransformOpts : TransformModulesOptions = {
671
- input : [ { code, path : filePath } ] ,
672
- entryStrategy : opts . entryStrategy ,
673
- minify : 'simplify' ,
674
- sourceMaps : opts . sourcemap || 'development' === opts . buildMode ,
675
- transpileTs : true ,
676
- transpileJsx : true ,
677
- explicitExtensions : true ,
678
- preserveFilenames : true ,
679
- srcDir : srcDir ,
680
- rootDir : opts . rootDir ,
681
- mode : mode ,
682
- scope : opts . scope ? opts . scope : void 0 ,
683
- stripCtxName : SERVER_STRIP_CTX_NAME ,
684
- stripExports : SERVER_STRIP_EXPORTS ,
685
- isServer : false ,
686
- } ;
687
- const clientNewOutput = optimizer . transformModulesSync ( clientTransformOpts ) ;
688
- debug ( 'client build' , transformOpts , newOutput ) ;
689
-
690
- diagnosticsCallback ( clientNewOutput . diagnostics , optimizer , srcDir ) ;
691
-
692
- results . set ( normalizedID , clientNewOutput ) ;
693
- for ( const mod of clientNewOutput . modules ) {
694
- if ( isAdditionalFile ( mod ) ) {
695
- const key = normalizePath ( path . join ( srcDir , mod . path ) ) ;
696
- transformedOutputs . set ( key , [ mod , id ] ) ;
697
- // these are in ssr context and should be in client context
698
- // deps.add(key);
699
- // ctx.addWatchFile(key);
700
- if ( mod . hook ) {
701
- currentOutputs . set ( mod . hook . name , [ mod , id ] ) ;
702
- jsPacketIdSource . set ( mod . hook . name , id ) ;
703
- console . log ( 'hook' , mod . hook . name . toLowerCase ( ) , id ) ;
704
- }
705
- }
706
- }
707
- }
708
641
709
642
// Force loading generated submodules into Rollup cache so later
710
643
// unchanged imports are not missing in our internal transform cache
@@ -779,7 +712,7 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
779
712
} ;
780
713
781
714
const debug = ( ...str : any [ ] ) => {
782
- if ( true || opts . debug ) {
715
+ if ( opts . debug ) {
783
716
// eslint-disable-next-line no-console
784
717
console . debug ( `[QWIK PLUGIN: ${ id } ]` , ...str ) ;
785
718
}
0 commit comments