将 devDependencies 写入 package.json

@param {object} devDependencies 待写入的 devDependencies
@returns {Promise} Promise
967950
function writePackageJson (devDependencies) {
  debug('input devDependencies: %o', devDependencies)

  if (!lodash.isPlainObject(devDependencies)) {
    debug('devDependencies isn\'t plain object, return')
    // 不报错
    return Promise.resolve()
  }

  const baseDir = getBaseDir()
  const pkgPath = path.join(baseDir, 'package.json')

  debug(`package.json: ${pkgPath}`)

  if (!fs.existsSync(pkgPath)) {
    debug(`file not exists: ${pkgPath}, return`)
    return Promise.resolve()
  }

  let content

  try {
    content = JSON.parse(fs.readFileSync(pkgPath))
  } catch (error) {
    debug('parse package.json error')
    return Promise.resolve()
  }

  content.devDependencies = sort(Object.assign(
    {},
    content.devDependencies || {},
    devDependencies
  ))

  return writeJsonFile(pkgPath, content, {
    detectIndent: true
  })
}
1330109
function getAllDependencies() {
    var folder = './' + getBowerFolder();
    var bowerDependencies = fs.readdirSync(folder, {encoding: 'utf8'});

    var dependencyInfos = [];
    bowerDependencies.forEach(function(dirname) {
        var filepath = nodePath.resolve(cwd, folder, dirname, '.bower.json');
        if (fs.existsSync(filepath)) {
            var dependencyInfo = getDependency(filepath);
            dependencyInfo.dirName = dirname;
            dependencyInfos.push(dependencyInfo);
        }
    });

    return dependencyInfos;
}
1132285
function getDependencies (injector, dependencies) {
  return dependencies.map((name) => {
    let dependency = injector.getComponent(name);

    if (!dependency) {
      /* Anything starting 'npm:' is automatically included */
      if (/^npm:/.test(name)) {
        const npmModule = name.substr(4);

        injector.registerComponent({
          // eslint-disable-next-line import/no-dynamic-require, global-require
          factory: () => require(npmModule),
          name,
        });

        dependency = injector.getComponent(name);
      } else {
        throw new Error(`Missing dependency: ${name}`);
      }
    }

    /* If instance hasn't already been processed, process it */
    if (!dependency.instance) {
      dependency.instance = injector.process(dependency.factory, dependency.deps);
    }

    return dependency.instance;
  });
}
682556
async function aggregateBoltDependencies(data) {
  let componentDependencies = [];
  let componentsWithoutDeps = data;

  componentsWithoutDeps.forEach(item => {
    if (item.deps) {
      componentDependencies.push([...item.deps]);
    }
  });

  componentDependencies = flattenDeep(componentDependencies);

  componentDependencies = componentDependencies.filter(function(x, i, a) {
    if (x !== '@bolt/build-tools' && a.indexOf(x) === i) {
      return x;
    }
  });

  let globalDepsSrc = await Promise.all(componentDependencies.map(getPkgInfo));

  componentsWithoutDeps = componentsWithoutDeps.concat(globalDepsSrc);

  var uniqueComponentsWithDeps = removeDuplicateObjectsFromArray(
    componentsWithoutDeps,
    'name',
  );

  return uniqueComponentsWithDeps;
}
1011370
function (name) {
        if (_.has(this.json.dependencies, name)) {
          return 'dependencies';
        }
        if (_.has(this.json.devDependencies, name)) {
          return 'devDependencies';
        }
        return false;
      }
900706
function resolveTransitiveDependencies(module, hash) {
    if (!(module instanceof Module)) {
      return Promise.reject("Unable to resolve module of type " + typeof(module));
    }

    var promises = [];
    for (var i in module.dependencies) {
      (function(dependencyName) {

        /* Ignore already resolved dependencies */
        if (hash[dependencyName]) return;

        /* Get a module or a promise to it and put it in the hash NOW! */
        var dependency = hash[dependencyName] = moduleOrPromise(dependencyName);

        /* Transitively resolve the dependency */
        promises.push(Promise.resolve(dependency).then(function(dependency) {
          hash[dependencyName] = dependency;
          return resolveTransitiveDependencies(dependency, hash);
        }));

      })(module.dependencies[i]);
    }

    return Promise.all(promises).then(function() {
      return hash;
    });
  }
