diff --git a/.changeset/five-dodos-cheat.md b/.changeset/five-dodos-cheat.md new file mode 100644 index 00000000..39b81f39 --- /dev/null +++ b/.changeset/five-dodos-cheat.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-json-schema-validator": patch +--- + +fix: don't crash if schema cache directories already exist diff --git a/src/utils/schema.ts b/src/utils/schema.ts index 9075ca0f..2c9ca01c 100644 --- a/src/utils/schema.ts +++ b/src/utils/schema.ts @@ -127,7 +127,7 @@ function loadJsonFromURL( const httpRequestOptions = options?.requestOptions ?? {}; const httpGetModulePath = resolvePath(options?.getModulePath, context); - makeDirs(path.dirname(jsonFilePath)); + fs.mkdirSync(path.dirname(jsonFilePath), { recursive: true }); let data, timestamp; try { @@ -211,20 +211,6 @@ function postProcess( return data; } -/** - * Make directories - */ -function makeDirs(dir: string) { - const dirs = [dir]; - while (!fs.existsSync(dirs[0])) { - dirs.unshift(path.dirname(dirs[0])); - } - dirs.shift(); - for (const dir of dirs) { - fs.mkdirSync(dir); - } -} - /** * JSON Schema to string */