MCPcopy Create free account
hub / github.com/ember-cli/ember-cli / _findPackage

Method _findPackage

lib/models/package-info-cache/index.js:368–393  ·  view source on GitHub ↗
(packageName, startPath)

Source from the content-addressed store, hash-verified

366 * @param {String} the path of the directory to start searching from
367 */
368 _findPackage(packageName, startPath) {
369 let parsedPath = path.parse(startPath);
370 let root = parsedPath.root;
371
372 let currPath = startPath;
373
374 while (currPath !== root) {
375 let endsWithNodeModules = path.basename(currPath) === 'node_modules';
376
377 let nodeModulesPath = endsWithNodeModules ? currPath : `${currPath}${path.sep}node_modules`;
378
379 let nodeModulesList = this._readNodeModulesList(nodeModulesPath);
380
381 // _readNodeModulesList only returns a NodeModulesList or null
382 if (nodeModulesList) {
383 let pkg = nodeModulesList.findPackage(packageName);
384 if (pkg) {
385 return pkg;
386 }
387 }
388
389 currPath = path.dirname(currPath);
390 }
391
392 return null;
393 }
394
395 /**
396 * Given a directory that supposedly contains a package, create a PackageInfo

Callers 1

addDependenciesMethod · 0.80

Calls 2

_readNodeModulesListMethod · 0.95
findPackageMethod · 0.80

Tested by

no test coverage detected