From 0830dcb05ee3097b3df3cb4f6d0aff253ee1a2a6 Mon Sep 17 00:00:00 2001 From: Anton Stoychev Date: Fri, 6 Dec 2024 08:25:29 +0200 Subject: [PATCH] fix: don't crash if schema cache directories already exist (#365) * fix: don't crash if schema cache directories already exist * Create five-dodos-cheat.md --------- Co-authored-by: Yosuke Ota --- .changeset/five-dodos-cheat.md | 5 +++++ src/utils/schema.ts | 16 +--------------- 2 files changed, 6 insertions(+), 15 deletions(-) create mode 100644 .changeset/five-dodos-cheat.md 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 */