File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99import Ajv2020 , { ErrorObject } from 'ajv/dist/2020' ;
1010import * as schema from './awf-config-schema.json' ;
11-
12- // Compile once (module-level singleton). allErrors collects every violation.
11+ function loadSchema ( ) : Record < string , unknown > {
12+ try {
13+ // Keep the local relative require so source execution works and bundlers can still see it.
14+ // eslint-disable-next-line @typescript-eslint/no-require-imports
15+ return require ( './awf-config-schema.json' ) as Record < string , unknown > ;
16+ } catch ( error : unknown ) {
17+ const moduleError = error as { code ?: string } ;
18+ if ( moduleError . code !== 'MODULE_NOT_FOUND' ) {
19+ throw error ;
20+ }
1321// verbose=true provides parentSchema on errors for richer formatting.
22+ // `tsc` does not copy the schema into `dist/`, so compiled JS may need to load
23+ // the original file from `src/` when running directly under Node.js.
24+ // eslint-disable-next-line @typescript-eslint/no-require-imports
25+ return require ( '../src/awf-config-schema.json' ) as Record < string , unknown > ;
26+ }
27+ }
28+
29+ const schema = loadSchema ( ) ;
30+
1431const ajv = new Ajv2020 ( { allErrors : true , verbose : true } ) ;
1532// 'version' is a metadata keyword (not a standard JSON Schema keyword); register
1633// it so Ajv strict mode does not reject the schema.
You can’t perform that action at this time.
0 commit comments