Ensure that package.json is checked in and unmodified
@return {Promise<boolean>} true, if everything is fine
969015
function checkPackageJsonInGit () {
  return exec('git', ['status', '--porcelain', 'package.json'])
    .then(function ([stdout, stderr]) {
      debug('git status --porcelain package.json', 'stdout', stdout, 'stderr', stderr)
      if (stdout.indexOf('package.json') >= 0) {
        throw new Error('package.json has changes!\n' +
          'I would like to add scripts to your package.json, but ' +
          'there are changes that have not been commited yet.\n' +
          'I don\'t want to damage anything, so I\'m not doing anyhting right now. ' +
          'Please commit your package.json')
      }
    })
}
603875
function isInstallationAlreadyPerformed(ctx) {
  var pathToInstallFlag = path.join(ctx.opts.projectRoot, 'plugins', ctx.opts.plugin.id, INSTALLATION_FLAG_FILE_NAME);
  try {
    fs.accessSync(pathToInstallFlag, fs.F_OK);
    return true;
  } catch (err) {
    return false;
  }
}
1311564
function validateAndUpgrade(argv: Array<string>, ctx: ConfigT) {
  const projectDir = ctx.root;

  const packageJSON = JSON.parse(
    fs.readFileSync(path.resolve(projectDir, 'package.json'), 'utf8'),
  );

  warn(
    'You should consider using the new upgrade tool based on Git. It ' +
      'makes upgrades easier by resolving most conflicts automatically.\n' +
      'To use it:\n' +
      '- Go back to the old version of React Native\n' +
      '- Run "npm install -g react-native-git-upgrade"\n' +
      '- Run "react-native-git-upgrade"\n' +
      'See https://facebook.github.io/react-native/docs/upgrading.html',
  );

  const projectName = packageJSON.name;
  if (!projectName) {
    warn(
      'Your project needs to have a name, declared in package.json, ' +
        'such as "name": "AwesomeApp". Please add a project name. Aborting.',
    );
    return;
  }

  const version = packageJSON.dependencies['react-native'];
  if (!version) {
    warn(
      'Your "package.json" file doesn\'t seem to declare "react-native" as ' +
        'a dependency. Nothing to upgrade. Aborting.',
    );
    return;
  }

  if (version === 'latest' || version === '*') {
    warn(
      'Some major releases introduce breaking changes.\n' +
        'Please use a caret version number in your "package.json" file \n' +
        'to avoid breakage. Use e.g. react-native: ^0.38.0. Aborting.',
    );
    return;
  }

  const installed = JSON.parse(
    fs.readFileSync(
      path.resolve(projectDir, 'node_modules/react-native/package.json'),
      'utf8',
    ),
  );

  if (!semver.satisfies(installed.version, version)) {
    warn(
      'react-native version in "package.json" doesn\'t match ' +
        'the installed version in "node_modules".\n' +
        'Try running "npm install" to fix this. Aborting.',
    );
    return;
  }

  const v = version.replace(/^(~|\^|=)/, '').replace(/x/i, '0');

  if (!semver.valid(v)) {
    warn(
      "A valid version number for 'react-native' is not specified in your " +
        "'package.json' file. Aborting.",
    );
    return;
  }

  logger.info(
    `Upgrading project to react-native v${installed.version}\n` +
      'Check out the release notes and breaking changes: ' +
      `https://github.com/facebook/react-native/releases/tag/v${semver.major(
        v,
      )}.${semver.minor(v)}.0`,
  );

  // >= v0.21.0, we require react to be a peer dependency
  if (semver.gte(v, '0.21.0') && !packageJSON.dependencies.react) {
    warn(
      'Your "package.json" file doesn\'t seem to have "react" as a dependency.\n' +
        '"react" was changed from a dependency to a peer dependency in react-native v0.21.0.\n' +
        'Therefore, it\'s necessary to include "react" in your project\'s dependencies.\n' +
        'Please run "npm install --save react", then re-run "react-native upgrade".\n',
    );
    return;
  }

  if (semver.satisfies(v, '~0.26.0')) {
    warn(
      'React Native 0.26 introduced some breaking changes to the native files on iOS. You can\n' +
        'perform them manually by checking the release notes or use "rnpm" ' +
        'to do it automatically.\n' +
        'Just run:\n' +
        '"npm install -g rnpm && npm install rnpm-plugin-upgrade@0.26 --save-dev", ' +
        'then run "rnpm upgrade".',
    );
  }

  upgradeProjectFiles(projectDir, projectName);

  logger.info(
    `Successfully upgraded this project to react-native v${installed.version}`,
  );
}
73446
function updatePackageJSONVersion() {
  let packageJSONPath = path.join(__dirname, '..', 'package.json');

  let pkgContents = fs.readFileSync(packageJSONPath, { encoding: 'utf-8' });
  let pkg = JSON.parse(pkgContents);
  if (!pkg._originalVersion) {
    pkg._originalVersion = pkg.version;
  }
  pkg._versionPreviouslyCalculated = true;
  pkg.version = buildInfo.version;
  fs.writeFileSync(packageJSONPath, JSON.stringify(pkg, null, 2), {
    encoding: 'utf-8',
  });
}
791155
function (packageList)
		{
			if (!_.isObject(packageList))
				return false;

			var pkgList = _.keys(packageList);
			var pkgRequire;
			var pkgName;
			var pkgInfo;
			var depName;
			var depVersion;
			var i=0;
			var valid;
			var error;
			while (pkgList.length > 0)
			{
				valid=true;
				error=[];
				pkgName=pkgList[i];
				pkgInfo=packageList[pkgName];
				pkgRequire=pkgInfo.require;

				for (p in pkgRequire)
				{
					depName = p;
					depVersion = pkgRequire[p];
					if (packageList[depName]==undefined)
					{ error.push(depName+'@'+depVersion+' is not installed.'); continue; }
					if (depVersion!=="*" && packageList[depName].version!=depVersion)
					{ error.push(depName+' needs to be '+depVersion); }
				}

				if (valid||error.length>0)
				{
					if (error.length>0)
					{
						delete packageList[pkgName];
						for (e in error)
							self.e.log('Error on loading `'+pkgName+'`: '+error[e],'error');
					}
				
					pkgList.splice(i,1);
				}

				i++;
				if (i>=pkgList.length)
					i=0;
			}
		}
