eslint-plugin-json-schema-validator
Advanced tools
Comparing version 3.2.8 to 4.0.0
@@ -15,3 +15,4 @@ "use strict"; | ||
const validator_factory_1 = require("../utils/validator-factory"); | ||
const node_fs_1 = __importDefault(require("node:fs")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const CATALOG_URL = "https://www.schemastore.org/api/json/catalog.json"; | ||
function matchFile(filename, fileMatch) { | ||
@@ -51,3 +52,3 @@ return (fileMatch.includes(path_1.default.basename(filename)) || | ||
if (option.useSchemastoreCatalog !== false) { | ||
const catalog = require("../../schemastore/www.schemastore.org/api/json/catalog.json"); | ||
const catalog = (0, schema_1.loadJson)(CATALOG_URL, context); | ||
const schemas = catalog.schemas; | ||
@@ -346,3 +347,3 @@ for (const schemaData of schemas) { | ||
try { | ||
if (node_fs_1.default.statSync(filename).isDirectory()) { | ||
if (fs_1.default.statSync(filename).isDirectory()) { | ||
return child || filename; | ||
@@ -349,0 +350,0 @@ } |
import type { RuleContext } from "../types"; | ||
import type { SchemaObject } from "./types"; | ||
export declare function urlToSchemastoreFilePath(url: string): string | null; | ||
export declare function loadSchema(schemaPath: string, context: RuleContext): null | SchemaObject; | ||
export declare function loadJson<T = any>(jsonPath: string, context: RuleContext): null | T; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadSchema = exports.urlToSchemastoreFilePath = void 0; | ||
exports.loadJson = exports.loadSchema = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
@@ -16,39 +16,28 @@ const fs_1 = __importDefault(require("fs")); | ||
const RELOADING = new Set(); | ||
function urlToSchemastoreFilePath(url) { | ||
if (/^https?:\/\/json\.schemastore\.org\//u.test(url)) { | ||
const jsonPath = url.replace(/^https?:\/\//u, ""); | ||
if (jsonPath.endsWith(".json")) { | ||
return jsonPath; | ||
} | ||
return `${jsonPath}.json`; | ||
} | ||
return null; | ||
function loadSchema(schemaPath, context) { | ||
return loadJsonInternal(schemaPath, context, (schema) => { | ||
(0, json_schema_migrate_1.draft7)(schema); | ||
return schema; | ||
}); | ||
} | ||
exports.urlToSchemastoreFilePath = urlToSchemastoreFilePath; | ||
function loadSchema(schemaPath, context) { | ||
if (schemaPath.startsWith("http://") || schemaPath.startsWith("https://")) { | ||
const jsonPath = urlToSchemastoreFilePath(schemaPath); | ||
if (!jsonPath) { | ||
return loadSchemaFromURL(schemaPath, context); | ||
} | ||
try { | ||
return require(`../../schemastore/${jsonPath}`); | ||
} | ||
catch (_a) { | ||
} | ||
return loadSchemaFromURL(schemaPath, context); | ||
exports.loadSchema = loadSchema; | ||
function loadJson(jsonPath, context) { | ||
return loadJsonInternal(jsonPath, context); | ||
} | ||
exports.loadJson = loadJson; | ||
function loadJsonInternal(jsonPath, context, edit) { | ||
if (jsonPath.startsWith("http://") || jsonPath.startsWith("https://")) { | ||
return loadJsonFromURL(jsonPath, context, edit); | ||
} | ||
const json = fs_1.default.readFileSync(path_1.default.resolve(getCwd(context), schemaPath), "utf-8"); | ||
const schema = JSON.parse(json); | ||
(0, json_schema_migrate_1.draft7)(schema); | ||
return schema; | ||
const json = fs_1.default.readFileSync(path_1.default.resolve(getCwd(context), jsonPath), "utf-8"); | ||
const data = JSON.parse(json); | ||
return edit ? edit(data) : data; | ||
} | ||
exports.loadSchema = loadSchema; | ||
function loadSchemaFromURL(schemaUrl, context) { | ||
function loadJsonFromURL(jsonPath, context, edit) { | ||
var _a, _b, _c; | ||
let jsonPath = schemaUrl.replace(/^https?:\/\//u, ""); | ||
if (!jsonPath.endsWith(".json")) { | ||
jsonPath = `${jsonPath}.json`; | ||
let jsonFileName = jsonPath.replace(/^https?:\/\//u, ""); | ||
if (!jsonFileName.endsWith(".json")) { | ||
jsonFileName = `${jsonFileName}.json`; | ||
} | ||
const jsonFilePath = path_1.default.join(__dirname, `../../.cached_schemastore/${jsonPath}`); | ||
const jsonFilePath = path_1.default.join(__dirname, `../../.cached_schemastore/${jsonFileName}`); | ||
const options = (_b = (_a = context.settings) === null || _a === void 0 ? void 0 : _a["json-schema-validator"]) === null || _b === void 0 ? void 0 : _b.http; | ||
@@ -58,20 +47,25 @@ const httpRequestOptions = (_c = options === null || options === void 0 ? void 0 : options.requestOptions) !== null && _c !== void 0 ? _c : {}; | ||
makeDirs(path_1.default.dirname(jsonFilePath)); | ||
if (fs_1.default.existsSync(jsonFilePath)) { | ||
const { schema, timestamp } = require(jsonFilePath); | ||
if (schema != null && typeof timestamp === "number") { | ||
if (timestamp + TTL < Date.now()) { | ||
if (!RELOADING.has(schemaUrl)) { | ||
RELOADING.add(schemaUrl); | ||
(0, http_client_1.get)(schemaUrl, httpRequestOptions, httpGetModulePath).then((json) => { | ||
postProcess(schemaUrl, jsonFilePath, json, context); | ||
RELOADING.delete(schemaUrl); | ||
}); | ||
} | ||
let data, timestamp; | ||
try { | ||
; | ||
({ data, timestamp } = | ||
require(`../../.cached_schemastore/${jsonFileName}`)); | ||
} | ||
catch (_d) { | ||
} | ||
if (data != null && typeof timestamp === "number") { | ||
if (timestamp + TTL < Date.now()) { | ||
if (!RELOADING.has(jsonFilePath)) { | ||
RELOADING.add(jsonFilePath); | ||
(0, http_client_1.get)(jsonPath, httpRequestOptions, httpGetModulePath).then((json) => { | ||
postProcess(jsonPath, jsonFilePath, json, context, edit); | ||
RELOADING.delete(jsonFilePath); | ||
}); | ||
} | ||
return schema; | ||
} | ||
return data; | ||
} | ||
let json; | ||
try { | ||
json = (0, http_client_1.syncGet)(schemaUrl, httpRequestOptions, httpGetModulePath); | ||
json = (0, http_client_1.syncGet)(jsonPath, httpRequestOptions, httpGetModulePath); | ||
} | ||
@@ -82,8 +76,8 @@ catch (e) { | ||
} | ||
return postProcess(schemaUrl, jsonFilePath, json, context); | ||
return postProcess(jsonPath, jsonFilePath, json, context, edit); | ||
} | ||
function postProcess(schemaUrl, jsonFilePath, json, context) { | ||
let schema; | ||
function postProcess(schemaUrl, jsonFilePath, json, context, edit) { | ||
let data; | ||
try { | ||
schema = JSON.parse(json); | ||
data = JSON.parse(json); | ||
} | ||
@@ -97,5 +91,7 @@ catch (_a) { | ||
} | ||
(0, json_schema_migrate_1.draft7)(schema); | ||
if (edit) { | ||
data = edit(data); | ||
} | ||
fs_1.default.writeFileSync(jsonFilePath, schemaStringify({ | ||
schema, | ||
data, | ||
timestamp: Date.now(), | ||
@@ -105,3 +101,3 @@ v: require("../../package.json").version, | ||
delete require.cache[jsonFilePath]; | ||
return schema; | ||
return data; | ||
} | ||
@@ -108,0 +104,0 @@ function makeDirs(dir) { |
{ | ||
"name": "eslint-plugin-json-schema-validator", | ||
"version": "3.2.8", | ||
"version": "4.0.0", | ||
"description": "ESLint plugin that validates data using JSON Schema Validator.", | ||
@@ -11,8 +11,7 @@ "repository": "git+https://github.com/ota-meshi/eslint-plugin-json-schema-validator.git", | ||
"engines": { | ||
"node": "^14.17.0 || >=16.0.0" | ||
"node": "^14.18.0 || >=16.0.0" | ||
}, | ||
"main": "lib/index.js", | ||
"files": [ | ||
"lib", | ||
"schemastore" | ||
"lib" | ||
], | ||
@@ -42,8 +41,5 @@ "keywords": [ | ||
"preversion": "yarn test && git add .", | ||
"re-migrate": "yarn ts tools/update-schemastore/re-migrate", | ||
"test": "env-cmd -e test yarn mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000", | ||
"ts": "node -r esbuild-register", | ||
"update": "yarn ts ./tools/update && yarn lint-fix", | ||
"update:schemastore": "yarn ts tools/update-schemastore", | ||
"update:schemastore-only": "yarn ts tools/update-schemastore/only", | ||
"version": "env-cmd -e version yarn update && git add ." | ||
@@ -61,3 +57,3 @@ }, | ||
"minimatch": "^5.0.0", | ||
"synckit": "^0.7.1", | ||
"synckit": "^0.8.0", | ||
"toml-eslint-parser": "^0.4.0", | ||
@@ -97,3 +93,2 @@ "tunnel-agent": "^0.6.0", | ||
"eslint-plugin-yml": "^1.0.0", | ||
"eslint4b": "^7.3.1", | ||
"espree": "^9.0.0", | ||
@@ -116,4 +111,5 @@ "mocha": "^10.0.0", | ||
"vue-eslint-parser": "^9.0.0", | ||
"vuepress": "^1.5.2" | ||
"vuepress": "^1.5.2", | ||
"yaml": "^2.1.1" | ||
} | ||
} |
@@ -233,4 +233,2 @@ # Introduction | ||
The JSON Schema included in this plugin release is copy from [SchemaStore]. Check [here](https://github.com/ota-meshi/eslint-plugin-json-schema-validator/blob/main/schemastore/README.md) for licenses and details. | ||
[SchemaStore]: https://github.com/SchemaStore/schemastore | ||
@@ -237,0 +235,0 @@ [JSON]: https://json.org/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
99053
51
2304
240
+ Added@pkgr/core@0.1.1(transitive)
+ Addedsynckit@0.8.8(transitive)
- Removed@pkgr/utils@2.4.2(transitive)
- Removedbig-integer@1.6.52(transitive)
- Removedbplist-parser@0.2.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedbundle-name@3.0.0(transitive)
- Removeddefault-browser@4.0.0(transitive)
- Removeddefault-browser-id@3.0.0(transitive)
- Removeddefine-lazy-prop@3.0.0(transitive)
- Removedexeca@5.1.17.2.0(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedhuman-signals@2.1.04.3.1(transitive)
- Removedis-docker@2.2.13.0.0(transitive)
- Removedis-inside-container@1.0.0(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-stream@2.0.13.0.0(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedmimic-fn@2.1.04.0.0(transitive)
- Removednpm-run-path@4.0.15.3.0(transitive)
- Removedonetime@5.1.26.0.0(transitive)
- Removedopen@9.1.0(transitive)
- Removedpath-key@4.0.0(transitive)
- Removedpicocolors@1.1.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedrun-applescript@5.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.03.0.0(transitive)
- Removedsynckit@0.7.3(transitive)
- Removedtitleize@3.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removeduntildify@4.0.0(transitive)
Updatedsynckit@^0.8.0