@apidevtools/json-schema-ref-parser 15.1.1 → 15.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,7 +35,7 @@ export default {
35
35
  try {
36
36
  return yaml.load(data, { schema: JSON_SCHEMA });
37
37
  }
38
- catch (e) {
38
+ catch {
39
39
  try {
40
40
  // fallback to non JSON_SCHEMA
41
41
  return yaml.load(data);
@@ -1,4 +1,3 @@
1
- import fs from "fs";
2
1
  import * as url from "../util/url.js";
3
2
  import { ResolverError } from "../util/errors.js";
4
3
  export default {
@@ -19,6 +18,7 @@ export default {
19
18
  */
20
19
  async read(file) {
21
20
  let path;
21
+ const fs = await import("fs");
22
22
  try {
23
23
  path = url.toFileSystemPath(file.url);
24
24
  }
@@ -1,8 +1,8 @@
1
- import path from "path";
1
+ const win32Sep = "\\";
2
2
  export default function convertPathToPosix(filePath) {
3
3
  const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
4
4
  if (isExtendedLengthPath) {
5
5
  return filePath;
6
6
  }
7
- return filePath.split(path?.win32?.sep).join(path?.posix?.sep ?? "/");
7
+ return filePath.split(win32Sep).join("/");
8
8
  }
@@ -25,14 +25,14 @@ export declare function getProtocol(path: string | undefined): string | undefine
25
25
  * @param path
26
26
  * @returns
27
27
  */
28
- export declare function getExtension(path: any): any;
28
+ export declare function getExtension(path: string): string;
29
29
  /**
30
30
  * Removes the query, if any, from the given path.
31
31
  *
32
32
  * @param path
33
33
  * @returns
34
34
  */
35
- export declare function stripQuery(path: any): any;
35
+ export declare function stripQuery(path: string): string;
36
36
  /**
37
37
  * Returns the hash (URL fragment), of the given path.
38
38
  * If there is no hash, then the root hash ("#") is returned.
@@ -47,7 +47,7 @@ export declare function getHash(path: undefined | string): string;
47
47
  * @param path
48
48
  * @returns
49
49
  */
50
- export declare function stripHash(path?: string | undefined): string;
50
+ export declare function stripHash(path: string | undefined): string;
51
51
  /**
52
52
  * Determines whether the given path is an HTTP(S) URL.
53
53
  *
@@ -98,4 +98,3 @@ export declare function toFileSystemPath(path: string | undefined, keepFileProto
98
98
  * @returns
99
99
  */
100
100
  export declare function safePointerToPath(pointer: string): string[];
101
- export declare function relative(from: string, to: string): string;
@@ -1,11 +1,10 @@
1
1
  import convertPathToPosix from "./convert-path-to-posix.js";
2
- import path, { win32 } from "path";
3
2
  const forwardSlashPattern = /\//g;
4
3
  const protocolPattern = /^(\w{2,}):\/\//i;
5
4
  const jsonPointerSlash = /~1/g;
6
5
  const jsonPointerTilde = /~0/g;
7
- import { join } from "path";
8
6
  import { isWindows } from "./is-windows.js";
7
+ const isAbsoluteWin32Path = /^[a-zA-Z]:\\/;
9
8
  // RegExp patterns to URL-encode special characters in local filesystem paths
10
9
  const urlEncodePatterns = [
11
10
  [/\?/g, "%3F"],
@@ -351,11 +350,19 @@ export function fromFileSystemPath(path) {
351
350
  const posixUpper = projectDirPosixPath.toUpperCase();
352
351
  const hasProjectDir = upperPath.includes(posixUpper);
353
352
  const hasProjectUri = upperPath.includes(posixUpper);
354
- const isAbsolutePath = win32?.isAbsolute(path) ||
353
+ const isAbsolutePath = isAbsoluteWin32Path.test(path) ||
355
354
  path.startsWith("http://") ||
356
355
  path.startsWith("https://") ||
357
356
  path.startsWith("file://");
358
357
  if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
358
+ const join = (a, b) => {
359
+ if (a.endsWith("/") || a.endsWith("\\")) {
360
+ return a + b;
361
+ }
362
+ else {
363
+ return a + "/" + b;
364
+ }
365
+ };
359
366
  path = join(projectDir, path);
360
367
  }
361
368
  path = convertPathToPosix(path);
@@ -432,12 +439,3 @@ export function safePointerToPath(pointer) {
432
439
  return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
433
440
  });
434
441
  }
435
- export function relative(from, to) {
436
- if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
437
- return resolve(from, to);
438
- }
439
- const fromDir = path.dirname(stripHash(from));
440
- const toPath = stripHash(to);
441
- const result = path.relative(fromDir, toPath);
442
- return result + getHash(to);
443
- }
@@ -41,7 +41,7 @@ export default {
41
41
  if (typeof data === "string") {
42
42
  try {
43
43
  return yaml.load(data, { schema: JSON_SCHEMA });
44
- } catch (e: any) {
44
+ } catch {
45
45
  try {
46
46
  // fallback to non JSON_SCHEMA
47
47
  return yaml.load(data);
@@ -1,4 +1,3 @@
1
- import fs from "fs";
2
1
  import * as url from "../util/url.js";
3
2
  import { ResolverError } from "../util/errors.js";
4
3
  import type { JSONSchema, ResolverOptions } from "../types/index.js";
@@ -24,6 +23,7 @@ export default {
24
23
  */
25
24
  async read(file: FileInfo): Promise<Buffer> {
26
25
  let path: string | undefined;
26
+ const fs = await import("fs");
27
27
  try {
28
28
  path = url.toFileSystemPath(file.url);
29
29
  } catch (err: any) {
@@ -1,5 +1,4 @@
1
- import path from "path";
2
-
1
+ const win32Sep = "\\";
3
2
  export default function convertPathToPosix(filePath: string) {
4
3
  const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
5
4
 
@@ -7,5 +6,5 @@ export default function convertPathToPosix(filePath: string) {
7
6
  return filePath;
8
7
  }
9
8
 
10
- return filePath.split(path?.win32?.sep).join(path?.posix?.sep ?? "/");
9
+ return filePath.split(win32Sep).join("/");
11
10
  }
package/lib/util/url.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import convertPathToPosix from "./convert-path-to-posix.js";
2
- import path, { win32 } from "path";
3
2
 
4
3
  const forwardSlashPattern = /\//g;
5
4
  const protocolPattern = /^(\w{2,}):\/\//i;
6
5
  const jsonPointerSlash = /~1/g;
7
6
  const jsonPointerTilde = /~0/g;
8
7
 
9
- import { join } from "path";
10
8
  import { isWindows } from "./is-windows.js";
11
9
 
10
+ const isAbsoluteWin32Path = /^[a-zA-Z]:\\/;
11
+
12
12
  // RegExp patterns to URL-encode special characters in local filesystem paths
13
13
  const urlEncodePatterns = [
14
14
  [/\?/g, "%3F"],
@@ -98,7 +98,7 @@ export function getProtocol(path: string | undefined) {
98
98
  * @param path
99
99
  * @returns
100
100
  */
101
- export function getExtension(path: any) {
101
+ export function getExtension(path: string) {
102
102
  const lastDot = path.lastIndexOf(".");
103
103
  if (lastDot >= 0) {
104
104
  return stripQuery(path.substring(lastDot).toLowerCase());
@@ -112,7 +112,7 @@ export function getExtension(path: any) {
112
112
  * @param path
113
113
  * @returns
114
114
  */
115
- export function stripQuery(path: any) {
115
+ export function stripQuery(path: string) {
116
116
  const queryIndex = path.indexOf("?");
117
117
  if (queryIndex >= 0) {
118
118
  path = path.substring(0, queryIndex);
@@ -144,7 +144,7 @@ export function getHash(path: undefined | string) {
144
144
  * @param path
145
145
  * @returns
146
146
  */
147
- export function stripHash(path?: string | undefined) {
147
+ export function stripHash(path: string | undefined) {
148
148
  if (!path) {
149
149
  return "";
150
150
  }
@@ -391,12 +391,19 @@ export function fromFileSystemPath(path: string) {
391
391
  const hasProjectDir = upperPath.includes(posixUpper);
392
392
  const hasProjectUri = upperPath.includes(posixUpper);
393
393
  const isAbsolutePath =
394
- win32?.isAbsolute(path) ||
394
+ isAbsoluteWin32Path.test(path) ||
395
395
  path.startsWith("http://") ||
396
396
  path.startsWith("https://") ||
397
397
  path.startsWith("file://");
398
398
 
399
399
  if (!(hasProjectDir || hasProjectUri || isAbsolutePath) && !projectDir.startsWith("http")) {
400
+ const join = (a: string, b: string) => {
401
+ if (a.endsWith("/") || a.endsWith("\\")) {
402
+ return a + b;
403
+ } else {
404
+ return a + "/" + b;
405
+ }
406
+ };
400
407
  path = join(projectDir, path);
401
408
  }
402
409
  path = convertPathToPosix(path);
@@ -485,15 +492,3 @@ export function safePointerToPath(pointer: string) {
485
492
  return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
486
493
  });
487
494
  }
488
-
489
- export function relative(from: string, to: string) {
490
- if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
491
- return resolve(from, to);
492
- }
493
-
494
- const fromDir = path.dirname(stripHash(from));
495
- const toPath = stripHash(to);
496
-
497
- const result = path.relative(fromDir, toPath);
498
- return result + getHash(to);
499
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "15.1.1",
3
+ "version": "15.1.3",
4
4
  "description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
5
5
  "type": "module",
6
6
  "types": "dist/lib/index.d.ts",
@@ -72,18 +72,18 @@
72
72
  "@types/json-schema": "^7.0.15"
73
73
  },
74
74
  "dependencies": {
75
- "js-yaml": "^4.1.0"
75
+ "js-yaml": "^4.1.1"
76
76
  },
77
77
  "devDependencies": {
78
- "@eslint/compat": "^1.4.1",
78
+ "@eslint/compat": "^2.0.0",
79
79
  "@eslint/js": "^9.39.1",
80
80
  "@types/eslint": "^9.6.1",
81
81
  "@types/js-yaml": "^4.0.9",
82
82
  "@types/json-schema": "^7.0.15",
83
83
  "@types/node": "^24",
84
- "@typescript-eslint/eslint-plugin": "^8.46.4",
85
- "@typescript-eslint/parser": "^8.46.4",
86
- "@vitest/coverage-v8": "^4.0.8",
84
+ "@typescript-eslint/eslint-plugin": "^8.48.0",
85
+ "@typescript-eslint/parser": "^8.48.0",
86
+ "@vitest/coverage-v8": "^4.0.14",
87
87
  "cross-env": "^10.1.0",
88
88
  "eslint": "^9.39.1",
89
89
  "eslint-config-prettier": "^10.1.8",
@@ -92,12 +92,12 @@
92
92
  "eslint-plugin-promise": "^7.2.1",
93
93
  "eslint-plugin-unused-imports": "^4.3.0",
94
94
  "globals": "^16.5.0",
95
- "jsdom": "^27.1.0",
96
- "prettier": "^3.6.2",
97
- "rimraf": "^6.1.0",
95
+ "jsdom": "^27.2.0",
96
+ "prettier": "^3.7.3",
97
+ "rimraf": "^6.1.2",
98
98
  "typescript": "^5.9.3",
99
- "typescript-eslint": "^8.46.4",
100
- "vitest": "^4.0.8"
99
+ "typescript-eslint": "^8.48.0",
100
+ "vitest": "^4.0.14"
101
101
  },
102
102
  "release": {
103
103
  "branches": [
@@ -110,5 +110,5 @@
110
110
  "@semantic-release/github"
111
111
  ]
112
112
  },
113
- "packageManager": "yarn@4.11.0"
113
+ "packageManager": "yarn@4.12.0"
114
114
  }