11import path from 'node:path'
2- import { canonicalJson } from '#design-diff/ast'
3- import { compareDefinitions , finding } from '#design-diff/compare'
2+ import { finding } from '#design-diff/compare'
43import { Resolver } from '#design-diff/resolve'
54import type { SourceTree } from '#design-diff/source'
6- import type { Change , Config , Data , Definition } from '#design-diff/types'
5+ import type { Change , Config } from '#design-diff/types'
76
8- /** Explicit file-loading conventions are data edges, never runtime filesystem reads. */
9- export function fileLoadedInputs ( before : SourceTree , after : SourceTree , config : Config ) : Change [ ] {
10- const read = (
11- tree : SourceTree ,
12- input : NonNullable < Config [ 'fileInputs' ] > [ number ]
13- ) : Definition [ ] => {
14- if ( ! tree . entries . has ( input . list ) && ! tree . entries . has ( input . renderer ) ) return [ ]
15- const definitions : Definition [ ] = [ ]
16- const emit = ( file : string , value : Data , unresolved : string [ ] = [ ] ) =>
17- definitions . push ( {
18- key : file ,
19- kind : unresolved . length ? 'review' : 'content' ,
20- property : 'file-loaded-documentation' ,
21- value,
22- location : { file, line : 1 , column : 1 } ,
23- symbol : input . export ,
24- conditions : [ { renderer : input . renderer , list : input . list } ] ,
25- dependencies : [ file , input . list , input . renderer ] ,
26- unresolved,
27- } )
7+ /** Content never qualifies; validate current file-loaded documentation only for coverage notes. */
8+ export function fileLoadedInputDiagnostics ( tree : SourceTree , config : Config ) : Change [ ] {
9+ const diagnostics = new Map < string , Change > ( )
10+ for ( const input of config . fileInputs ?? [ ] ) {
11+ if ( ! tree . entries . has ( input . list ) && ! tree . entries . has ( input . renderer ) ) continue
12+ const emit = ( file : string , reason : string ) => {
13+ if ( diagnostics . has ( file ) ) return
14+ diagnostics . set (
15+ file ,
16+ finding ( undefined , {
17+ key : file ,
18+ kind : 'review' ,
19+ property : 'file-loaded-documentation' ,
20+ value : tree . entries . get ( file ) ?. oid ?? 'missing' ,
21+ location : { file, line : 1 , column : 1 } ,
22+ symbol : input . export ,
23+ conditions : [ { renderer : input . renderer , list : input . list } ] ,
24+ dependencies : [ file , input . list , input . renderer ] ,
25+ unresolved : [ reason ] ,
26+ } )
27+ )
28+ }
2829 try {
2930 const resolver = new Resolver ( tree )
3031 const exported = resolver . module ( input . list ) . exports . get ( input . export )
@@ -37,36 +38,22 @@ export function fileLoadedInputs(before: SourceTree, after: SourceTree, config:
3738 ! evidence . value . every ( ( file ) => typeof file === 'string' )
3839 )
3940 throw new Error ( 'Configured input list is not a static string array' )
40- if ( ! input . contentOnly ) emit ( input . list , evidence . value )
4141 for ( const name of evidence . value as string [ ] ) {
4242 const file = path . posix . normalize ( path . posix . join ( input . root , name ) )
4343 if ( ! file . startsWith ( `${ input . root } /` ) || ! file . endsWith ( '.json' ) )
4444 throw new Error ( 'Unsupported configured input path' )
4545 try {
46- const value = JSON . parse ( tree . texts . get ( file ) ?? '' )
47- if ( ! input . contentOnly ) emit ( file , canonicalJson ( value ) )
46+ JSON . parse ( tree . texts . get ( file ) ?? '' )
4847 } catch {
49- emit ( file , tree . entries . get ( file ) ?. oid ?? 'missing' , [
50- 'Configured documentation JSON is missing, malformed or exceeds the source budget' ,
51- ] )
48+ emit (
49+ file ,
50+ 'Configured documentation JSON is missing, malformed or exceeds the source budget'
51+ )
5252 }
5353 }
5454 } catch {
55- emit ( input . list , tree . entries . get ( input . list ) ?. oid ?? 'missing' , [
56- 'Configured documentation list or renderer could not be resolved' ,
57- ] )
55+ emit ( input . list , 'Configured documentation list or renderer could not be resolved' )
5856 }
59- return definitions
60- }
61- const findings : Change [ ] = [ ]
62- for ( const input of config . fileInputs ?? [ ] ) {
63- const a = read ( before , input )
64- const b = read ( after , input )
65- findings . push ( ...compareDefinitions ( a , b ) )
66- /** Invalid documentation remains an explicit coverage note without notifying the designer. */
67- for ( const definition of b . filter ( ( definition ) => definition . unresolved . length ) )
68- if ( ! findings . some ( ( finding ) => finding . after ?. location . file === definition . location . file ) )
69- findings . push ( finding ( undefined , definition ) )
7057 }
71- return findings
58+ return [ ... diagnostics . values ( ) ]
7259}
0 commit comments