diff --git a/index.d.ts b/index.d.ts index 42830df00..b6d4b56f1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1243,6 +1243,14 @@ export class Root extends NamespaceBase { */ public resolvePath(origin: string, target: string): (string|null); + /** + * Fetch content from file path or url + * This method exists so you can override it with your own logic. + * @param path File path or url + * @param callback Callback function + */ + public fetch(path: string, callback: FetchCallback): void; + /** * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback. * @param filename Names of one or multiple files to load diff --git a/src/root.js b/src/root.js index 79c270f28..df6f11fa6 100644 --- a/src/root.js +++ b/src/root.js @@ -61,6 +61,16 @@ Root.fromJSON = function fromJSON(json, root) { */ Root.prototype.resolvePath = util.path.resolve; +/** + * Fetch content from file path or url + * This method exists so you can override it with your own logic. + * @function + * @param {string} path File path or url + * @param {FetchCallback} callback Callback function + * @returns {undefined} + */ +Root.prototype.fetch = util.fetch; + // A symbol-like function to safely signal synchronous loading /* istanbul ignore next */ function SYNC() {} // eslint-disable-line no-empty-function @@ -168,7 +178,7 @@ Root.prototype.load = function load(filename, options, callback) { process(filename, source); } else { ++queued; - util.fetch(filename, function(err, source) { + self.fetch(filename, function(err, source) { --queued; /* istanbul ignore if */ if (!callback)