@@ -494,17 +494,28 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
494494 }
495495 return ;
496496 }
497- let isAbsoluteDevFile ;
497+ importerId = normalizePath ( importerId ) ;
498+ const parsedImporterId = parseId ( importerId ) ;
499+ const dir = path . dirname ( parsedImporterId . pathId ) ;
498500 if ( opts . target === 'ssr' && ! isSSR && importerId . endsWith ( '.html' ) && server ) {
499501 // This is a request from a dev-mode browser
500502 // we uri-encode chunk paths in dev mode, and other imported files don't have % in their paths (hopefully)
501503 // These will be individual source files and their QRL segments
502504 id = decodeURIComponent ( id ) ;
505+ // Support absolute paths for qrl segments, due to e.g. pnpm linking
506+ const isAbsoluteFile = id . startsWith ( '/@fs/' ) ;
507+ if ( isAbsoluteFile ) {
508+ id = id . slice ( 4 ) ;
509+ }
503510 // Check for parent passed via QRL
504511 const match = / ^ ( [ ^ ? ] * ) \? _ q r l _ p a r e n t = ( .* ) / . exec ( id ) ;
505512 if ( match ) {
506513 id = match [ 1 ] ;
507- const parentId = match [ 2 ] ;
514+ const parentId = id . slice ( 0 , id . lastIndexOf ( '/' ) + 1 ) + match [ 2 ] ;
515+ if ( ! isAbsoluteFile ) {
516+ // We know for sure that the path is relative to the html importer even though it starts with /
517+ id = normalizePath ( path . join ( dir , id ) ) ;
518+ }
508519 // building here via ctx.load doesn't seem to work (target is always ssr?)
509520 // instead we use the devserver directly
510521 if ( ! clientResults . has ( parentId ) ) {
@@ -513,41 +524,20 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
513524 // The QRL segment should exist now
514525 }
515526 }
516- // Support absolute paths for qrl segments, due to e.g. pnpm linking
517- isAbsoluteDevFile = id . startsWith ( '/@fs/' ) ;
518- if ( isAbsoluteDevFile ) {
519- id = id . slice ( 4 ) ;
520- }
521527 }
522528 const parsedId = parseId ( id ) ;
523529 let importeePathId = normalizePath ( parsedId . pathId ) ;
524- if ( isAbsoluteDevFile ) {
530+ const ext = path . extname ( importeePathId ) . toLowerCase ( ) ;
531+ if ( ext in RESOLVE_EXTS ) {
532+ debug ( `resolveId("${ importeePathId } ", "${ importerId } ")` ) ;
533+ // resolve relative paths
534+ importeePathId = normalizePath ( path . resolve ( dir , importeePathId ) ) ;
535+
525536 if ( transformedOutputs . has ( importeePathId ) ) {
526537 debug ( `resolveId() Resolved ${ importeePathId } from transformedOutputs` ) ;
527- return { id : importeePathId + parsedId . query } ;
528- }
529- // fall through to standard resolve
530- } else {
531- const ext = path . extname ( importeePathId ) . toLowerCase ( ) ;
532- if ( ext in RESOLVE_EXTS ) {
533- importerId = normalizePath ( importerId ) ;
534- debug ( `resolveId("${ importeePathId } ", "${ importerId } ")` ) ;
535- const parsedImporterId = parseId ( importerId ) ;
536- const dir = path . dirname ( parsedImporterId . pathId ) ;
537- if ( parsedImporterId . pathId . endsWith ( '.html' ) && ! importeePathId . endsWith ( '.html' ) ) {
538- // dev mode browser requests, add rootDir
539- importeePathId = normalizePath ( path . join ( dir , importeePathId ) ) ;
540- } else {
541- importeePathId = normalizePath ( path . resolve ( dir , importeePathId ) ) ;
542- }
543- const transformedOutput = transformedOutputs . get ( importeePathId ) ;
544-
545- if ( transformedOutput ) {
546- debug ( `resolveId() Resolved ${ importeePathId } from transformedOutputs` ) ;
547- return {
548- id : importeePathId + parsedId . query ,
549- } ;
550- }
538+ return {
539+ id : importeePathId + parsedId . query ,
540+ } ;
551541 }
552542 }
553543 } else if ( path . isAbsolute ( id ) ) {
@@ -556,9 +546,8 @@ export function createPlugin(optimizerOptions: OptimizerOptions = {}) {
556546 const ext = path . extname ( importeePathId ) . toLowerCase ( ) ;
557547 if ( ext in RESOLVE_EXTS ) {
558548 debug ( `resolveId("${ importeePathId } ", "${ importerId } ")` ) ;
559- const transformedOutput = transformedOutputs . get ( importeePathId ) ;
560549
561- if ( transformedOutput ) {
550+ if ( transformedOutputs . has ( importeePathId ) ) {
562551 debug ( `resolveId() Resolved ${ importeePathId } from transformedOutputs` ) ;
563552 return {
564553 id : importeePathId + parsedId . query ,
@@ -929,20 +918,20 @@ export function parseId(originalId: string) {
929918 } ;
930919}
931920
932- const TRANSFORM_EXTS : { [ ext : string ] : boolean } = {
921+ const TRANSFORM_EXTS = {
933922 '.jsx' : true ,
934923 '.ts' : true ,
935924 '.tsx' : true ,
936- } ;
925+ } as const ;
937926
938- const RESOLVE_EXTS : { [ ext : string ] : boolean } = {
927+ const RESOLVE_EXTS = {
939928 '.tsx' : true ,
940929 '.ts' : true ,
941930 '.jsx' : true ,
942931 '.js' : true ,
943932 '.mjs' : true ,
944933 '.cjs' : true ,
945- } ;
934+ } as const ;
946935
947936const TRANSFORM_REGEX = / \. q w i k \. [ m c ] ? j s $ / ;
948937
0 commit comments