510459
function updateVersion () {
    start(`Updating ${"package.json".cyan} version from ${oldVersion.cyan} to ${newVersion.cyan}...`);
    pkg.version = newVersion;
    fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
    done();
    abortCmds.push('git checkout package.json');
    pushCmds.push('git add package.json');
  }
1114074
function packageVersion(repo) {
    var location = repo ? path.join(repo, 'package.json') : './package.json';
    var pack = require(location);
    return pack['version'];
}
897433
function ensureDir(dir) {
  return new Promise((resolve, reject) => {
    try {
      FS.ensureDirSync(dir);
      resolve(dir);
    } catch (err) {
      reject(err);
    }
  });
}
1083402
function checkIfVersionUpdated() {

        var latestBuildNumber = updateJsonHandler.get("latestBuildNumber"),
            currentBuildNumber = Number(/-([0-9]+)/.exec(brackets.metadata.version)[1]);

        return latestBuildNumber === currentBuildNumber;
    }
892172
function visitPackageJSON(folderPath)
{
  let files = fs.readdirSync(folderPath);
  for (var i in files) {
    let name = files[i];
    let filePath = path.join(folderPath, files[i]);
    if(fs.statSync(filePath).isDirectory()) {
      visitPackageJSON(filePath);
    } else {
      if (name === 'package.json') {
        try {
          patchPackageJSON_preNodeGyp_modulePath(filePath);
        } catch (e) {
          console.warn(
            'Failed to patch the file : "' +
            filePath +
            '". The following error was thrown: ' +
            JSON.stringify(e)
          );
        }
      }
    }
  }
}
948674
protected function areReposConfigured()
    {
        if (! $this->json) {
            $this->readJson();
        }
        
        return ! empty($this->json['repositories']) && $this->pregGrepRecursive('/^http(s|\?)?:\/\/wpackagist\.org\/?$/', $this->json['repositories']);
    }
1177030
function isCompassInstalled() {
  var deferred = q.defer(),
      cmd = 'compass';

  exec(cmd, function (err) {
    deferred.resolve(! err);
  });

  return deferred.promise;
}
251539
function () {

		if (packageInfo) return packageInfo;

		var fs = require('fs');
		packageInfo = JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8'));

		return packageInfo;

	}
229016
function () {
  var shrinkWrapPath = path.resolve(process.cwd(), 'npm-shrinkwrap.json');
  if (fs.existsSync(shrinkWrapPath)) {
    logger.logInfo('[npm] using npm-shrinkwrap.json instead of package.json');
    return shrinkWrapPath;
  }

  if (getNpmMajorVersion() >= 5) {
      var packageLockPath = path.resolve(process.cwd(), 'package-lock.json');
      if (fs.existsSync(packageLockPath)) {
          logger.logInfo('[npm] using package-lock.json instead of package.json');
          return packageLockPath;
      }
  }

  var packagePath = path.resolve(process.cwd(), 'package.json');
  return packagePath;
}
1136380
function(context, pkg, source) {
		source = source || "{}";
		var packageJSON = JSON.parse(source);
		utils.extend(pkg, packageJSON);
		context.packages.push(pkg);
		return pkg;
	}
408033
function isPackageAlreadyInstalled(packageInstallFolder) {
    try {
        const flagFilePath = path.join(packageInstallFolder, INSTALLED_FLAG_FILENAME);
        if (!fs.existsSync(flagFilePath)) {
            return false;
        }
        const fileContents = fs.readFileSync(flagFilePath).toString();
        return fileContents.trim() === process.version;
    }
    catch (e) {
        return false;
    }
}
1203846
function (packages) {
  var resolvedPackages = {};

  _.forOwn(packages, function (definition, packageName) {
    if (!definition) return;

    var git = definition.git;
    if (!git) return;

    var repo = resolvedPackages[git] = resolvedPackages[git] || {};

    // If no branch provided - checkout origin HEAD and
    // don't show 'detached HEAD' notification
    branch = definition.branch || '-q origin';
    // If no version provided - pull HEAD
    version = definition.version || 'HEAD';
    repo[branch] = repo[branch] || {};
    repo[branch][version] = repo[branch][version] || {};
    repo[branch][version][packageName] = definition.path || '';
  });

  return resolvedPackages;
}