lib/dev.js
function (source, target, isExternal) {
  // Clone source
  var pkg = JSON.parse(JSON.stringify(source));

  // Validation of source package.
  ["name", "description"].forEach(function (name) {
    if (!pkg[name]) {
      throw new Error("Source object missing field: " + name);
    }
  });

  var nameRe = new RegExp("(^|.*\/)(" + source.name + ")(\/.*|$)");

  // Update with internal "development" names
  pkg.name += "-dev";
  pkg.description += " (Development)";

  // Update external fields to add `-dev` if applicable and present.
  if (isExternal) {
    [
      "repository.url",
      "bugs.url",
      "homepage"
    ].forEach(function (paths) {
      // Traverse the package structure.
      var parts = paths.split(".");
      var pkgPart = pkg;
      parts.forEach(function (part, i) {
        if (pkgPart && pkgPart[part]) {
          if (i + 1 === parts.length) {
            // Done! Update part if present.
            if (nameRe.test(pkgPart[part])) {
              pkgPart[part] = pkgPart[part].replace(nameRe, "$1" + pkg.name + "$3");
            }
            return;
          }

          // Increment
          pkgPart = pkgPart[part];
          return;
        }

        // Failed.
        pkgPart = null;
      });
    });
  }

  // Copy back in dependencies from dev package
  pkg.dependencies = (target || {}).dependencies || {};
  pkg.peerDependencies = (target || {}).peerDependencies || {};

  // Remove scripts, dev deps, etc.
  pkg.scripts = {};
  pkg.devDependencies = {};

  return pkg;
}
function (source, target, isExternal) {
  // Clone source
  var pkg = JSON.parse(JSON.stringify(source));

  // Validation of source package.
  ["name", "description"].forEach(function (name) {
    if (!pkg[name]) {
      throw new Error("Source object missing field: " + name);
    }
  });

  var nameRe = new RegExp("(^|.*\/)(" + source.name + ")(\/.*|$)");

  // Update with internal "development" names
  pkg.name += "-dev";
  pkg.description += " (Development)";

  // Update external fields to add `-dev` if applicable and present.
  if (isExternal) {
    [
      "repository.url",
      "bugs.url",
      "homepage"
    ].forEach(function (paths) {
      // Traverse the package structure.
      var parts = paths.split(".");
      var pkgPart = pkg;
      parts.forEach(function (part, i) {
        if (pkgPart && pkgPart[part]) {
          if (i + 1 === parts.length) {
            // Done! Update part if present.
            if (nameRe.test(pkgPart[part])) {
              pkgPart[part] = pkgPart[part].replace(nameRe, "$1" + pkg.name + "$3");
            }
            return;
          }

          // Increment
          pkgPart = pkgPart[part];
          return;
        }

        // Failed.
        pkgPart = null;
      });
    });
  }

  // Copy back in dependencies from dev package
  pkg.dependencies = (target || {}).dependencies || {};
  pkg.peerDependencies = (target || {}).peerDependencies || {};

  // Remove scripts, dev deps, etc.
  pkg.scripts = {};
  pkg.devDependencies = {};

  return pkg;
}
function ( source , target , isExternal ) { // Clone source var pkg = JSON . parse ( JSON . stringify ( source ) ) ; // Validation of source package. [ "name" , "description" ] . forEach ( function ( name ) { if ( ! pkg [ name ] ) { throw new Error ( "Source object missing field: " + name ) ; } } ) ; var nameRe = new RegExp ( "(^|.*\/)(" + source . name + ")(\/.*|$)" ) ; // Update with internal "development" names pkg . name += "-dev" ; pkg . description += " (Development)" ; // Update external fields to add `-dev` if applicable and present. if ( isExternal ) { [ "repository.url" , "bugs.url" , "homepage" ] . forEach ( function ( paths ) { // Traverse the package structure. var parts = paths . split ( "." ) ; var pkgPart = pkg ; parts . forEach ( function ( part , i ) { if ( pkgPart && pkgPart [ part ] ) { if ( i + 1 === parts . length ) { // Done! Update part if present. if ( nameRe . test ( pkgPart [ part ] ) ) { pkgPart [ part ] = pkgPart [ part ] . replace ( nameRe , "$1" + pkg . name + "$3" ) ; } return ; } // Increment pkgPart = pkgPart [ part ] ; return ; } // Failed. pkgPart = null ; } ) ; } ) ; } // Copy back in dependencies from dev package pkg . dependencies = ( target || { } ) . dependencies || { } ; pkg . peerDependencies = ( target || { } ) . peerDependencies || { } ; // Remove scripts, dev deps, etc. pkg . scripts = { } ; pkg . devDependencies = { } ; return pkg ; }
Update `target` JSON structure with fields from `source`.

@param {Object}  source      Source JSON object
@param {Object}  target      Target JSON object
@param {Boolean} isExternal  Is external (`../NAME-dev`) dev package.
@returns {Object}            Updated JSON object
Update target JSON structure with fields from source .