797119
public function addClassDependency(string $class, string $package, bool $required = true, bool $devDependency = false)
    {
        if ($devDependency) {
            $this->devDependencies[] = [
                'class' => $class,
                'name' => $package,
                'required' => $required,
            ];
        } else {
            $this->dependencies[] = [
                'class' => $class,
                'name' => $package,
                'required' => $required,
            ];
        }
    }
1146377
function(context, pkg, isRoot) {
		var deps = crawl.getDependencies(context.loader, pkg, isRoot);

		return Promise.all(utils.filter(utils.map(deps, function(childPkg){
			return crawl.fetchDep(context, pkg, childPkg, isRoot);
		}), truthy)).then(function(packages){
 			// at this point all dependencies of pkg have been loaded, it's ok to get their children

			return Promise.all(utils.map(packages, function(childPkg){
				// Also load 'steal' so that the builtins will be configured
				if(childPkg && childPkg.name === 'steal') {
					return crawl.deps(context, childPkg);
				}
			})).then(function(){
				return packages;
			});
		});
	}
719356
function orderByDependencies(packages) {
  const packageDependencyGraph = pkg =>
    R.pipe(
      allDeps,
      R.map(dependencyName => [dependencyName, pkg.name]),
    )(pkg)

  // :: Array<Package> -> Array<Array<string, string>>
  const dependencyGraph = R.chain(packageDependencyGraph)

  // :: Package -> bool
  const hasNoDependencies = ({ dependencies }) => dependencies.length === 0

  // :: Array<Package>
  const packagesWithNoDependencies = R.pipe(
    R.filter(hasNoDependencies),
    R.map(R.prop('name')),
  )(packages)

  // :: string -> Package
  const findPackageByName = R.map(name =>
    R.find(R.propEq('name', name), packages),
  )

  return R.pipe(
    dependencyGraph,
    toposort,
    R.without(packagesWithNoDependencies),
    R.concat(packagesWithNoDependencies),
    findPackageByName,
  )(packages)
}
9802
function getDependencies(component, Prism) {
    // Cast require to an Array
    const deps = [].concat(component.require || []);

    if (Prism) {
        return deps.filter(
            dep =>
                // Remove dependencies that are already loaded
                !Prism.languages[dep]
        );
    }
    return deps;
}
298240
function fetchDependentPackages( $dependencyType, &$failedList )
    {
        $packages = array();
        $provides = $this->Parameters['dependencies'][$dependencyType];

        if ( $provides != null )
        {
            foreach ( $provides as $provide )
            {
                // fetch only dependent packages, not package items.
                if ( $provide['type'] == 'ezpackage' )
                {
                    // TODO: Add fetching from URL (not here ?)
                    $package = $this->fetch( $provide['name'] );

                    if ( !$package )
                    {
                        $failedList[] = $provide['name'];
                        continue;
                    }
                    $packages[] =& $package;
                }
            }
        }
        return $packages;
    }
40636
function (options, callback) {
        options = extend({}, DEPENDENCY_WRITE_DEFAULTS, options)
        var json = require(options.jsonUri)

        // the JSON DSL has the option to have "/foo" in <moduleNameLeft>
        after.reduce(json, createFoldersIntoFilesIterator(options.uri), 
            {}, runDependencyMapper)

        function runDependencyMapper(err, data) {
            if (err) {
                return callback(err)
            }
            after.map(data, mapToDependencies, callback)
        }

        function mapToDependencies(dependencies, moduleName, callback) {
            if (isFile.test(moduleName)) {
                // the JSON DSL has the option to have "/foo" or ["/foo"]
                // in <moduleNameRight>.
                after.map(dependencies, createConvertToProxyNameIterator({
                    moduleName: moduleName,
                    uri: options.uri
                }), callback)
            }
        }
    }
