@apidevtools/json-schema-ref-parser 10.0.1 → 11.0.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/README.md +22 -0
- package/dist/lib/bundle.d.ts +10 -0
- package/dist/lib/bundle.js +266 -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 +206 -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 +162 -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 +46 -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 +54 -0
- package/dist/lib/pointer.d.ts +87 -0
- package/dist/lib/pointer.js +256 -0
- package/dist/lib/ref.d.ts +180 -0
- package/dist/lib/ref.js +238 -0
- package/dist/lib/refs.d.ts +127 -0
- package/dist/lib/refs.js +222 -0
- package/dist/lib/resolve-external.d.ts +14 -0
- package/dist/lib/resolve-external.js +133 -0
- package/dist/lib/resolvers/file.d.ts +3 -0
- package/dist/lib/resolvers/file.js +62 -0
- package/dist/lib/resolvers/http.d.ts +3 -0
- package/dist/lib/resolvers/http.js +146 -0
- package/dist/lib/types/index.d.ts +104 -0
- package/dist/lib/types/index.js +2 -0
- package/dist/lib/util/convert-path-to-posix.d.ts +1 -0
- package/dist/lib/util/convert-path-to-posix.js +14 -0
- package/dist/lib/util/errors.d.ts +50 -0
- package/dist/lib/util/errors.js +106 -0
- package/dist/lib/util/is-windows.d.ts +1 -0
- package/dist/lib/util/is-windows.js +6 -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 +133 -0
- package/dist/lib/util/url.d.ts +94 -0
- package/dist/lib/util/url.js +304 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.js +19 -0
- package/lib/{bundle.js → bundle.ts} +106 -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 +287 -0
- package/lib/refs.ts +236 -0
- package/lib/{resolve-external.js → resolve-external.ts} +44 -41
- 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/convert-path-to-posix.ts +11 -0
- package/lib/util/errors.ts +141 -0
- package/lib/util/is-windows.ts +2 -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} +92 -91
- package/package.json +44 -46
- 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/cjs/util/url.js +0 -228
- 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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare const parse: (u: any) => URL;
|
|
2
|
+
/**
|
|
3
|
+
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
|
|
4
|
+
*
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolve(from: any, to: any): string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
|
10
|
+
*
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function cwd(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the protocol of the given URL, or `undefined` if it has no protocol.
|
|
16
|
+
*
|
|
17
|
+
* @param path
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function getProtocol(path: string | undefined): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the lowercased file extension of the given URL,
|
|
23
|
+
* or an empty string if it has no extension.
|
|
24
|
+
*
|
|
25
|
+
* @param path
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function getExtension(path: any): any;
|
|
29
|
+
/**
|
|
30
|
+
* Removes the query, if any, from the given path.
|
|
31
|
+
*
|
|
32
|
+
* @param path
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export declare function stripQuery(path: any): any;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the hash (URL fragment), of the given path.
|
|
38
|
+
* If there is no hash, then the root hash ("#") is returned.
|
|
39
|
+
*
|
|
40
|
+
* @param path
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export declare function getHash(path: any): any;
|
|
44
|
+
/**
|
|
45
|
+
* Removes the hash (URL fragment), if any, from the given path.
|
|
46
|
+
*
|
|
47
|
+
* @param path
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
export declare function stripHash(path: any): any;
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether the given path is an HTTP(S) URL.
|
|
53
|
+
*
|
|
54
|
+
* @param path
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export declare function isHttp(path: any): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Determines whether the given path is a filesystem path.
|
|
60
|
+
* This includes "file://" URLs.
|
|
61
|
+
*
|
|
62
|
+
* @param path
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
export declare function isFileSystemPath(path: string | undefined): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Converts a filesystem path to a properly-encoded URL.
|
|
68
|
+
*
|
|
69
|
+
* This is intended to handle situations where JSON Schema $Ref Parser is called
|
|
70
|
+
* with a filesystem path that contains characters which are not allowed in URLs.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* The following filesystem paths would be converted to the following URLs:
|
|
74
|
+
*
|
|
75
|
+
* <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
|
|
76
|
+
* C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
|
|
77
|
+
* file://Project #42/file.json ==> file://Project%20%2342/file.json
|
|
78
|
+
*
|
|
79
|
+
* @param path
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
export declare function fromFileSystemPath(path: any): any;
|
|
83
|
+
/**
|
|
84
|
+
* Converts a URL to a local filesystem path.
|
|
85
|
+
*/
|
|
86
|
+
export declare function toFileSystemPath(path: string | undefined, keepFileProtocol?: boolean): string;
|
|
87
|
+
/**
|
|
88
|
+
* Converts a $ref pointer to a valid JSON Path.
|
|
89
|
+
*
|
|
90
|
+
* @param pointer
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
export declare function safePointerToPath(pointer: any): any;
|
|
94
|
+
export declare function relative(from: string | undefined, to: string | undefined): string;
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.relative = exports.safePointerToPath = exports.toFileSystemPath = exports.fromFileSystemPath = exports.isFileSystemPath = exports.isHttp = exports.stripHash = exports.getHash = exports.stripQuery = exports.getExtension = exports.getProtocol = exports.cwd = exports.resolve = exports.parse = void 0;
|
|
30
|
+
const convert_path_to_posix_1 = __importDefault(require("./convert-path-to-posix"));
|
|
31
|
+
const path_1 = __importStar(require("path"));
|
|
32
|
+
const forwardSlashPattern = /\//g;
|
|
33
|
+
const protocolPattern = /^(\w{2,}):\/\//i;
|
|
34
|
+
const jsonPointerSlash = /~1/g;
|
|
35
|
+
const jsonPointerTilde = /~0/g;
|
|
36
|
+
const path_2 = require("path");
|
|
37
|
+
const is_windows_1 = require("./is-windows");
|
|
38
|
+
const projectDir = (0, path_2.join)(__dirname, "..", "..");
|
|
39
|
+
// RegExp patterns to URL-encode special characters in local filesystem paths
|
|
40
|
+
const urlEncodePatterns = [/\?/g, "%3F", /#/g, "%23"];
|
|
41
|
+
// RegExp patterns to URL-decode special characters for local filesystem paths
|
|
42
|
+
const urlDecodePatterns = [/%23/g, "#", /%24/g, "$", /%26/g, "&", /%2C/g, ",", /%40/g, "@"];
|
|
43
|
+
const parse = (u) => new URL(u);
|
|
44
|
+
exports.parse = parse;
|
|
45
|
+
/**
|
|
46
|
+
* Returns resolved target URL relative to a base URL in a manner similar to that of a Web browser resolving an anchor tag HREF.
|
|
47
|
+
*
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
function resolve(from, to) {
|
|
51
|
+
const resolvedUrl = new URL(to, new URL(from, "resolve://"));
|
|
52
|
+
if (resolvedUrl.protocol === "resolve:") {
|
|
53
|
+
// `from` is a relative URL.
|
|
54
|
+
const { pathname, search, hash } = resolvedUrl;
|
|
55
|
+
return pathname + search + hash;
|
|
56
|
+
}
|
|
57
|
+
return resolvedUrl.toString();
|
|
58
|
+
}
|
|
59
|
+
exports.resolve = resolve;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the current working directory (in Node) or the current page URL (in browsers).
|
|
62
|
+
*
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
function cwd() {
|
|
66
|
+
if (typeof window !== "undefined") {
|
|
67
|
+
return location.href;
|
|
68
|
+
}
|
|
69
|
+
const path = process.cwd();
|
|
70
|
+
const lastChar = path.slice(-1);
|
|
71
|
+
if (lastChar === "/" || lastChar === "\\") {
|
|
72
|
+
return path;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return path + "/";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.cwd = cwd;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the protocol of the given URL, or `undefined` if it has no protocol.
|
|
81
|
+
*
|
|
82
|
+
* @param path
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
function getProtocol(path) {
|
|
86
|
+
const match = protocolPattern.exec(path || "");
|
|
87
|
+
if (match) {
|
|
88
|
+
return match[1].toLowerCase();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.getProtocol = getProtocol;
|
|
92
|
+
/**
|
|
93
|
+
* Returns the lowercased file extension of the given URL,
|
|
94
|
+
* or an empty string if it has no extension.
|
|
95
|
+
*
|
|
96
|
+
* @param path
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
function getExtension(path) {
|
|
100
|
+
const lastDot = path.lastIndexOf(".");
|
|
101
|
+
if (lastDot >= 0) {
|
|
102
|
+
return stripQuery(path.substr(lastDot).toLowerCase());
|
|
103
|
+
}
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
exports.getExtension = getExtension;
|
|
107
|
+
/**
|
|
108
|
+
* Removes the query, if any, from the given path.
|
|
109
|
+
*
|
|
110
|
+
* @param path
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
function stripQuery(path) {
|
|
114
|
+
const queryIndex = path.indexOf("?");
|
|
115
|
+
if (queryIndex >= 0) {
|
|
116
|
+
path = path.substr(0, queryIndex);
|
|
117
|
+
}
|
|
118
|
+
return path;
|
|
119
|
+
}
|
|
120
|
+
exports.stripQuery = stripQuery;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the hash (URL fragment), of the given path.
|
|
123
|
+
* If there is no hash, then the root hash ("#") is returned.
|
|
124
|
+
*
|
|
125
|
+
* @param path
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
function getHash(path) {
|
|
129
|
+
const hashIndex = path.indexOf("#");
|
|
130
|
+
if (hashIndex >= 0) {
|
|
131
|
+
return path.substr(hashIndex);
|
|
132
|
+
}
|
|
133
|
+
return "#";
|
|
134
|
+
}
|
|
135
|
+
exports.getHash = getHash;
|
|
136
|
+
/**
|
|
137
|
+
* Removes the hash (URL fragment), if any, from the given path.
|
|
138
|
+
*
|
|
139
|
+
* @param path
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
function stripHash(path) {
|
|
143
|
+
const hashIndex = path.indexOf("#");
|
|
144
|
+
if (hashIndex >= 0) {
|
|
145
|
+
path = path.substr(0, hashIndex);
|
|
146
|
+
}
|
|
147
|
+
return path;
|
|
148
|
+
}
|
|
149
|
+
exports.stripHash = stripHash;
|
|
150
|
+
/**
|
|
151
|
+
* Determines whether the given path is an HTTP(S) URL.
|
|
152
|
+
*
|
|
153
|
+
* @param path
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
function isHttp(path) {
|
|
157
|
+
const protocol = getProtocol(path);
|
|
158
|
+
if (protocol === "http" || protocol === "https") {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
else if (protocol === undefined) {
|
|
162
|
+
// There is no protocol. If we're running in a browser, then assume it's HTTP.
|
|
163
|
+
return typeof window !== "undefined";
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// It's some other protocol, such as "ftp://", "mongodb://", etc.
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.isHttp = isHttp;
|
|
171
|
+
/**
|
|
172
|
+
* Determines whether the given path is a filesystem path.
|
|
173
|
+
* This includes "file://" URLs.
|
|
174
|
+
*
|
|
175
|
+
* @param path
|
|
176
|
+
* @returns
|
|
177
|
+
*/
|
|
178
|
+
function isFileSystemPath(path) {
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
if (typeof window !== "undefined" || process.browser) {
|
|
181
|
+
// We're running in a browser, so assume that all paths are URLs.
|
|
182
|
+
// This way, even relative paths will be treated as URLs rather than as filesystem paths
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
const protocol = getProtocol(path);
|
|
186
|
+
return protocol === undefined || protocol === "file";
|
|
187
|
+
}
|
|
188
|
+
exports.isFileSystemPath = isFileSystemPath;
|
|
189
|
+
/**
|
|
190
|
+
* Converts a filesystem path to a properly-encoded URL.
|
|
191
|
+
*
|
|
192
|
+
* This is intended to handle situations where JSON Schema $Ref Parser is called
|
|
193
|
+
* with a filesystem path that contains characters which are not allowed in URLs.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* The following filesystem paths would be converted to the following URLs:
|
|
197
|
+
*
|
|
198
|
+
* <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
|
|
199
|
+
* C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
|
|
200
|
+
* file://Project #42/file.json ==> file://Project%20%2342/file.json
|
|
201
|
+
*
|
|
202
|
+
* @param path
|
|
203
|
+
* @returns
|
|
204
|
+
*/
|
|
205
|
+
function fromFileSystemPath(path) {
|
|
206
|
+
// Step 1: On Windows, replace backslashes with forward slashes,
|
|
207
|
+
// rather than encoding them as "%5C"
|
|
208
|
+
if ((0, is_windows_1.isWindows)()) {
|
|
209
|
+
const upperPath = path.toUpperCase();
|
|
210
|
+
const projectDirPosixPath = (0, convert_path_to_posix_1.default)(projectDir);
|
|
211
|
+
const posixUpper = projectDirPosixPath.toUpperCase();
|
|
212
|
+
const hasProjectDir = upperPath.includes(posixUpper);
|
|
213
|
+
const hasProjectUri = upperPath.includes(posixUpper);
|
|
214
|
+
const isAbsolutePath = path_1.win32.isAbsolute(path);
|
|
215
|
+
if (!(hasProjectDir || hasProjectUri || isAbsolutePath)) {
|
|
216
|
+
path = (0, path_2.join)(projectDir, path);
|
|
217
|
+
}
|
|
218
|
+
path = (0, convert_path_to_posix_1.default)(path);
|
|
219
|
+
}
|
|
220
|
+
// Step 2: `encodeURI` will take care of MOST characters
|
|
221
|
+
path = encodeURI(path);
|
|
222
|
+
// Step 3: Manually encode characters that are not encoded by `encodeURI`.
|
|
223
|
+
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
|
224
|
+
// but are just normal characters in a filesystem path.
|
|
225
|
+
for (let i = 0; i < urlEncodePatterns.length; i += 2) {
|
|
226
|
+
path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
|
|
227
|
+
}
|
|
228
|
+
return path;
|
|
229
|
+
}
|
|
230
|
+
exports.fromFileSystemPath = fromFileSystemPath;
|
|
231
|
+
/**
|
|
232
|
+
* Converts a URL to a local filesystem path.
|
|
233
|
+
*/
|
|
234
|
+
function toFileSystemPath(path, keepFileProtocol) {
|
|
235
|
+
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
|
|
236
|
+
path = decodeURI(path);
|
|
237
|
+
// Step 2: Manually decode characters that are not decoded by `decodeURI`.
|
|
238
|
+
// This includes characters such as "#" and "?", which have special meaning in URLs,
|
|
239
|
+
// but are just normal characters in a filesystem path.
|
|
240
|
+
for (let i = 0; i < urlDecodePatterns.length; i += 2) {
|
|
241
|
+
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
|
|
242
|
+
}
|
|
243
|
+
// Step 3: If it's a "file://" URL, then format it consistently
|
|
244
|
+
// or convert it to a local filesystem path
|
|
245
|
+
let isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
|
|
246
|
+
if (isFileUrl) {
|
|
247
|
+
// Strip-off the protocol, and the initial "/", if there is one
|
|
248
|
+
path = path[7] === "/" ? path.substr(8) : path.substr(7);
|
|
249
|
+
// insert a colon (":") after the drive letter on Windows
|
|
250
|
+
if ((0, is_windows_1.isWindows)() && path[1] === "/") {
|
|
251
|
+
path = path[0] + ":" + path.substr(1);
|
|
252
|
+
}
|
|
253
|
+
if (keepFileProtocol) {
|
|
254
|
+
// Return the consistently-formatted "file://" URL
|
|
255
|
+
path = "file:///" + path;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
// Convert the "file://" URL to a local filesystem path.
|
|
259
|
+
// On Windows, it will start with something like "C:/".
|
|
260
|
+
// On Posix, it will start with "/"
|
|
261
|
+
isFileUrl = false;
|
|
262
|
+
path = (0, is_windows_1.isWindows)() ? path : "/" + path;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Step 4: Normalize Windows paths (unless it's a "file://" URL)
|
|
266
|
+
if ((0, is_windows_1.isWindows)() && !isFileUrl) {
|
|
267
|
+
// Replace forward slashes with backslashes
|
|
268
|
+
path = path.replace(forwardSlashPattern, "\\");
|
|
269
|
+
// Capitalize the drive letter
|
|
270
|
+
if (path.substr(1, 2) === ":\\") {
|
|
271
|
+
path = path[0].toUpperCase() + path.substr(1);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return path;
|
|
275
|
+
}
|
|
276
|
+
exports.toFileSystemPath = toFileSystemPath;
|
|
277
|
+
/**
|
|
278
|
+
* Converts a $ref pointer to a valid JSON Path.
|
|
279
|
+
*
|
|
280
|
+
* @param pointer
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
function safePointerToPath(pointer) {
|
|
284
|
+
if (pointer.length <= 1 || pointer[0] !== "#" || pointer[1] !== "/") {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
return pointer
|
|
288
|
+
.slice(2)
|
|
289
|
+
.split("/")
|
|
290
|
+
.map((value) => {
|
|
291
|
+
return decodeURIComponent(value).replace(jsonPointerSlash, "/").replace(jsonPointerTilde, "~");
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
exports.safePointerToPath = safePointerToPath;
|
|
295
|
+
function relative(from, to) {
|
|
296
|
+
if (!isFileSystemPath(from) || !isFileSystemPath(to)) {
|
|
297
|
+
return resolve(from, to);
|
|
298
|
+
}
|
|
299
|
+
const fromDir = path_1.default.dirname(stripHash(from));
|
|
300
|
+
const toPath = stripHash(to);
|
|
301
|
+
const result = path_1.default.relative(fromDir, toPath);
|
|
302
|
+
return result + getHash(to);
|
|
303
|
+
}
|
|
304
|
+
exports.relative = relative;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("vitest/config");
|
|
4
|
+
const isBrowser = process.env.BROWSER === "true";
|
|
5
|
+
exports.default = (0, config_1.defineConfig)({
|
|
6
|
+
test: {
|
|
7
|
+
environment: isBrowser ? "jsdom" : "node",
|
|
8
|
+
dir: "test",
|
|
9
|
+
exclude: ["**/__IGNORED__/**"],
|
|
10
|
+
watch: false,
|
|
11
|
+
globalSetup: isBrowser ? ["./test/fixtures/server.ts"] : undefined,
|
|
12
|
+
setupFiles: isBrowser ? ["./test/fixtures/polyfill.ts"] : undefined,
|
|
13
|
+
testTimeout: 5000,
|
|
14
|
+
globals: true,
|
|
15
|
+
passWithNoTests: true,
|
|
16
|
+
reporters: ["verbose"],
|
|
17
|
+
coverage: { reporter: ["lcov", "html", "text"] },
|
|
18
|
+
},
|
|
19
|
+
});
|