@@ -40,6 +40,7 @@ import {
4040 lintVideoMediaStartPastEof ,
4141} from "./hevcPreviewLint.js" ;
4242import { lintHyperframeHtml } from "./hyperframeLinter.js" ;
43+ import { extractFontFaceFamilies } from "./rules/fonts.js" ;
4344import { lintProjectShaderScripts } from "./projectShaders.js" ;
4445import type {
4546 HyperframeLintFinding ,
@@ -198,6 +199,41 @@ function resolveCssAssetCandidates(
198199 return resolveLocalAssetCandidates ( projectDir , url ) ;
199200}
200201
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+ }
216+ }
217+ return out ;
218+ } ;
219+ return walk ( compositionsDir , "" ) . sort ( ) ;
220+ }
221+
222+ function declaredProjectFontFamilies ( projectDir : string , sources : HtmlSource [ ] ) : string [ ] {
223+ const families = new Set < string > ( ) ;
224+ for ( const { html, compSrcPath } of sources ) {
225+ const { document } = parseHTML ( html ) ;
226+ const styles = [
227+ ...querySelectorAllIncludingTemplates ( document , "style" ) . map ( ( style ) => ( {
228+ content : style . textContent ?? "" ,
229+ } ) ) ,
230+ ...collectLocalStylesheets ( projectDir , document , compSrcPath ) ,
231+ ] ;
232+ for ( const family of extractFontFaceFamilies ( styles ) ) families . add ( family ) ;
233+ }
234+ return [ ...families ] ;
235+ }
236+
201237export async function lintProject (
202238 projectDir : string ,
203239 entryFile ?: string ,
@@ -215,37 +251,31 @@ export async function lintProject(
215251 let totalInfos = 0 ;
216252
217253 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+ ] ) ;
218264 const rootResult = await lintHyperframeHtml ( rootHtml , {
219265 ...hostOptions ,
220266 filePath : indexPath ,
221267 compSrcPath : rootFile ,
222268 externalStyles : collectExternalStyles ( projectDir , rootHtml , rootCompSrcPath ) ,
269+ projectFontFamilies,
223270 } ) ;
224271 results . push ( { file : rootFile , result : rootResult , contentHash : contentDigest ( rootHtml ) } ) ;
225272 totalErrors += rootResult . errorCount ;
226273 totalWarnings += rootResult . warningCount ;
227274 totalInfos += rootResult . infoCount ;
228275
229276 const allHtmlSources : HtmlSource [ ] = [ { html : rootHtml , compSrcPath : rootCompSrcPath } ] ;
230- const compositionsDir = resolve ( projectDir , "compositions" ) ;
231- if ( ! entryFile && existsSync ( compositionsDir ) ) {
232- const collectHtmlFiles = ( dir : string , rel : string ) : string [ ] => {
233- const out : string [ ] = [ ] ;
234- for ( const entry of readdirSync ( dir , { withFileTypes : true } ) ) {
235- const relPath = rel ? `${ rel } /${ entry . name } ` : entry . name ;
236- if ( entry . isDirectory ( ) ) {
237- // Registry components are source snippets, not independently mounted
238- // sub-compositions. Linting every installed template here makes an
239- // unused component fail the assembled project check.
240- if ( ! rel && entry . name === "components" ) continue ;
241- out . push ( ...collectHtmlFiles ( join ( dir , entry . name ) , relPath ) ) ;
242- } else if ( entry . isFile ( ) && entry . name . endsWith ( ".html" ) && ! entry . name . startsWith ( "._" ) ) {
243- out . push ( relPath ) ;
244- }
245- }
246- return out ;
247- } ;
248- const files = collectHtmlFiles ( compositionsDir , "" ) . sort ( ) ;
277+ if ( compositionFiles . length > 0 ) {
278+ const files = compositionFiles ;
249279 for ( const file of files ) {
250280 const filePath = join ( compositionsDir , file ) ;
251281 const html = readFileSync ( filePath , "utf-8" ) ;
@@ -262,6 +292,7 @@ export async function lintProject(
262292 isSubComposition : true ,
263293 compSrcPath,
264294 externalStyles : collectExternalStyles ( projectDir , html , compSrcPath ) ,
295+ projectFontFamilies,
265296 } ) ;
266297 results . push ( {
267298 file : `compositions/${ file } ` ,
0 commit comments