Skip to content

Commit ad3cffd

Browse files
authored
feat: add configurable Root.prototype.fetch
1 parent 1b8aa8f commit ad3cffd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,14 @@ export class Root extends NamespaceBase {
12431243
*/
12441244
public resolvePath(origin: string, target: string): (string|null);
12451245

1246+
/**
1247+
* Fetch content from file path or url
1248+
* This method exists so you can override it with your own logic.
1249+
* @param path File path or url
1250+
* @param callback Callback function
1251+
*/
1252+
public fetch(path: string, callback: FetchCallback): void;
1253+
12461254
/**
12471255
* Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
12481256
* @param filename Names of one or multiple files to load

src/root.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ Root.fromJSON = function fromJSON(json, root) {
6161
*/
6262
Root.prototype.resolvePath = util.path.resolve;
6363

64+
/**
65+
* Fetch content from file path or url
66+
* This method exists so you can override it with your own logic.
67+
* @function
68+
* @param {string} path File path or url
69+
* @param {FetchCallback} callback Callback function
70+
* @returns {undefined}
71+
*/
72+
Root.prototype.fetch = util.fetch;
73+
6474
// A symbol-like function to safely signal synchronous loading
6575
/* istanbul ignore next */
6676
function SYNC() {} // eslint-disable-line no-empty-function
@@ -168,7 +178,7 @@ Root.prototype.load = function load(filename, options, callback) {
168178
process(filename, source);
169179
} else {
170180
++queued;
171-
util.fetch(filename, function(err, source) {
181+
self.fetch(filename, function(err, source) {
172182
--queued;
173183
/* istanbul ignore if */
174184
if (!callback)

0 commit comments

Comments
 (0)