MCPcopy
hub / github.com/webpack/webpack / fetchPathsFromURL

Function fetchPathsFromURL

lib/util/extractSourceMap.js:105–137  ·  view source on GitHub ↗

* Fetch from multiple possible file paths * @param {ReadResource} readResource read resource function * @param {string[]} possibleRequests array of possible file paths * @param {string} errorsAccumulator accumulated error messages * @returns {Promise<{ path: string, data?: string }>} source cont

(
	readResource,
	possibleRequests,
	errorsAccumulator = ""
)

Source from the content-addressed store, hash-verified

103 * @returns {Promise<{ path: string, data?: string }>} source content promise
104 */
105async function fetchPathsFromURL(
106 readResource,
107 possibleRequests,
108 errorsAccumulator = ""
109) {
110 /** @type {StringOrBuffer} */
111 let result;
112
113 try {
114 result = await readResource(possibleRequests[0]);
115 } catch (error) {
116 errorsAccumulator += `${/** @type {Error} */ (error).message}\n\n`;
117
118 const [, ...tailPossibleRequests] = possibleRequests;
119
120 if (tailPossibleRequests.length === 0) {
121 /** @type {Error} */ (error).message = errorsAccumulator;
122
123 throw error;
124 }
125
126 return fetchPathsFromURL(
127 readResource,
128 tailPossibleRequests,
129 errorsAccumulator
130 );
131 }
132
133 return {
134 path: possibleRequests[0],
135 data: result.toString("utf8")
136 };
137}
138
139/**
140 * Fetch source content from URL

Callers 1

fetchFromURLFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected