@@ -40,7 +40,7 @@ import {
4040 lintVideoMediaStartPastEof ,
4141} from "./hevcPreviewLint.js" ;
4242import { lintHyperframeHtml } from "./hyperframeLinter.js" ;
43- import { extractFontFaceFamilies } from "./rules/fonts.js" ;
43+ import { collectGoogleFontFamilies , extractFontFaceFamilies } from "./rules/fonts.js" ;
4444import { lintProjectShaderScripts } from "./projectShaders.js" ;
4545import type {
4646 HyperframeLintFinding ,
@@ -199,24 +199,30 @@ function resolveCssAssetCandidates(
199199 return resolveLocalAssetCandidates ( projectDir , url ) ;
200200}
201201
202- function collectHtmlFiles ( compositionsDir : string ) : string [ ] {
203- const walk = ( dir : string , rel : string ) : string [ ] => {
204- const out : string [ ] = [ ] ;
205- for ( const entry of readdirSync ( dir , { withFileTypes : true } ) ) {
206- const relPath = rel ? `${ rel } /${ entry . name } ` : entry . name ;
207- if ( entry . isDirectory ( ) ) {
208- // Registry components are source snippets, not independently mounted
209- // sub-compositions. Linting every installed template here makes an
210- // unused component fail the assembled project check.
211- if ( ! rel && entry . name === "components" ) continue ;
212- out . push ( ...walk ( join ( dir , entry . name ) , relPath ) ) ;
213- } else if ( entry . isFile ( ) && entry . name . endsWith ( ".html" ) && ! entry . name . startsWith ( "._" ) ) {
214- out . push ( relPath ) ;
215- }
202+ function mountedSources (
203+ projectDir : string ,
204+ rootHtml : string ,
205+ rootCompSrcPath ?: string ,
206+ ) : HtmlSource [ ] {
207+ const sources : HtmlSource [ ] = [ { html : rootHtml , compSrcPath : rootCompSrcPath } ] ;
208+ const seen = new Set < string > ( ) ;
209+ for ( const source of sources ) {
210+ const { document } = parseHTML ( source . html ) ;
211+ for ( const host of querySelectorAllIncludingTemplates ( document , "[data-composition-src]" ) ) {
212+ const src = host . getAttribute ( "data-composition-src" ) ?. trim ( ) ;
213+ if ( ! src || isUnresolvedAssetPlaceholder ( src ) || isRemoteOrInlineUrl ( src ) ) continue ;
214+ const path = resolve ( projectDir , src ) ;
215+ if ( seen . has ( path ) || ! isWithinProjectRoot ( projectDir , path ) ) continue ;
216+ seen . add ( path ) ;
217+ const read = readProjectFile ( path ) ;
218+ if ( read . kind !== "file" ) continue ;
219+ sources . push ( {
220+ html : read . text ,
221+ compSrcPath : relative ( resolve ( projectDir ) , path ) . replace ( / \\ / g, "/" ) ,
222+ } ) ;
216223 }
217- return out ;
218- } ;
219- return walk ( compositionsDir , "" ) . sort ( ) ;
224+ }
225+ return sources ;
220226}
221227
222228function declaredProjectFontFamilies ( projectDir : string , sources : HtmlSource [ ] ) : string [ ] {
@@ -230,6 +236,7 @@ function declaredProjectFontFamilies(projectDir: string, sources: HtmlSource[]):
230236 ...collectLocalStylesheets ( projectDir , document , compSrcPath ) ,
231237 ] ;
232238 for ( const family of extractFontFaceFamilies ( styles ) ) families . add ( family ) ;
239+ for ( const family of collectGoogleFontFamilies ( html , styles ) ) families . add ( family ) ;
233240 }
234241 return [ ...families ] ;
235242}
@@ -251,16 +258,10 @@ export async function lintProject(
251258 let totalInfos = 0 ;
252259
253260 const rootHtml = readFileSync ( indexPath , "utf-8" ) ;
254- const compositionsDir = resolve ( projectDir , "compositions" ) ;
255- const compositionFiles =
256- ! entryFile && existsSync ( compositionsDir ) ? collectHtmlFiles ( compositionsDir ) : [ ] ;
257- const projectFontFamilies = declaredProjectFontFamilies ( projectDir , [
258- { html : rootHtml , compSrcPath : rootCompSrcPath } ,
259- ...compositionFiles . map ( ( file ) => ( {
260- html : readFileSync ( join ( compositionsDir , file ) , "utf-8" ) ,
261- compSrcPath : `compositions/${ file } ` ,
262- } ) ) ,
263- ] ) ;
261+ const projectFontFamilies = declaredProjectFontFamilies (
262+ projectDir ,
263+ mountedSources ( projectDir , rootHtml , rootCompSrcPath ) ,
264+ ) ;
264265 const rootResult = await lintHyperframeHtml ( rootHtml , {
265266 ...hostOptions ,
266267 filePath : indexPath ,
@@ -274,8 +275,25 @@ export async function lintProject(
274275 totalInfos += rootResult . infoCount ;
275276
276277 const allHtmlSources : HtmlSource [ ] = [ { html : rootHtml , compSrcPath : rootCompSrcPath } ] ;
277- if ( compositionFiles . length > 0 ) {
278- const files = compositionFiles ;
278+ const compositionsDir = resolve ( projectDir , "compositions" ) ;
279+ if ( ! entryFile && existsSync ( compositionsDir ) ) {
280+ const collectHtmlFiles = ( dir : string , rel : string ) : string [ ] => {
281+ const out : string [ ] = [ ] ;
282+ for ( const entry of readdirSync ( dir , { withFileTypes : true } ) ) {
283+ const relPath = rel ? `${ rel } /${ entry . name } ` : entry . name ;
284+ if ( entry . isDirectory ( ) ) {
285+ // Registry components are source snippets, not independently mounted
286+ // sub-compositions. Linting every installed template here makes an
287+ // unused component fail the assembled project check.
288+ if ( ! rel && entry . name === "components" ) continue ;
289+ out . push ( ...collectHtmlFiles ( join ( dir , entry . name ) , relPath ) ) ;
290+ } else if ( entry . isFile ( ) && entry . name . endsWith ( ".html" ) && ! entry . name . startsWith ( "._" ) ) {
291+ out . push ( relPath ) ;
292+ }
293+ }
294+ return out ;
295+ } ;
296+ const files = collectHtmlFiles ( compositionsDir , "" ) . sort ( ) ;
279297 for ( const file of files ) {
280298 const filePath = join ( compositionsDir , file ) ;
281299 const html = readFileSync ( filePath , "utf-8" ) ;
0 commit comments