@apidevtools/json-schema-ref-parser 10.0.1 → 10.1.0
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.
- package/dist/lib/bundle.d.ts +10 -0
- package/dist/lib/bundle.js +265 -0
- package/dist/lib/dereference.d.ts +9 -0
- package/dist/lib/dereference.js +206 -0
- package/dist/lib/index.d.ts +206 -0
- package/dist/lib/index.js +223 -0
- package/dist/lib/normalize-args.d.ts +10 -0
- package/dist/lib/normalize-args.js +42 -0
- package/dist/lib/options.d.ts +77 -0
- package/dist/lib/options.js +119 -0
- package/dist/lib/parse.d.ts +8 -0
- package/dist/lib/parse.js +177 -0
- package/dist/lib/parsers/binary.d.ts +3 -0
- package/dist/lib/parsers/binary.js +35 -0
- package/dist/lib/parsers/json.d.ts +3 -0
- package/dist/lib/parsers/json.js +57 -0
- package/dist/lib/parsers/text.d.ts +3 -0
- package/dist/lib/parsers/text.js +42 -0
- package/dist/lib/parsers/yaml.d.ts +3 -0
- package/dist/lib/parsers/yaml.js +65 -0
- package/dist/lib/pointer.d.ts +87 -0
- package/dist/lib/pointer.js +256 -0
- package/dist/lib/ref.d.ts +181 -0
- package/dist/lib/ref.js +239 -0
- package/dist/lib/refs.d.ts +127 -0
- package/dist/lib/refs.js +223 -0
- package/dist/lib/resolve-external.d.ts +14 -0
- package/dist/lib/resolve-external.js +148 -0
- package/dist/lib/resolvers/file.d.ts +3 -0
- package/dist/lib/resolvers/file.js +76 -0
- package/dist/lib/resolvers/http.d.ts +3 -0
- package/dist/lib/resolvers/http.js +159 -0
- package/dist/lib/types/index.d.ts +104 -0
- package/dist/lib/types/index.js +2 -0
- package/dist/lib/util/errors.d.ts +50 -0
- package/dist/lib/util/errors.js +106 -0
- package/dist/lib/util/maybe.d.ts +3 -0
- package/dist/lib/util/maybe.js +24 -0
- package/dist/lib/util/next.d.ts +2 -0
- package/dist/lib/util/next.js +16 -0
- package/dist/lib/util/plugins.d.ts +36 -0
- package/dist/lib/util/plugins.js +144 -0
- package/dist/lib/util/url.d.ts +93 -0
- package/{cjs → dist/lib}/util/url.js +134 -102
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.js +23 -0
- package/lib/{bundle.js → bundle.ts} +105 -101
- package/lib/{dereference.js → dereference.ts} +113 -52
- package/lib/index.ts +413 -0
- package/lib/{normalize-args.js → normalize-args.ts} +7 -14
- package/lib/options.ts +202 -0
- package/lib/parse.ts +153 -0
- package/lib/parsers/binary.ts +39 -0
- package/lib/parsers/{json.js → json.ts} +9 -22
- package/lib/parsers/text.ts +46 -0
- package/lib/parsers/{yaml.js → yaml.ts} +15 -19
- package/lib/pointer.ts +296 -0
- package/lib/ref.ts +288 -0
- package/lib/refs.ts +238 -0
- package/lib/{resolve-external.js → resolve-external.ts} +39 -36
- package/lib/resolvers/file.ts +40 -0
- package/lib/resolvers/http.ts +136 -0
- package/lib/tsconfig.json +103 -0
- package/lib/types/index.ts +135 -0
- package/lib/util/errors.ts +141 -0
- package/lib/util/maybe.ts +22 -0
- package/lib/util/next.ts +13 -0
- package/lib/util/{plugins.js → plugins.ts} +58 -57
- package/lib/util/{url.js → url.ts} +64 -83
- package/package.json +44 -45
- package/cjs/bundle.js +0 -304
- package/cjs/dereference.js +0 -258
- package/cjs/index.js +0 -603
- package/cjs/normalize-args.js +0 -64
- package/cjs/options.js +0 -125
- package/cjs/package.json +0 -3
- package/cjs/parse.js +0 -338
- package/cjs/parsers/binary.js +0 -54
- package/cjs/parsers/json.js +0 -199
- package/cjs/parsers/text.js +0 -61
- package/cjs/parsers/yaml.js +0 -239
- package/cjs/pointer.js +0 -290
- package/cjs/ref.js +0 -333
- package/cjs/refs.js +0 -214
- package/cjs/resolve-external.js +0 -333
- package/cjs/resolvers/file.js +0 -106
- package/cjs/resolvers/http.js +0 -184
- package/cjs/util/errors.js +0 -401
- package/cjs/util/plugins.js +0 -159
- package/cjs/util/projectDir.cjs +0 -6
- package/lib/index.d.ts +0 -496
- package/lib/index.js +0 -290
- package/lib/options.js +0 -128
- package/lib/parse.js +0 -162
- package/lib/parsers/binary.js +0 -53
- package/lib/parsers/text.js +0 -64
- package/lib/pointer.js +0 -293
- package/lib/ref.js +0 -292
- package/lib/refs.js +0 -196
- package/lib/resolvers/file.js +0 -63
- package/lib/resolvers/http.js +0 -155
- package/lib/util/errors.js +0 -134
- package/lib/util/projectDir.cjs +0 -6
|
@@ -1,48 +1,53 @@
|
|
|
1
|
+
import type { FileInfo } from "../types/index.js";
|
|
2
|
+
import type $RefParserOptions from "../options.js";
|
|
3
|
+
import type { ResolverOptions } from "../types/index.js";
|
|
4
|
+
import type $Refs from "../refs.js";
|
|
5
|
+
import type { Plugin } from "../types/index.js";
|
|
6
|
+
import type { JSONSchema } from "../types/index.js";
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* Returns the given plugins as an array, rather than an object map.
|
|
3
10
|
* All other methods in this module expect an array of plugins rather than an object map.
|
|
4
11
|
*
|
|
5
|
-
* @
|
|
6
|
-
* @return {object[]}
|
|
12
|
+
* @returns
|
|
7
13
|
*/
|
|
8
|
-
export function all
|
|
14
|
+
export function all(plugins: $RefParserOptions["resolve"]): Plugin[] {
|
|
9
15
|
return Object.keys(plugins)
|
|
10
16
|
.filter((key) => {
|
|
11
17
|
return typeof plugins[key] === "object";
|
|
12
18
|
})
|
|
13
19
|
.map((key) => {
|
|
14
|
-
plugins[key]
|
|
15
|
-
return plugins[key];
|
|
20
|
+
(plugins[key] as ResolverOptions)!.name = key;
|
|
21
|
+
return plugins[key] as Plugin;
|
|
16
22
|
});
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* Filters the given plugins, returning only the ones return `true` for the given method.
|
|
21
|
-
*
|
|
22
|
-
* @param {object[]} plugins - An array of plugin objects
|
|
23
|
-
* @param {string} method - The name of the filter method to invoke for each plugin
|
|
24
|
-
* @param {object} file - A file info object, which will be passed to each method
|
|
25
|
-
* @return {object[]}
|
|
26
27
|
*/
|
|
27
|
-
export function filter
|
|
28
|
-
return plugins
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
28
|
+
export function filter(plugins: Plugin[], method: any, file: any) {
|
|
29
|
+
return plugins.filter((plugin: Plugin) => {
|
|
30
|
+
return !!getResult(plugin, method, file);
|
|
31
|
+
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Sorts the given plugins, in place, by their `order` property.
|
|
36
|
-
*
|
|
37
|
-
* @param {object[]} plugins - An array of plugin objects
|
|
38
|
-
* @returns {object[]}
|
|
39
36
|
*/
|
|
40
|
-
export function sort
|
|
41
|
-
for (
|
|
37
|
+
export function sort(plugins: Plugin[]) {
|
|
38
|
+
for (const plugin of plugins) {
|
|
42
39
|
plugin.order = plugin.order || Number.MAX_SAFE_INTEGER;
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
return plugins.sort((a, b) => {
|
|
42
|
+
return plugins.sort((a: any, b: any) => {
|
|
43
|
+
return a.order - b.order;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PluginResult {
|
|
48
|
+
plugin: Plugin;
|
|
49
|
+
result?: string | Buffer | JSONSchema;
|
|
50
|
+
error?: any;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/**
|
|
@@ -52,19 +57,21 @@ export function sort (plugins) {
|
|
|
52
57
|
* is immediately returned and no further plugins are called.
|
|
53
58
|
* If the promise rejects, or the callback is called with an error, then the next plugin is called.
|
|
54
59
|
* If ALL plugins fail, then the last error is thrown.
|
|
55
|
-
*
|
|
56
|
-
* @param {object[]} plugins - An array of plugin objects
|
|
57
|
-
* @param {string} method - The name of the method to invoke for each plugin
|
|
58
|
-
* @param {object} file - A file info object, which will be passed to each method
|
|
59
|
-
* @returns {Promise}
|
|
60
60
|
*/
|
|
61
|
-
export function run
|
|
62
|
-
|
|
61
|
+
export async function run(
|
|
62
|
+
plugins: Plugin[],
|
|
63
|
+
method: keyof Plugin | keyof ResolverOptions,
|
|
64
|
+
file: FileInfo,
|
|
65
|
+
$refs: $Refs,
|
|
66
|
+
) {
|
|
67
|
+
let plugin: Plugin;
|
|
68
|
+
let lastError: PluginResult;
|
|
69
|
+
let index = 0;
|
|
63
70
|
|
|
64
|
-
return new Promise((
|
|
71
|
+
return new Promise<PluginResult>((resolve, reject) => {
|
|
65
72
|
runNextPlugin();
|
|
66
73
|
|
|
67
|
-
function runNextPlugin
|
|
74
|
+
function runNextPlugin() {
|
|
68
75
|
plugin = plugins[index++];
|
|
69
76
|
if (!plugin) {
|
|
70
77
|
// There are no more functions, so re-throw the last error
|
|
@@ -73,42 +80,38 @@ export function run (plugins, method, file, $refs) {
|
|
|
73
80
|
|
|
74
81
|
try {
|
|
75
82
|
// console.log(' %s', plugin.name);
|
|
76
|
-
|
|
83
|
+
const result = getResult(plugin, method, file, callback, $refs);
|
|
77
84
|
if (result && typeof result.then === "function") {
|
|
78
85
|
// A promise was returned
|
|
79
86
|
result.then(onSuccess, onError);
|
|
80
|
-
}
|
|
81
|
-
else if (result !== undefined) {
|
|
87
|
+
} else if (result !== undefined) {
|
|
82
88
|
// A synchronous result was returned
|
|
83
89
|
onSuccess(result);
|
|
84
|
-
}
|
|
85
|
-
else if (index === plugins.length) {
|
|
90
|
+
} else if (index === plugins.length) {
|
|
86
91
|
throw new Error("No promise has been returned or callback has been called.");
|
|
87
92
|
}
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
93
|
+
} catch (e) {
|
|
90
94
|
onError(e);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
function callback
|
|
98
|
+
function callback(err: PluginResult["error"], result: PluginResult["result"]) {
|
|
95
99
|
if (err) {
|
|
96
100
|
onError(err);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
101
|
+
} else {
|
|
99
102
|
onSuccess(result);
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
function onSuccess
|
|
106
|
+
function onSuccess(result: PluginResult["result"]) {
|
|
104
107
|
// console.log(' success');
|
|
105
108
|
resolve({
|
|
106
109
|
plugin,
|
|
107
|
-
result
|
|
110
|
+
result,
|
|
108
111
|
});
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
function onError
|
|
114
|
+
function onError(error: PluginResult["error"]) {
|
|
112
115
|
// console.log(' %s', err.message || err);
|
|
113
116
|
lastError = {
|
|
114
117
|
plugin,
|
|
@@ -116,23 +119,23 @@ export function run (plugins, method, file, $refs) {
|
|
|
116
119
|
};
|
|
117
120
|
runNextPlugin();
|
|
118
121
|
}
|
|
119
|
-
})
|
|
122
|
+
});
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
/**
|
|
123
126
|
* Returns the value of the given property.
|
|
124
127
|
* If the property is a function, then the result of the function is returned.
|
|
125
128
|
* If the value is a RegExp, then it will be tested against the file URL.
|
|
126
|
-
* If the value is an
|
|
127
|
-
*
|
|
128
|
-
* @param {object} obj - The object whose property/method is called
|
|
129
|
-
* @param {string} prop - The name of the property/method to invoke
|
|
130
|
-
* @param {object} file - A file info object, which will be passed to the method
|
|
131
|
-
* @param {function} [callback] - A callback function, which will be passed to the method
|
|
132
|
-
* @returns {*}
|
|
129
|
+
* If the value is an array, then it will be compared against the file extension.
|
|
133
130
|
*/
|
|
134
|
-
function getResult
|
|
135
|
-
|
|
131
|
+
function getResult(
|
|
132
|
+
obj: Plugin,
|
|
133
|
+
prop: keyof Plugin | keyof ResolverOptions,
|
|
134
|
+
file: FileInfo,
|
|
135
|
+
callback?: (err?: Error, result?: any) => void,
|
|
136
|
+
$refs?: any,
|
|
137
|
+
) {
|
|
138
|
+
const value = obj[prop as keyof typeof obj] as unknown;
|
|
136
139
|
|
|
137
140
|
if (typeof value === "function") {
|
|
138
141
|
return value.apply(obj, [file, callback, $refs]);
|
|
@@ -144,11 +147,9 @@ function getResult (obj, prop, file, callback, $refs) {
|
|
|
144
147
|
// files by RegExp or by file extension.
|
|
145
148
|
if (value instanceof RegExp) {
|
|
146
149
|
return value.test(file.url);
|
|
147
|
-
}
|
|
148
|
-
else if (typeof value === "string") {
|
|
150
|
+
} else if (typeof value === "string") {
|
|
149
151
|
return value === file.extension;
|
|
150
|
-
}
|
|
151
|
-
else if (Array.isArray(value)) {
|
|
152
|
+
} else if (Array.isArray(value)) {
|
|
152
153
|
return value.indexOf(file.extension) !== -1;
|
|
153
154
|
}
|
|
154
155
|
}
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
jsonPointerTilde = /~0/g;
|
|
1
|
+
const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : ""),
|
|
2
|
+
forwardSlashPattern = /\//g,
|
|
3
|
+
protocolPattern = /^(\w{2,}):\/\//i,
|
|
4
|
+
jsonPointerSlash = /~1/g,
|
|
5
|
+
jsonPointerTilde = /~0/g;
|
|
6
|
+
import { join } from "path";
|
|
8
7
|
|
|
8
|
+
const projectDir = join(__dirname, "..", "..");
|
|
9
9
|
// RegExp patterns to URL-encode special characters in local filesystem paths
|
|
10
|
-
|
|
11
|
-
/\?/g, "%3F",
|
|
12
|
-
/\#/g, "%23",
|
|
13
|
-
];
|
|
10
|
+
const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
|
|
14
11
|
|
|
15
12
|
// RegExp patterns to URL-decode special characters for local filesystem paths
|
|
16
|
-
|
|
17
|
-
/\%23/g, "#",
|
|
18
|
-
/\%24/g, "$",
|
|
19
|
-
/\%26/g, "&",
|
|
20
|
-
/\%2C/g, ",",
|
|
21
|
-
/\%40/g, "@"
|
|
22
|
-
];
|
|
13
|
+
const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];
|
|
23
14
|
|
|
24
|
-
export const parse = (u) => new URL(u);
|
|
15
|
+
export const parse = (u: any) => new URL(u);
|
|
25
16
|
|
|
26
17
|
/**
|
|
27
18
|
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
|
|
28
19
|
*
|
|
29
|
-
* @
|
|
20
|
+
* @returns
|
|
30
21
|
*/
|
|
31
|
-
export function resolve
|
|
32
|
-
|
|
22
|
+
export function resolve(from: any, to: any) {
|
|
23
|
+
const resolvedUrl = new URL(to, new URL(from, "resolve://"));
|
|
33
24
|
if (resolvedUrl.protocol === "resolve:") {
|
|
34
25
|
// `from` is a relative URL.
|
|
35
|
-
|
|
26
|
+
const { pathname, search, hash } = resolvedUrl;
|
|
36
27
|
return pathname + search + hash;
|
|
37
28
|
}
|
|
38
29
|
return resolvedUrl.toString();
|
|
@@ -41,20 +32,19 @@ export function resolve (from, to) {
|
|
|
41
32
|
/**
|
|
42
33
|
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
|
43
34
|
*
|
|
44
|
-
* @returns
|
|
35
|
+
* @returns
|
|
45
36
|
*/
|
|
46
|
-
export function cwd
|
|
37
|
+
export function cwd() {
|
|
47
38
|
if (typeof window !== "undefined") {
|
|
48
39
|
return location.href;
|
|
49
40
|
}
|
|
50
41
|
|
|
51
|
-
|
|
42
|
+
const path = process.cwd();
|
|
52
43
|
|
|
53
|
-
|
|
44
|
+
const lastChar = path.slice(-1);
|
|
54
45
|
if (lastChar === "/" || lastChar === "\\") {
|
|
55
46
|
return path;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
47
|
+
} else {
|
|
58
48
|
return path + "/";
|
|
59
49
|
}
|
|
60
50
|
}
|
|
@@ -62,11 +52,11 @@ export function cwd () {
|
|
|
62
52
|
/**
|
|
63
53
|
* Returns the protocol of the given URL, or `undefined` if it has no protocol.
|
|
64
54
|
*
|
|
65
|
-
* @param
|
|
66
|
-
* @returns
|
|
55
|
+
* @param path
|
|
56
|
+
* @returns
|
|
67
57
|
*/
|
|
68
|
-
export function getProtocol
|
|
69
|
-
|
|
58
|
+
export function getProtocol(path: any) {
|
|
59
|
+
const match = protocolPattern.exec(path);
|
|
70
60
|
if (match) {
|
|
71
61
|
return match[1].toLowerCase();
|
|
72
62
|
}
|
|
@@ -76,11 +66,11 @@ export function getProtocol (path) {
|
|
|
76
66
|
* Returns the lowercased file extension of the given URL,
|
|
77
67
|
* or an empty string if it has no extension.
|
|
78
68
|
*
|
|
79
|
-
* @param
|
|
80
|
-
* @returns
|
|
69
|
+
* @param path
|
|
70
|
+
* @returns
|
|
81
71
|
*/
|
|
82
|
-
export function getExtension
|
|
83
|
-
|
|
72
|
+
export function getExtension(path: any) {
|
|
73
|
+
const lastDot = path.lastIndexOf(".");
|
|
84
74
|
if (lastDot >= 0) {
|
|
85
75
|
return stripQuery(path.substr(lastDot).toLowerCase());
|
|
86
76
|
}
|
|
@@ -90,11 +80,11 @@ export function getExtension (path) {
|
|
|
90
80
|
/**
|
|
91
81
|
* Removes the query, if any, from the given path.
|
|
92
82
|
*
|
|
93
|
-
* @param
|
|
94
|
-
* @returns
|
|
83
|
+
* @param path
|
|
84
|
+
* @returns
|
|
95
85
|
*/
|
|
96
|
-
export function stripQuery
|
|
97
|
-
|
|
86
|
+
export function stripQuery(path: any) {
|
|
87
|
+
const queryIndex = path.indexOf("?");
|
|
98
88
|
if (queryIndex >= 0) {
|
|
99
89
|
path = path.substr(0, queryIndex);
|
|
100
90
|
}
|
|
@@ -105,11 +95,11 @@ export function stripQuery (path) {
|
|
|
105
95
|
* Returns the hash (URL fragment), of the given path.
|
|
106
96
|
* If there is no hash, then the root hash ("#") is returned.
|
|
107
97
|
*
|
|
108
|
-
* @param
|
|
109
|
-
* @returns
|
|
98
|
+
* @param path
|
|
99
|
+
* @returns
|
|
110
100
|
*/
|
|
111
|
-
export function getHash
|
|
112
|
-
|
|
101
|
+
export function getHash(path: any) {
|
|
102
|
+
const hashIndex = path.indexOf("#");
|
|
113
103
|
if (hashIndex >= 0) {
|
|
114
104
|
return path.substr(hashIndex);
|
|
115
105
|
}
|
|
@@ -119,11 +109,11 @@ export function getHash (path) {
|
|
|
119
109
|
/**
|
|
120
110
|
* Removes the hash (URL fragment), if any, from the given path.
|
|
121
111
|
*
|
|
122
|
-
* @param
|
|
123
|
-
* @returns
|
|
112
|
+
* @param path
|
|
113
|
+
* @returns
|
|
124
114
|
*/
|
|
125
|
-
export function stripHash
|
|
126
|
-
|
|
115
|
+
export function stripHash(path: any) {
|
|
116
|
+
const hashIndex = path.indexOf("#");
|
|
127
117
|
if (hashIndex >= 0) {
|
|
128
118
|
path = path.substr(0, hashIndex);
|
|
129
119
|
}
|
|
@@ -133,19 +123,17 @@ export function stripHash (path) {
|
|
|
133
123
|
/**
|
|
134
124
|
* Determines whether the given path is an HTTP(S) URL.
|
|
135
125
|
*
|
|
136
|
-
* @param
|
|
137
|
-
* @returns
|
|
126
|
+
* @param path
|
|
127
|
+
* @returns
|
|
138
128
|
*/
|
|
139
|
-
export function isHttp
|
|
140
|
-
|
|
129
|
+
export function isHttp(path: any) {
|
|
130
|
+
const protocol = getProtocol(path);
|
|
141
131
|
if (protocol === "http" || protocol === "https") {
|
|
142
132
|
return true;
|
|
143
|
-
}
|
|
144
|
-
else if (protocol === undefined) {
|
|
133
|
+
} else if (protocol === undefined) {
|
|
145
134
|
// There is no protocol. If we're running in a browser, then assume it's HTTP.
|
|
146
135
|
return typeof window !== "undefined";
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
136
|
+
} else {
|
|
149
137
|
// It's some other protocol, such as "ftp://", "mongodb://", etc.
|
|
150
138
|
return false;
|
|
151
139
|
}
|
|
@@ -155,17 +143,18 @@ export function isHttp (path) {
|
|
|
155
143
|
* Determines whether the given path is a filesystem path.
|
|
156
144
|
* This includes "file://" URLs.
|
|
157
145
|
*
|
|
158
|
-
* @param
|
|
159
|
-
* @returns
|
|
146
|
+
* @param path
|
|
147
|
+
* @returns
|
|
160
148
|
*/
|
|
161
|
-
export function isFileSystemPath
|
|
162
|
-
|
|
149
|
+
export function isFileSystemPath(path: any) {
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
if (typeof window !== "undefined" || process.browser) {
|
|
163
152
|
// We're running in a browser, so assume that all paths are URLs.
|
|
164
153
|
// This way, even relative paths will be treated as URLs rather than as filesystem paths
|
|
165
154
|
return false;
|
|
166
155
|
}
|
|
167
156
|
|
|
168
|
-
|
|
157
|
+
const protocol = getProtocol(path);
|
|
169
158
|
return protocol === undefined || protocol === "file";
|
|
170
159
|
}
|
|
171
160
|
|
|
@@ -182,10 +171,10 @@ export function isFileSystemPath (path) {
|
|
|
182
171
|
* C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
|
|
183
172
|
* file://Project #42/file.json ==> file://Project%20%2342/file.json
|
|
184
173
|
*
|
|
185
|
-
* @param
|
|
186
|
-
* @returns
|
|
174
|
+
* @param path
|
|
175
|
+
* @returns
|
|
187
176
|
*/
|
|
188
|
-
export function fromFileSystemPath
|
|
177
|
+
export function fromFileSystemPath(path: any) {
|
|
189
178
|
// Step 1: On Windows, replace backslashes with forward slashes,
|
|
190
179
|
// rather than encoding them as "%5C"
|
|
191
180
|
if (isWindows) {
|
|
@@ -193,8 +182,7 @@ export function fromFileSystemPath (path) {
|
|
|
193
182
|
const hasProjectUri = path.toUpperCase().includes(projectDir.replace(/\\/g, "/").toUpperCase());
|
|
194
183
|
if (hasProjectDir || hasProjectUri) {
|
|
195
184
|
path = path.replace(/\\/g, "/");
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
185
|
+
} else {
|
|
198
186
|
path = `${projectDir}/${path}`.replace(/\\/g, "/");
|
|
199
187
|
}
|
|
200
188
|
}
|
|
@@ -214,20 +202,16 @@ export function fromFileSystemPath (path) {
|
|
|
214
202
|
|
|
215
203
|
/**
|
|
216
204
|
* Converts a URL to a local filesystem path.
|
|
217
|
-
*
|
|
218
|
-
* @param {string} path
|
|
219
|
-
* @param {boolean} [keepFileProtocol] - If true, then "file://" will NOT be stripped
|
|
220
|
-
* @returns {string}
|
|
221
205
|
*/
|
|
222
|
-
export function toFileSystemPath
|
|
206
|
+
export function toFileSystemPath(path: string | undefined, keepFileProtocol?: boolean): string {
|
|
223
207
|
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
|
|
224
|
-
path = decodeURI(path);
|
|
208
|
+
path = decodeURI(path!);
|
|
225
209
|
|
|
226
210
|
// Step 2: Manually decode characters that are not decoded by `decodeURI`.
|
|
227
211
|
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
|
228
212
|
// but are just normal characters in a filesystem path.
|
|
229
213
|
for (let i = 0; i < urlDecodePatterns.length; i += 2) {
|
|
230
|
-
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
|
|
214
|
+
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1] as string);
|
|
231
215
|
}
|
|
232
216
|
|
|
233
217
|
// Step 3: If it's a "file://" URL, then format it consistently
|
|
@@ -245,8 +229,7 @@ export function toFileSystemPath (path, keepFileProtocol) {
|
|
|
245
229
|
if (keepFileProtocol) {
|
|
246
230
|
// Return the consistently-formatted "file://" URL
|
|
247
231
|
path = "file:///" + path;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
232
|
+
} else {
|
|
250
233
|
// Convert the "file://" URL to a local filesystem path.
|
|
251
234
|
// On Windows, it will start with something like "C:/".
|
|
252
235
|
// On Posix, it will start with "/"
|
|
@@ -272,10 +255,10 @@ export function toFileSystemPath (path, keepFileProtocol) {
|
|
|
272
255
|
/**
|
|
273
256
|
* Converts a $ref pointer to a valid JSON Path.
|
|
274
257
|
*
|
|
275
|
-
* @param
|
|
276
|
-
* @returns
|
|
258
|
+
* @param pointer
|
|
259
|
+
* @returns
|
|
277
260
|
*/
|
|
278
|
-
export function safePointerToPath
|
|
261
|
+
export function safePointerToPath(pointer: any) {
|
|
279
262
|
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
|
|
280
263
|
return [];
|
|
281
264
|
}
|
|
@@ -283,9 +266,7 @@ export function safePointerToPath (pointer) {
|
|
|
283
266
|
return pointer
|
|
284
267
|
.slice(2)
|
|
285
268
|
.split("/")
|
|
286
|
-
.map((value) => {
|
|
287
|
-
return decodeURIComponent(value)
|
|
288
|
-
.replace(jsonPointerSlash, "/")
|
|
289
|
-
.replace(jsonPointerTilde, "~");
|
|
269
|
+
.map((value: any) => {
|
|
270
|
+
return decodeURIComponent(value).replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
|
|
290
271
|
});
|
|
291
272
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apidevtools/json-schema-ref-parser",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
{
|
|
29
29
|
"name": "Jakub Rożek",
|
|
30
30
|
"email": "jakub@stoplight.io"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "JonLuca DeCaro",
|
|
34
|
+
"email": "apis@jonlu.ca"
|
|
31
35
|
}
|
|
32
36
|
],
|
|
33
37
|
"homepage": "https://apitools.dev/json-schema-ref-parser/",
|
|
@@ -37,67 +41,62 @@
|
|
|
37
41
|
},
|
|
38
42
|
"license": "MIT",
|
|
39
43
|
"funding": "https://github.com/sponsors/philsturgeon",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"exports": {
|
|
43
|
-
"types": "./lib/index.d.ts",
|
|
44
|
-
"require": "./cjs/index.js",
|
|
45
|
-
"default": "./lib/index.js"
|
|
46
|
-
},
|
|
44
|
+
"types": "dist/lib/index.d.ts",
|
|
45
|
+
"main": "dist/lib/index.js",
|
|
47
46
|
"browser": {
|
|
48
47
|
"fs": false
|
|
49
48
|
},
|
|
50
49
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
50
|
+
"node": ">= 16"
|
|
52
51
|
},
|
|
53
52
|
"files": [
|
|
54
53
|
"lib",
|
|
54
|
+
"dist",
|
|
55
55
|
"cjs"
|
|
56
56
|
],
|
|
57
|
-
"type": "module",
|
|
58
57
|
"scripts": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"test
|
|
65
|
-
"test:
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"upgrade": "npm-check -u && npm audit fix"
|
|
58
|
+
"prepublishOnly": "yarn build",
|
|
59
|
+
"lint": "eslint lib",
|
|
60
|
+
"build": "rm -fr dist/* && tsc",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"prettier": "prettier --write \"**/*.+(js|jsx|ts|tsx|har||json|css|md)\"",
|
|
63
|
+
"test": "vitest --coverage",
|
|
64
|
+
"test:node": "yarn test",
|
|
65
|
+
"test:browser": "cross-env BROWSER=\"true\" yarn test",
|
|
66
|
+
"test:update": "vitest -u",
|
|
67
|
+
"test:watch": "vitest -w"
|
|
70
68
|
},
|
|
71
69
|
"devDependencies": {
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"
|
|
70
|
+
"@types/eslint": "8.4.10",
|
|
71
|
+
"@types/js-yaml": "^4.0.5",
|
|
72
|
+
"@types/node": "^18.11.18",
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^5.48.2",
|
|
74
|
+
"@typescript-eslint/eslint-plugin-tslint": "^5.48.2",
|
|
75
|
+
"@typescript-eslint/parser": "^5.48.2",
|
|
76
|
+
"@vitest/coverage-c8": "^0.28.1",
|
|
77
|
+
"abortcontroller-polyfill": "^1.7.5",
|
|
80
78
|
"c8": "^7.12.0",
|
|
81
|
-
"chai": "^4.2.0",
|
|
82
|
-
"chai-subset": "^1.6.0",
|
|
83
|
-
"chokidar": "^3.5.3",
|
|
84
|
-
"copyfiles": "^2.4.1",
|
|
85
79
|
"cross-env": "^7.0.3",
|
|
86
|
-
"eslint": "^
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
80
|
+
"eslint": "^8.32.0",
|
|
81
|
+
"eslint-config-prettier": "^8.6.0",
|
|
82
|
+
"eslint-config-standard": "^17.0.0",
|
|
83
|
+
"eslint-plugin-import": "^2.27.5",
|
|
84
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
85
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
86
|
+
"eslint-plugin-unused-imports": "^2.0.0",
|
|
87
|
+
"jsdom": "^21.1.0",
|
|
88
|
+
"lint-staged": "^13.1.0",
|
|
89
|
+
"node-fetch": "^3.3.0",
|
|
90
|
+
"prettier": "^2.8.3",
|
|
91
|
+
"typescript": "^4.9.4",
|
|
92
|
+
"vitest": "^0.28.1"
|
|
95
93
|
},
|
|
96
94
|
"dependencies": {
|
|
97
95
|
"@jsdevtools/ono": "^7.1.3",
|
|
98
|
-
"@types/json-schema": "^7.0.
|
|
99
|
-
"
|
|
100
|
-
"js-yaml": "^4.1.0"
|
|
96
|
+
"@types/json-schema": "^7.0.11",
|
|
97
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
98
|
+
"js-yaml": "^4.1.0",
|
|
99
|
+
"lodash.clonedeep": "^4.5.0"
|
|
101
100
|
},
|
|
102
101
|
"release": {
|
|
103
102
|
"branches": [
|