@apidevtools/json-schema-ref-parser 10.1.0 → 11.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.
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -40,26 +31,24 @@ exports.default = {
40
31
  * @param file.data - The file contents. This will be whatever data type was returned by the resolver
41
32
  * @returns
42
33
  */
43
- parse(file) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- // eslint-disable-line require-await
46
- let data = file.data;
47
- if (Buffer.isBuffer(data)) {
48
- data = data.toString();
49
- }
50
- if (typeof data === "string") {
51
- try {
52
- return js_yaml_1.default.load(data, { schema: js_yaml_2.JSON_SCHEMA });
53
- }
54
- catch (e) {
55
- // @ts-expect-error TS(2571): Object is of type 'unknown'.
56
- throw new errors_js_1.ParserError(e.message, file.url);
57
- }
34
+ async parse(file) {
35
+ // eslint-disable-line require-await
36
+ let data = file.data;
37
+ if (Buffer.isBuffer(data)) {
38
+ data = data.toString();
39
+ }
40
+ if (typeof data === "string") {
41
+ try {
42
+ return js_yaml_1.default.load(data, { schema: js_yaml_2.JSON_SCHEMA });
58
43
  }
59
- else {
60
- // data is already a JavaScript value (object, array, number, null, NaN, etc.)
61
- return data;
44
+ catch (e) {
45
+ // @ts-expect-error TS(2571): Object is of type 'unknown'.
46
+ throw new errors_js_1.ParserError(e.message, file.url);
62
47
  }
63
- });
48
+ }
49
+ else {
50
+ // data is already a JavaScript value (object, array, number, null, NaN, etc.)
51
+ return data;
52
+ }
64
53
  },
65
54
  };
package/dist/lib/ref.d.ts CHANGED
@@ -2,7 +2,6 @@ import Pointer from "./pointer.js";
2
2
  import type { JSONParserError, MissingPointerError, ParserError, ResolverError } from "./util/errors.js";
3
3
  import type $Refs from "./refs.js";
4
4
  import type $RefParserOptions from "./options.js";
5
- import type { JSONSchema } from "./types";
6
5
  type $RefError = JSONParserError | ResolverError | ParserError | MissingPointerError;
7
6
  /**
8
7
  * This class represents a single JSON reference and its resolved value.
@@ -100,7 +99,7 @@ declare class $Ref {
100
99
  * @param value - The value to inspect
101
100
  * @returns
102
101
  */
103
- static isExternal$Ref(value: any): value is JSONSchema;
102
+ static isExternal$Ref(value: any): boolean;
104
103
  /**
105
104
  * Determines whether the given value is a JSON reference, and whether it is allowed by the options.
106
105
  * For example, if it references an external file, then options.resolve.external must be true.
package/dist/lib/ref.js CHANGED
@@ -64,8 +64,7 @@ class $Ref {
64
64
  * @returns - Returns the resolved value
65
65
  */
66
66
  get(path, options) {
67
- var _a;
68
- return (_a = this.resolve(path, options)) === null || _a === void 0 ? void 0 : _a.value;
67
+ return this.resolve(path, options)?.value;
69
68
  }
70
69
  /**
71
70
  * Resolves the given JSON reference within this {@link $Ref#value}.
package/dist/lib/refs.js CHANGED
@@ -29,8 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const ono_1 = require("@jsdevtools/ono");
30
30
  const ref_js_1 = __importDefault(require("./ref.js"));
31
31
  const url = __importStar(require("./util/url.js"));
32
- const isWindows = /^win/.test(globalThis.process ? globalThis.process.platform : "");
33
- const getPathFromOs = (filePath) => (isWindows ? filePath.replace(/\\/g, "/") : filePath);
32
+ const convert_path_to_posix_1 = __importDefault(require("./util/convert-path-to-posix"));
34
33
  /**
35
34
  * When you call the resolve method, the value that gets passed to the callback function (or Promise) is a $Refs object. This same object is accessible via the parser.$refs property of $RefParser objects.
36
35
  *
@@ -49,7 +48,7 @@ class $Refs {
49
48
  paths(...types) {
50
49
  const paths = getPaths(this._$refs, types);
51
50
  return paths.map((path) => {
52
- return getPathFromOs(path.decoded);
51
+ return (0, convert_path_to_posix_1.default)(path.decoded);
53
52
  });
54
53
  }
55
54
  /**
@@ -63,7 +62,7 @@ class $Refs {
63
62
  const $refs = this._$refs;
64
63
  const paths = getPaths($refs, types);
65
64
  return paths.reduce((obj, path) => {
66
- obj[getPathFromOs(path.decoded)] = $refs[path.encoded].value;
65
+ obj[(0, convert_path_to_posix_1.default)(path.decoded)] = $refs[path.encoded].value;
67
66
  return obj;
68
67
  }, {});
69
68
  }
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -70,6 +61,7 @@ function resolveExternal(parser, options) {
70
61
  *
71
62
  * @param obj - The value to crawl. If it's not an object or array, it will be ignored.
72
63
  * @param path - The full path of `obj`, possibly with a JSON Pointer in the hash
64
+ * @param {boolean} external - Whether `obj` was found in an external document.
73
65
  * @param $refs
74
66
  * @param options
75
67
  * @param seen - Internal.
@@ -80,7 +72,7 @@ function resolveExternal(parser, options) {
80
72
  * If any of the JSON references point to files that contain additional JSON references,
81
73
  * then the corresponding promise will internally reference an array of promises.
82
74
  */
