Skip to content

Commit 6091f09

Browse files
lpcoxCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 24b3cce commit 6091f09

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/schema-validator.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@
88

99
import Ajv2020, { ErrorObject } from 'ajv/dist/2020';
1010
import * 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+
1431
const 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.

0 commit comments

Comments
 (0)