MCPcopy
hub / github.com/webpack/webpack / _getManagedItemInfo

Method _getManagedItemInfo

lib/FileSystemInfo.js:4395–4463  ·  lib/FileSystemInfo.js::FileSystemInfo._getManagedItemInfo

* @private * @type {Processor<string, string>}

(path, callback)

Source from the content-addressed store, hash-verified

4393 * @type {Processor<string, string>}
4394 */
4395 _getManagedItemInfo(path, callback) {
4396 const dir = dirname(this.fs, path);
4397 this.managedItemDirectoryQueue.add(dir, (err, elements) => {
4398 if (err) {
4399 return callback(err);
4400 }
4401 if (!(/** @type {Set<string>} */ (elements).has(path))) {
4402 class="cm">// file or directory doesn't exist
4403 this._managedItems.set(path, class="st">"*missing");
4404 return callback(null, class="st">"*missing");
4405 }
4406 class="cm">// something exists
4407 class="cm">// it may be a file or directory
4408 if (
4409 path.endsWith(class="st">"node_modules") &&
4410 (path.endsWith(class="st">"/node_modules") || path.endsWith(class="st">"\\node_modules"))
4411 ) {
4412 class="cm">// we are only interested in existence of this special directory
4413 this._managedItems.set(path, class="st">"*node_modules");
4414 return callback(null, class="st">"*node_modules");
4415 }
4416
4417 class="cm">// we assume itclass="st">'s a directory, as files shouldn't occur in managed paths
4418 const packageJsonPath = join(this.fs, path, class="st">"package.json");
4419 this.fs.readFile(packageJsonPath, (err, content) => {
4420 if (err) {
4421 if (err.code === class="st">"ENOENT" || err.code === class="st">"ENOTDIR") {
4422 class="cm">// no package.json or path is not a directory
4423 this.fs.readdir(path, (err, elements) => {
4424 if (
4425 !err &&
4426 /** @type {string[]} */ (elements).length === 1 &&
4427 /** @type {string[]} */ (elements)[0] === class="st">"node_modules"
4428 ) {
4429 class="cm">// This is only a grouping folder e.g. used by yarn
4430 class="cm">// we are only interested in existence of this special directory
4431 this._managedItems.set(path, class="st">"*nested");
4432 return callback(null, class="st">"*nested");
4433 }
4434 /** @type {Logger} */
4435 (this.logger).warn(
4436 `Managed item ${path} isnclass="st">'t a directory or doesn't contain a package.json (see snapshot.managedPaths option)`
4437 );
4438 return callback();
4439 });
4440 return;
4441 }
4442 return callback(/** @type {WebpackError} */ (err));
4443 }
4444 /** @type {JsonObject} */
4445 let data;
4446 try {
4447 data = JSON.parse(/** @type {Buffer} */ (content).toString(class="st">"utf8"));
4448 } catch (parseErr) {
4449 return callback(/** @type {WebpackError} */ (parseErr));
4450 }
4451 if (!data.name) {
4452 /** @type {Logger} */

Callers

nothing calls this directly

Calls 10

dirnameFunction · 0.85
joinFunction · 0.85
readFileMethod · 0.80
warnMethod · 0.80
callbackFunction · 0.50
addMethod · 0.45
hasMethod · 0.45
setMethod · 0.45
parseMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected