@apidevtools/json-schema-ref-parser 15.1.2 → 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,9 +1,8 @@
1
- import path from "path";
2
1
  const win32Sep = "\\";
3
2
  export default function convertPathToPosix(filePath) {
4
3
  const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
5
4
  if (isExtendedLengthPath) {
6
5
  return filePath;
7
6
  }
8
- return filePath.split(win32Sep).join(path?.posix?.sep ?? "/");
7
+ return filePath.split(win32Sep).join("/");
9
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,10 +1,8 @@
1
1
  import convertPathToPosix from "./convert-path-to-posix.js";
2
- import path 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";
9
7
  const isAbsoluteWin32Path = /^[a-zA-Z]:\\/;
10
8
  // RegExp patterns to URL-encode special characters in local filesystem paths
@@ -357,6 +355,14 @@ export function fromFileSystemPath(path) {
357
355
  path.startsWith("https://") ||
358
356
  path.startsWith("file://");
359
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
+ };
360
366
  path = join(projectDir, path);
361
367
  }
362
368
  path = convertPathToPosix(path);
@@ -433,12 +439,3 @@ export function safePointerToPath(pointer) {
433
439
  return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
434
440
  });
435
441
  }
436
- export function relative(from, to) {
437
- if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
438
- return resolve(from, to);
439
- }
440
- const fromDir = path.dirname(stripHash(from));
441
- const toPath = stripHash(to);
442
- const result = path.relative(fromDir, toPath);
443
- return result + getHash(to);
444
- }
@@ -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,3 @@
1
- import path from "path";
2
-
3
1
  const win32Sep = "\\";
4
2
  export default function convertPathToPosix(filePath: string) {
5
3
  const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
@@ -8,5 +6,5 @@ export default function convertPathToPosix(filePath: string) {
8
6
  return filePath;
9
7
  }
10
8
 
11
- return filePath.split(win32Sep).join(path?.posix?.sep ?? "/");
9
+ return filePath.split(win32Sep).join("/");
12
10
  }
package/lib/util/url.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import convertPathToPosix from "./convert-path-to-posix.js";
2
- import path 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
 
12
10
  const isAbsoluteWin32Path = /^[a-zA-Z]:\\/;
@@ -100,7 +98,7 @@ export function getProtocol(path: string | undefined) {
100
98
  * @param path
101
99
  * @returns
102
100
  */
103
- export function getExtension(path: any) {
101
+ export function getExtension(path: string) {
104
102
  const lastDot = path.lastIndexOf(".");
105
103
  if (lastDot >= 0) {
106
104
  return stripQuery(path.substring(lastDot).toLowerCase());
@@ -114,7 +112,7 @@ export function getExtension(path: any) {
114
112
  * @param path
115
113
  * @returns
116
114
  */
117
- export function stripQuery(path: any) {
115
+ export function stripQuery(path: string) {
118
116
  const queryIndex = path.indexOf("?");
119
117
  if (queryIndex >= 0) {
120
118
  path = path.substring(0, queryIndex);
@@ -146,7 +144,7 @@ export function getHash(path: undefined | string) {
146
144
  * @param path
147
145
  * @returns
148
146
  */
149
- export function stripHash(path?: string | undefined) {
147
+ export function stripHash(path: string | undefined) {
150
148
  if (!path) {
151
149
  return "";
152
150
  }
@@ -399,6 +397,13 @@ export function fromFileSystemPath(path: string) {
399
397
  path.startsWith("file://");
400
398
 
401
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
+ };
402
407
  path = join(projectDir, path);
403
408
  }
404
409
  path = convertPathToPosix(path);
@@ -487,15 +492,3 @@ export function safePointerToPath(pointer: string) {
487
492
  return value.replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
488
493
  });
489
494
  }
490
-
491
- export function relative(from: string, to: string) {
492
- if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
493
- return resolve(from, to);
494
- }
495
-
496
- const fromDir = path.dirname(stripHash(from));
497
- const toPath = stripHash(to);
498
-
499
- const result = path.relative(fromDir, toPath);
500
- return result + getHash(to);
501
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apidevtools/json-schema-ref-parser",
3
- "version": "15.1.2",
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",
@@ -81,9 +81,9 @@
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.9",
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",
@@ -93,11 +93,11 @@
93
93
  "eslint-plugin-unused-imports": "^4.3.0",
94
94
  "globals": "^16.5.0",
95
95
  "jsdom": "^27.2.0",
96
- "prettier": "^3.6.2",
97
- "rimraf": "^6.1.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.9"
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
  }