MCPcopy
hub / github.com/webpack/webpack / getDescriptionFile

Function getDescriptionFile

lib/sharing/utils.js:306–364  ·  view source on GitHub ↗
(
	fs,
	directory,
	descriptionFiles,
	callback,
	satisfiesDescriptionFileData,
	checkedFilePaths = new Set()
)

Source from the content-addressed store, hash-verified

304 * @param {Set<string>} checkedFilePaths set of file paths that have been checked
305 */
306const getDescriptionFile = (
307 fs,
308 directory,
309 descriptionFiles,
310 callback,
311 satisfiesDescriptionFileData,
312 checkedFilePaths = new Set()
313) => {
314 let i = 0;
315
316 const satisfiesDescriptionFileDataInternal = {
317 check: satisfiesDescriptionFileData,
318 checkedFilePaths
319 };
320
321 const tryLoadCurrent = () => {
322 if (i >= descriptionFiles.length) {
323 const parentDirectory = dirname(fs, directory);
324 if (!parentDirectory || parentDirectory === directory) {
325 return callback(null, undefined, [
326 ...satisfiesDescriptionFileDataInternal.checkedFilePaths
327 ]);
328 }
329 return getDescriptionFile(
330 fs,
331 parentDirectory,
332 descriptionFiles,
333 callback,
334 satisfiesDescriptionFileDataInternal.check,
335 satisfiesDescriptionFileDataInternal.checkedFilePaths
336 );
337 }
338 const filePath = join(fs, directory, descriptionFiles[i]);
339 readJson(fs, filePath, (err, data) => {
340 if (err) {
341 if ("code" in err && err.code === "ENOENT") {
342 i++;
343 return tryLoadCurrent();
344 }
345 return callback(err);
346 }
347 if (!data || typeof data !== "object" || Array.isArray(data)) {
348 return callback(
349 new Error(`Description file ${filePath} is not an object`)
350 );
351 }
352 if (
353 typeof satisfiesDescriptionFileDataInternal.check === "function" &&
354 !satisfiesDescriptionFileDataInternal.check({ data, path: filePath })
355 ) {
356 i++;
357 satisfiesDescriptionFileDataInternal.checkedFilePaths.add(filePath);
358 return tryLoadCurrent();
359 }
360 callback(null, { data, path: filePath });
361 });
362 };
363 tryLoadCurrent();

Callers 2

tryLoadCurrentFunction · 0.85

Calls 1

tryLoadCurrentFunction · 0.85

Tested by

no test coverage detected