Skip to content

Commit

Permalink
fix: don't crash if schema cache directories already exist (#365)
Browse files Browse the repository at this point in the history
* fix: don't crash if schema cache directories already exist

* Create five-dodos-cheat.md

---------

Co-authored-by: Yosuke Ota <[email protected]>
  • Loading branch information
antitoxic and ota-meshi authored Dec 6, 2024
1 parent 40ea781 commit 0830dcb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-dodos-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-json-schema-validator": patch
---

fix: don't crash if schema cache directories already exist
16 changes: 1 addition & 15 deletions src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function loadJsonFromURL<T>(
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 {
Expand Down Expand Up @@ -211,20 +211,6 @@ function postProcess<T>(
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
*/
Expand Down

0 comments on commit 0830dcb

Please sign in to comment.