@@ -35,6 +35,10 @@ function parseSubCompHtml(html: string): ParsableDocumentLike {
3535 return parseHTML ( html ) . document as unknown as ParsableDocumentLike ;
3636}
3737
38+ /** The file a source was read from, as per-file findings carry it. */
39+ const sourceFile = ( projectDir : string , compSrcPath ?: string ) =>
40+ resolve ( projectDir , compSrcPath ?? "index.html" ) ;
41+
3842interface HtmlSource {
3943 html : string ;
4044 compSrcPath ?: string ;
@@ -357,7 +361,7 @@ function lintAudioSrcNotFound(
357361
358362 const audioSrcRe = mediaSrcTagRe ( "audio" ) ;
359363
360- const missingSrcs : string [ ] = [ ] ;
364+ const missingByFile = new Map < string , Set < string > > ( ) ;
361365 for ( const { html, compSrcPath } of htmlSources ) {
362366 let match : RegExpExecArray | null ;
363367 while ( ( match = audioSrcRe . exec ( html ) ) !== null ) {
@@ -368,16 +372,18 @@ function lintAudioSrcNotFound(
368372 ? rewriteAssetPath ( compSrcPath , src , ( path ) => existsSync ( join ( projectDir , path ) ) )
369373 : src ;
370374 if ( ! existsSync ( resolveProjectRelativeSrc ( rootRelative , projectDir ) ) ) {
371- missingSrcs . push ( src ) ;
375+ const file = sourceFile ( projectDir , compSrcPath ) ;
376+ missingByFile . set ( file , ( missingByFile . get ( file ) ?? new Set ( ) ) . add ( src ) ) ;
372377 }
373378 }
374379 }
375380
376- if ( missingSrcs . length > 0 ) {
377- const unique = [ ...new Set ( missingSrcs ) ] ;
381+ for ( const [ file , srcs ] of missingByFile ) {
382+ const unique = [ ...srcs ] ;
378383 findings . push ( {
379384 code : "audio_src_not_found" ,
380385 severity : "error" ,
386+ file,
381387 message : `<audio> element references file(s) not found in the project: ${ unique . join ( ", " ) } . The rendered video will be silent.` ,
382388 fixHint :
383389 unique . length === 1
@@ -398,7 +404,10 @@ function lintMissingLocalAsset(
398404
399405 const localAssetSrcRe = mediaSrcTagRe ( "video|img|source" ) ;
400406
401- const missingByTag = new Map < string , Map < string , string > > ( ) ;
407+ const missingByTag = new Map <
408+ string ,
409+ { file : string ; tagName : string ; byResolved : Map < string , string > }
410+ > ( ) ;
402411
403412 for ( const { html, compSrcPath } of htmlSources ) {
404413 const scannable = maskNonScannableRanges ( html ) ;
@@ -419,20 +428,23 @@ function lintMissingLocalAsset(
419428 if ( resolvedAsset ) continue ;
420429
421430 const resolvedKey = resolve ( projectDir , rootRelative ) ;
422- let bucket = missingByTag . get ( tagName ) ;
431+ const file = sourceFile ( projectDir , compSrcPath ) ;
432+ const bucketKey = `${ file } \0${ tagName } ` ;
433+ let bucket = missingByTag . get ( bucketKey ) ;
423434 if ( ! bucket ) {
424- bucket = new Map < string , string > ( ) ;
425- missingByTag . set ( tagName , bucket ) ;
435+ bucket = { file , tagName , byResolved : new Map < string , string > ( ) } ;
436+ missingByTag . set ( bucketKey , bucket ) ;
426437 }
427- if ( ! bucket . has ( resolvedKey ) ) bucket . set ( resolvedKey , src ) ;
438+ if ( ! bucket . byResolved . has ( resolvedKey ) ) bucket . byResolved . set ( resolvedKey , src ) ;
428439 }
429440 }
430441
431- for ( const [ tagName , byResolved ] of missingByTag ) {
442+ for ( const { file , tagName, byResolved } of missingByTag . values ( ) ) {
432443 const unique = [ ...byResolved . values ( ) ] ;
433444 findings . push ( {
434445 code : "missing_local_asset" ,
435446 severity : "error" ,
447+ file,
436448 message :
437449 `<${ tagName } > element references local file(s) not found in the project: ${ unique . join ( ", " ) } . ` +
438450 "The renderer will silently skip these and produce a video with missing visuals." ,
@@ -453,9 +465,10 @@ function lintTextureMaskAssetNotFound(
453465 projectDir : string ,
454466 htmlSources : HtmlSource [ ] ,
455467) : HyperframeLintFinding [ ] {
456- const missing = new Map < string , string > ( ) ;
468+ const missingByFile = new Map < string , Set < string > > ( ) ;
457469
458470 for ( const { html, compSrcPath } of htmlSources ) {
471+ const file = sourceFile ( projectDir , compSrcPath ) ;
459472 for ( const cssSource of collectCssSources ( projectDir , html , compSrcPath ) ) {
460473 let match : RegExpExecArray | null ;
461474 const pattern = new RegExp ( MASK_IMAGE_URL_RE . source , MASK_IMAGE_URL_RE . flags ) ;
@@ -473,24 +486,24 @@ function lintTextureMaskAssetNotFound(
473486 cssSource . rootRelativePath ,
474487 ) ;
475488 if ( candidates . some ( existsSync ) ) continue ;
476- missing . set ( url , candidates [ 0 ] ?? resolve ( projectDir , url ) ) ;
489+ missingByFile . set ( file , ( missingByFile . get ( file ) ?? new Set ( ) ) . add ( url ) ) ;
477490 }
478491 }
479492 }
480493
481- if ( missing . size === 0 ) return [ ] ;
482- const urls = [ ...missing . keys ( ) ] ;
483- return [
484- {
494+ return [ ...missingByFile ] . map ( ( [ file , found ] ) : HyperframeLintFinding => {
495+ const urls = [ ...found ] ;
496+ return {
485497 code : "texture_mask_asset_not_found" ,
486498 severity : "error" ,
499+ file,
487500 message : `CSS mask-image references file(s) not found in the project: ${ urls . join ( ", " ) } .` ,
488501 fixHint :
489502 urls . length === 1
490503 ? `Add "${ urls [ 0 ] } " to the project, or update the mask-image URL to point to an existing texture mask.`
491504 : "Add the missing texture mask files to the project, or update the mask-image URLs to point to existing files." ,
492- } ,
493- ] ;
505+ } ;
506+ } ) ;
494507}
495508
496509function lintMultipleRootCompositions ( projectDir : string ) : HyperframeLintFinding [ ] {
0 commit comments