429764
function (dependencies, extension) {
            if (dependencies) {
                for (var i = dependencies.length - 1; i >= 0; i--) {
                    this.addDependency(dependencies[i], extension);
                }
            }
        }
1269375
function queueDependency(dep) {
            //Make sure to load any plugin and associate the dependency
            //with that plugin.
            var prefix = dep.prefix,
                fullName = dep.fullName;

            //Do not bother if the depName is already in transit
            if (specified[fullName] || fullName in defined) {
                return;
            }

            if (prefix && !plugins[prefix]) {
                //Queue up loading of the dependency, track it
                //via context.plugins. Mark it as a plugin so
                //that the build system will know to treat it
                //special.
                plugins[prefix] = undefined;

                //Remember this dep that needs to have normaliztion done
                //after the plugin loads.
                (normalizedWaiting[prefix] || (normalizedWaiting[prefix] = []))
                    .push(dep);

                //Register an action to do once the plugin loads, to update
                //all managerCallbacks to use a properly normalized module
                //name.
                (managerCallbacks[prefix] ||
                (managerCallbacks[prefix] = [])).push({
                    onDep: function (name, value) {
                        if (name === prefix) {
                            updateNormalizedNames(prefix);
                        }
                    }
                });

                queueDependency(makeModuleMap(prefix));
            }

            context.paused.push(dep);
        }
650548
function dependencies(dependencyObject) {
    'use strict';

    function extractSpecificPath(depPath, loadType) {
        if (typeof depPath === 'object') {
            return depPath[loadType];
        }

        return depPath;
    }

    var depNames, depPaths;

    depNames = Object.keys(dependencyObject);
    depPaths = depNames.map(function (depName) {return dependencyObject[depName]; });

    function init(root, factory) {

        if (typeof module === 'object' && module.exports) {
            // Node/CommonJS
            console.log("NODE MODE");
            factory.apply(root, depPaths.map(function (depPath) {return require(extractSpecificPath(depPath, 'node')); }));
        } else if (typeof define === 'function' && define.amd) {
            // AMD
            console.log("AMD MODE");
            define(depPaths.map(function (depPath) { return extractSpecificPath(depPath, 'browser'); }), factory);
        } else {
            // Browser globals
            console.log("GLOBALS MODE");
            factory.apply(root, depNames.map(function (depName) {return root[depName]; }));
        }
    }

    return { init: init };
}
512373
function dependentLink (pkg, cb) {
  asyncMap(pkg._resolvedDeps, function (dep, cb) {
    var dependents = path.join(npm.dir, dep.name, dep.version, "dependents")
      , to = path.join(dependents, pkg.name + "@" + pkg.version)
      , from = path.join(npm.dir, pkg.name, pkg.version)
    link(from, to, cb)
  }, cb)
}
484255
function searchDependencies (dependencies, root) {
  if (!dependencies) {
    return Promise.resolve([])
  } else {
    var pluginPkgPath
    var pluginPkgPaths = []
    for (var key in dependencies) {
      pluginPkgPath = path.join(root, 'node_modules', key)
      pluginPkgPaths.push(pluginPkgPath)
    }
    return Promise.all(pluginPkgPaths.map(function (pkgRoot) {
      var pkgPath = path.join(pkgRoot, 'package.json')
      return readJSON(pkgPath)
        .then(function (pkg) {
          if (pkg.vigour && pkg.vigour.plugin) {
            return searchDependencies(pkg.dependencies, pkgRoot)
              .then(function (deps) {
                return searchDependencies(pkg.dependencies, root)
                  .then(function (otherDeps) {
                    return deps.concat(otherDeps)
                  })
              })
          } else {
            return false
          }
        })
        .catch(function (reason) {
          return false
        })
    }))
    .then(function (arr) {
      arr = _flatten(arr)
      return pluginPkgPaths.concat(arr.reduce(function (prev, curr) {
        if (curr) {
          prev.push(curr)
        }
        return prev
      }, []))
    })
  }
}