From 8b943cc97fab890085448122e7c13dd035d0e238 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Dec 2023 00:47:15 -0500 Subject: JSON validation (#394) * Set up JSON testing * Add schema validation * Use parseJson * Finish types * Disambiguate ext/json-schema from node dependency with the same name * Add support for specifying the jsconfig file * Don't expose types * Update types * Use dictionary map type * Fix types * Fix AJV warnings * Move types * Move anb rename file * Move common mocks * Simplify types --- dev/data/manifest-variants.json | 1 - dev/jsconfig.json | 2 +- dev/manifest-util.js | 2 +- dev/schema-validate.js | 2 +- dev/util.js | 8 +++++--- 5 files changed, 8 insertions(+), 7 deletions(-) (limited to 'dev') diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json index ce82d0e3..119b47c2 100644 --- a/dev/data/manifest-variants.json +++ b/dev/data/manifest-variants.json @@ -311,7 +311,6 @@ }, { "name": "safari", - "fileName": null, "modifications": [ { "action": "remove", diff --git a/dev/jsconfig.json b/dev/jsconfig.json index a52153a8..d613e88d 100644 --- a/dev/jsconfig.json +++ b/dev/jsconfig.json @@ -29,7 +29,7 @@ "error": ["../types/ext/error"], "event-listener-collection": ["../types/ext/event-listener-collection"], "japanese-util": ["../types/ext/japanese-util"], - "json-schema": ["../types/ext/json-schema"], + "ext/json-schema": ["../types/ext/json-schema"], "log": ["../types/ext/log"], "settings": ["../types/ext/settings"], "structured-content": ["../types/ext/structured-content"], diff --git a/dev/manifest-util.js b/dev/manifest-util.js index 6a53c8d6..e4487035 100644 --- a/dev/manifest-util.js +++ b/dev/manifest-util.js @@ -121,7 +121,7 @@ export class ManifestUtil { /** * @param {import('dev/manifest').Manifest} manifest - * @param {import('dev/manifest').Modification[]} modifications + * @param {import('dev/manifest').Modification[]|undefined} modifications * @returns {import('dev/manifest').Manifest} */ _applyModifications(manifest, modifications) { diff --git a/dev/schema-validate.js b/dev/schema-validate.js index 57faf96c..d4e977e1 100644 --- a/dev/schema-validate.js +++ b/dev/schema-validate.js @@ -62,6 +62,6 @@ class JsonSchemaAjv { export function createJsonSchema(mode, schema) { switch (mode) { case 'ajv': return new JsonSchemaAjv(schema); - default: return new JsonSchema(/** @type {import('json-schema').Schema} */ (schema)); + default: return new JsonSchema(/** @type {import('ext/json-schema').Schema} */ (schema)); } } diff --git a/dev/util.js b/dev/util.js index 6a7fa8f5..542ad6a2 100644 --- a/dev/util.js +++ b/dev/util.js @@ -72,7 +72,7 @@ export function getArgs(args, argMap) { /** * @param {string} baseDirectory - * @param {?(fileName: string) => boolean} predicate + * @param {?(fileName: string, isDirectory: boolean) => boolean} predicate * @returns {string[]} */ export function getAllFiles(baseDirectory, predicate = null) { @@ -86,11 +86,13 @@ export function getAllFiles(baseDirectory, predicate = null) { const relativeFileName = path.relative(baseDirectory, fullFileName); const stats = fs.lstatSync(fullFileName); if (stats.isFile()) { - if (typeof predicate !== 'function' || predicate(relativeFileName)) { + if (typeof predicate !== 'function' || predicate(relativeFileName, false)) { results.push(relativeFileName); } } else if (stats.isDirectory()) { - directories.push(fullFileName); + if (typeof predicate !== 'function' || predicate(relativeFileName, true)) { + directories.push(fullFileName); + } } } } -- cgit v1.2.3