@@ -443,27 +443,40 @@ const HARD_REFERENCES = new Set(["video[src]", "audio[src]", "img[src]", "video[
443443const relativeToProject = ( ctx : ExternalAssetContext , absPath : string ) =>
444444 encodeUrlPath ( relative ( ctx . absProjectDir , absPath ) . replaceAll ( "\\" , "/" ) ) ;
445445
446+ function archiveTargetOf (
447+ ctx : ExternalAssetContext ,
448+ absPath : string ,
449+ rawPath : string ,
450+ options : { requireOnDisk : boolean ; filesystemPath : boolean } ,
451+ ) : string | null | undefined {
452+ if ( isPathInside ( absPath , ctx . absProjectDir ) ) {
453+ includeReferencedProjectFile ( ctx , absPath , rawPath , options . requireOnDisk ) ;
454+ return options . filesystemPath ? relativeToProject ( ctx , absPath ) : null ;
455+ }
456+ try {
457+ if ( ! existsSync ( absPath ) || ! statSync ( absPath ) . isFile ( ) ) return undefined ;
458+ } catch {
459+ return undefined ;
460+ }
461+ return encodeUrlPath ( addExternalAsset ( ctx , absPath ) ) ;
462+ }
463+
446464function tryResolveExternal (
447465 ctx : ExternalAssetContext ,
448466 rawPath : string ,
449467 referrerAbsDir : string ,
450468 requireOnDisk = false ,
451469) : string | null {
452- // A leading "/" is a filesystem path to the local render, and the cloud render host refuses one.
453470 const filesystemPath = rawPath . startsWith ( "/" ) && ! rawPath . startsWith ( "//" ) ;
454471 if ( isNonRelativeUrl ( rawPath ) && ! filesystemPath ) return null ;
455- for ( const path of decodeUrlPathVariants ( rawPath ) ) {
456- const absPath = resolve ( referrerAbsDir , path ) ;
457- if ( isPathInside ( absPath , ctx . absProjectDir ) ) {
458- includeReferencedProjectFile ( ctx , absPath , rawPath , requireOnDisk ) ;
459- return filesystemPath ? relativeToProject ( ctx , absPath ) : null ;
460- }
461- try {
462- if ( ! existsSync ( absPath ) || ! statSync ( absPath ) . isFile ( ) ) continue ;
463- } catch {
464- continue ;
465- }
466- return encodeUrlPath ( addExternalAsset ( ctx , absPath ) ) ;
472+ const cut = filesystemPath ? rawPath . search ( / [ ? # ] / ) : - 1 ;
473+ const [ path , suffix ] = cut < 0 ? [ rawPath , "" ] : [ rawPath . slice ( 0 , cut ) , rawPath . slice ( cut ) ] ;
474+ for ( const variant of decodeUrlPathVariants ( path ) ) {
475+ const target = archiveTargetOf ( ctx , resolve ( referrerAbsDir , variant ) , rawPath , {
476+ requireOnDisk,
477+ filesystemPath,
478+ } ) ;
479+ if ( target !== undefined ) return target && target + suffix ;
467480 }
468481 return null ;
469482}
0 commit comments