83
- function crawl(obj, path, $refs, options, seen) {
75
+ function crawl(obj, path, $refs, options, seen, external) {
84
76
  seen || (seen = new Set());
85
77
  let promises = [];
86
78
  if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !seen.has(obj)) {
@@ -88,17 +80,11 @@ function crawl(obj, path, $refs, options, seen) {
88
80
  if (ref_js_1.default.isExternal$Ref(obj)) {
89
81
  promises.push(resolve$Ref(obj, path, $refs, options));
90
82
  }
91
- else {
92
- for (const key of Object.keys(obj)) {
93
- const keyPath = pointer_js_1.default.join(path, key);
94
- const value = obj[key];
95
- if (ref_js_1.default.isExternal$Ref(value)) {
96
- promises.push(resolve$Ref(value, keyPath, $refs, options));
97
- }
98
- else {
99
- promises = promises.concat(crawl(value, keyPath, $refs, options, seen));
100
- }
101
- }
83
+ const keys = Object.keys(obj);
84
+ for (const key of keys) {
85
+ const keyPath = pointer_js_1.default.join(path, key);
86
+ const value = obj[key];
87
+ promises = promises.concat(crawl(value, keyPath, $refs, options, seen, external));
102
88
  }
103
89
  }
104
90
  return promises;
@@ -115,34 +101,33 @@ function crawl(obj, path, $refs, options, seen) {
115
101
  * The promise resolves once all JSON references in the object have been resolved,
116
102
  * including nested references that are contained in externally-referenced files.
117
103
  */
118
- function resolve$Ref($ref, path, $refs, options) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- // console.log('Resolving $ref pointer "%s" at %s', $ref.$ref, path);
121
- const resolvedPath = url.resolve(path, $ref.$ref);
122
- const withoutHash = url.stripHash(resolvedPath);
123
- // Do we already have this $ref?
124
- $ref = $refs._$refs[withoutHash];
125
- if ($ref) {
126
- // We've already parsed this $ref, so use the existing value
127
- return Promise.resolve($ref.value);
128
- }
129
- // Parse the $referenced file/url
130
- try {
131
- const result = yield (0, parse_js_1.default)(resolvedPath, $refs, options);
132
- // Crawl the parsed value
133
- // console.log('Resolving $ref pointers in %s', withoutHash);
134
- const promises = crawl(result, withoutHash + "#", $refs, options);
135
- return Promise.all(promises);
104
+ async function resolve$Ref($ref, path, $refs, options) {
105
+ const shouldResolveOnCwd = options.dereference.externalReferenceResolution === "root";
106
+ const resolvedPath = url.resolve(shouldResolveOnCwd ? url.cwd() : path, $ref.$ref);
107
+ const withoutHash = url.stripHash(resolvedPath);
108
+ // $ref.$ref = url.relative($refs._root$Ref.path, resolvedPath);
109
+ // Do we already have this $ref?
110
+ $ref = $refs._$refs[withoutHash];
111
+ if ($ref) {
112
+ // We've already parsed this $ref, so use the existing value
113
+ return Promise.resolve($ref.value);
114
+ }
115
+ // Parse the $referenced file/url
116
+ try {
117
+ const result = await (0, parse_js_1.default)(resolvedPath, $refs, options);
118
+ // Crawl the parsed value
119
+ // console.log('Resolving $ref pointers in %s', withoutHash);
120
+ const promises = crawl(result, withoutHash + "#", $refs, options, new Set(), true);
121
+ return Promise.all(promises);
122
+ }
123
+ catch (err) {
124
+ if (!options?.continueOnError || !(0, errors_js_1.isHandledError)(err)) {
125
+ throw err;
136
126
  }
137
- catch (err) {
138
- if (!(options === null || options === void 0 ? void 0 : options.continueOnError) || !(0, errors_js_1.isHandledError)(err)) {
139
- throw err;
140
- }
141
- if ($refs._$refs[withoutHash]) {
142
- err.source = decodeURI(url.stripHash(path));
143
- err.path = url.safePointerToPath(url.getHash(path));
144
- }
145
- return [];
127
+ if ($refs._$refs[withoutHash]) {
128
+ err.source = decodeURI(url.stripHash(path));
129
+ err.path = url.safePointerToPath(url.getHash(path));
146
130
  }
147
- });
131
+ return [];
132
+ }
148
133
  }
@@ -22,20 +22,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
25
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const promises_1 = __importDefault(require("fs/promises"));
26
+ const fs_1 = require("fs");
39
27
  const ono_1 = require("@jsdevtools/ono");
40
28
  const url = __importStar(require("../util/url.js"));
41
29
  const errors_js_1 = require("../util/errors.js");
@@ -55,22 +43,20 @@ exports.default = {
55
43
  /**
56
44
  * Reads the given file and returns its raw contents as a Buffer.
57
45
  */
58
- read(file) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- let path;
61
- try {
62
- path = url.toFileSystemPath(file.url);
63
- }
64
- catch (err) {
65
- throw new errors_js_1.ResolverError(ono_1.ono.uri(err, `Malformed URI: ${file.url}`), file.url);
66
- }
67
- try {
68
- const data = yield promises_1.default.readFile(path);
69
- return data;
70
- }
71
- catch (err) {
72
- throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error opening file "${path}"`), path);
73
- }
74
- });
46
+ async read(file) {
47
+ let path;
48
+ try {
49
+ path = url.toFileSystemPath(file.url);
50
+ }
51
+ catch (err) {
52
+ throw new errors_js_1.ResolverError(ono_1.ono.uri(err, `Malformed URI: ${file.url}`), file.url);
53
+ }
54
+ try {
55
+ const data = await fs_1.promises.readFile(path);
56
+ return data;
57
+ }
58
+ catch (err) {
59
+ throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error opening file "${path}"`), path);
60
+ }
75
61
  },
76
62
  };
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  const ono_1 = require("@jsdevtools/ono");
36
27
  const url = __importStar(require("../util/url.js"));
@@ -89,71 +80,67 @@ exports.default = {
89
80
  * @returns
90
81
  * The promise resolves with the raw downloaded data, or rejects if there is an HTTP error.
91
82
  */
92
- function download(u, httpOptions, _redirects) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- u = url.parse(u);
95
- const redirects = _redirects || [];
96
- redirects.push(u.href);
97
- try {
98
- const res = yield get(u, httpOptions);
99
- if (res.status >= 400) {
100
- throw (0, ono_1.ono)({ status: res.status }, `HTTP ERROR ${res.status}`);
83
+ async function download(u, httpOptions, _redirects) {
84
+ u = url.parse(u);
85
+ const redirects = _redirects || [];
86
+ redirects.push(u.href);
87
+ try {
88
+ const res = await get(u, httpOptions);
89
+ if (res.status >= 400) {
90
+ throw (0, ono_1.ono)({ status: res.status }, `HTTP ERROR ${res.status}`);
91
+ }
92
+ else if (res.status >= 300) {
93
+ if (!Number.isNaN(httpOptions.redirects) && redirects.length > httpOptions.redirects) {
94
+ throw new errors_js_1.ResolverError((0, ono_1.ono)({ status: res.status }, `Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`));
101
95
  }
102
- else if (res.status >= 300) {
103
- if (!Number.isNaN(httpOptions.redirects) && redirects.length > httpOptions.redirects) {
104
- throw new errors_js_1.ResolverError((0, ono_1.ono)({ status: res.status }, `Error downloading ${redirects[0]}. \nToo many redirects: \n ${redirects.join(" \n ")}`));
105
- }
106
- else if (!("location" in res.headers) || !res.headers.location) {
107
- throw (0, ono_1.ono)({ status: res.status }, `HTTP ${res.status} redirect with no location header`);
108
- }
109
- else {
110
- const redirectTo = url.resolve(u, res.headers.location);
111
- return download(redirectTo, httpOptions, redirects);
112
- }
96
+ else if (!("location" in res.headers) || !res.headers.location) {
97
+ throw (0, ono_1.ono)({ status: res.status }, `HTTP ${res.status} redirect with no location header`);
113
98
  }
114
99
  else {
115
- if (res.body) {
116
- const buf = yield res.arrayBuffer();
117
- return Buffer.from(buf);
118
- }
119
- return Buffer.alloc(0);
100
+ const redirectTo = url.resolve(u.href, res.headers.location);
101
+ return download(redirectTo, httpOptions, redirects);
120
102
  }
121
103
  }
122
- catch (err) {
123
- throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error downloading ${u.href}`), u.href);
104
+ else {
105
+ if (res.body) {
106
+ const buf = await res.arrayBuffer();
107
+ return Buffer.from(buf);
108
+ }
109
+ return Buffer.alloc(0);
124
110
  }
125
- });
111
+ }
112
+ catch (err) {
113
+ throw new errors_js_1.ResolverError((0, ono_1.ono)(err, `Error downloading ${u.href}`), u.href);
114
+ }
126
115
  }
127
116
  /**
128
117
  * Sends an HTTP GET request.
129
118
  * The promise resolves with the HTTP Response object.
130
119
  */
131
- function get(u, httpOptions) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- let controller;
134
- let timeoutId;
135
- if (httpOptions.timeout) {
136
- controller = new AbortController();
137
- timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout);
138
- }
139
- if (!global.fetch) {
140
- const { default: fetch, Request, Headers } = yield Promise.resolve().then(() => __importStar(require("node-fetch")));
141
- // @ts-ignore
142
- global.fetch = fetch;
143
- // @ts-ignore
144
- global.Request = Request;
145
- // @ts-ignore
146
- global.Headers = Headers;
147
- }
148
- const response = yield fetch(u, {
149
- method: "GET",
150
- headers: httpOptions.headers || {},
151
- credentials: httpOptions.withCredentials ? "include" : "same-origin",
152
- signal: controller ? controller.signal : null,
153
- });
154
- if (timeoutId) {
155
- clearTimeout(timeoutId);
156
- }
157
- return response;
120
+ async function get(u, httpOptions) {
121
+ let controller;
122
+ let timeoutId;
123
+ if (httpOptions.timeout) {
124
+ controller = new AbortController();
125
+ timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout);
126
+ }
127
+ if (!global.fetch) {
128
+ const { default: fetch, Request, Headers } = await Promise.resolve().then(() => __importStar(require("node-fetch")));
129
+ // @ts-ignore
130
+ global.fetch = fetch;
131
+ // @ts-ignore
132
+ global.Request = Request;
133
+ // @ts-ignore
134
+ global.Headers = Headers;
135
+ }
136
+ const response = await fetch(u, {
137
+ method: "GET",
138
+ headers: httpOptions.headers || {},
139
+ credentials: httpOptions.withCredentials ? "include" : "same-origin",
140
+ signal: controller ? controller.signal : null,
158
141
  });
142
+ if (timeoutId) {
143
+ clearTimeout(timeoutId);
144
+ }
145
+ return response;
159
146
  }
@@ -0,0 +1 @@
1
+ export default function convertPathToPosix(filePath: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ function convertPathToPosix(filePath) {
8
+ const isExtendedLengthPath = filePath.startsWith("\\\\?\\");
9
+ if (isExtendedLengthPath) {
10
+ return filePath;
11
+ }
12
+ return filePath.split(path_1.default.win32.sep).join(path_1.default.posix.sep);
13
+ }
14
+ exports.default = convertPathToPosix;
@@ -0,0 +1 @@
1
+ export declare const isWindows: () => boolean;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWindows = void 0;
4
+ const isWindowsConst = /^win/.test(globalThis.process ? globalThis.process.platform : "");
5
+ const isWindows = () => isWindowsConst;
6
+ exports.isWindows = isWindows;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.run = exports.sort = exports.filter = exports.all = void 0;
13
4
  /**
@@ -56,62 +47,60 @@ exports.sort = sort;
56
47
  * If the promise rejects, or the callback is called with an error, then the next plugin is called.
57
48
  * If ALL plugins fail, then the last error is thrown.
58
49
  */
59
- function run(plugins, method, file, $refs) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- let plugin;
62
- let lastError;
63
- let index = 0;
64
- return new Promise((resolve, reject) => {
65
- runNextPlugin();
66
- function runNextPlugin() {
67
- plugin = plugins[index++];
68
- if (!plugin) {
69
- // There are no more functions, so re-throw the last error
70
- return reject(lastError);
71
- }
72
- try {
73
- // console.log(' %s', plugin.name);
74
- const result = getResult(plugin, method, file, callback, $refs);
75
- if (result && typeof result.then === "function") {
76
- // A promise was returned
77
- result.then(onSuccess, onError);
78
- }
79
- else if (result !== undefined) {
80
- // A synchronous result was returned
81
- onSuccess(result);
82
- }
83
- else if (index === plugins.length) {
84
- throw new Error("No promise has been returned or callback has been called.");
85
- }
86
- }
87
- catch (e) {
88
- onError(e);
89
- }
50
+ async function run(plugins, method, file, $refs) {
51
+ let plugin;
52
+ let lastError;
53
+ let index = 0;
54
+ return new Promise((resolve, reject) => {
55
+ runNextPlugin();
56
+ function runNextPlugin() {
57
+ plugin = plugins[index++];
58
+ if (!plugin) {
59
+ // There are no more functions, so re-throw the last error
60
+ return reject(lastError);
90
61
  }
91
- function callback(err, result) {
92
- if (err) {
93
- onError(err);
62
+ try {
63
+ // console.log(' %s', plugin.name);
64
+ const result = getResult(plugin, method, file, callback, $refs);
65
+ if (result && typeof result.then === "function") {
66
+ // A promise was returned
67
+ result.then(onSuccess, onError);
94
68
  }
95
- else {
69
+ else if (result !== undefined) {
70
+ // A synchronous result was returned
96
71
  onSuccess(result);
97
72
  }
73
+ else if (index === plugins.length) {
74
+ throw new Error("No promise has been returned or callback has been called.");
75
+ }
98
76
  }
99
- function onSuccess(result) {
100
- // console.log(' success');
101
- resolve({
102
- plugin,
103
- result,
104
- });
77
+ catch (e) {
78
+ onError(e);
105
79
  }
106
- function onError(error) {
107
- // console.log(' %s', err.message || err);
108
- lastError = {
109
- plugin,
110
- error,
111
- };
112
- runNextPlugin();
80
+ }
81
+ function callback(err, result) {
82
+ if (err) {
83
+ onError(err);
84
+ }
85
+ else {
86
+ onSuccess(result);
113
87
  }
114
- });
88
+ }
89
+ function onSuccess(result) {
90
+ // console.log(' success');
91
+ resolve({
92
+ plugin,
93
+ result,
94
+ });
95
+ }
96
+ function onError(error) {
97
+ // console.log(' %s', err.message || err);
98
+ lastError = {
99
+ plugin,
100
+ error,
101
+ };
102
+ runNextPlugin();
103
+ }
115
104
  });
116
105
  }
117
106
  exports.run = run;
@@ -1,10 +1,10 @@
1
- export declare const parse: (u: any) => URL;
1
+ export declare const parse: (u: string | URL) => URL;
2
2
  /**
3
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
4
  *
5
5
  * @returns
6
6
  */
7
- export declare function resolve(from: any, to: any): string;
7
+ export declare function resolve(from: string, to: string): string;
8
8
  /**
9
9
  * Returns the current working directory (in Node) or the current page URL (in browsers).
10
10
  *
@@ -17,7 +17,7 @@ export declare function cwd(): string;
17
17
  * @param path
18
18
  * @returns
19
19
  */
20
- export declare function getProtocol(path: any): string | undefined;
20
+ export declare function getProtocol(path: string | undefined): string | undefined;
21
21
  /**
22
22
  * Returns the lowercased file extension of the given URL,
23
23
  * or an empty string if it has no extension.
@@ -62,7 +62,7 @@ export declare function isHttp(path: any): boolean;
62
62
  * @param path
63
63
  * @returns
64
64
  */
65
- export declare function isFileSystemPath(path: any): boolean;
65
+ export declare function isFileSystemPath(path: string | undefined): boolean;
66
66
  /**
67
67
  * Converts a filesystem path to a properly-encoded URL.
68
68
  *
@@ -91,3 +91,4 @@ export declare function toFileSystemPath(path: string | undefined, keepFileProto
91
91
  * @returns
92
92
  */
93
93
  export declare function safePointerToPath(pointer: any): any;
94
+ export declare function relative(from: string, to: string): string;