Crawl all saved JSON metadata or online to check we have all packages
        if delete - generate a diff of unowned files
551883
async def metadata_verify(config, args) -> int:
    
    all_package_files = []  # type: List[Path]
    loop = asyncio.get_event_loop()
    mirror_base = config.get("mirror", "directory")
    json_base = Path(mirror_base) / "web" / "json"
    workers = args.workers or config.getint("mirror", "workers")
    executor = concurrent.futures.ThreadPoolExecutor(max_workers=workers)

    logger.info(f"Starting verify for {mirror_base} with {workers} workers")
    try:
        json_files = await loop.run_in_executor(executor, os.listdir, json_base)
    except FileExistsError as fee:
        logger.error(f"Metadata base dir {json_base} does not exist: {fee}")
        return 2
    if not json_files:
        logger.error("No JSON metadata files found. Can not verify")
        return 3

    logger.debug(f"Found {len(json_files)} objects in {json_base}")
    logger.debug(f"Using a {workers} thread ThreadPoolExecutor")
    await async_verify(
        config, all_package_files, mirror_base, json_files, args, executor
    )

    if not args.delete:
        return 0

    return await delete_files(mirror_base, executor, all_package_files, args.dry_run)
989027
def check_exists_repositories(repo):
    
    pkg_list = "PACKAGES.TXT"
    if repo == "sbo":
        pkg_list = "SLACKBUILDS.TXT"
    if check_for_local_repos(repo) is True:
        pkg_list = "PACKAGES.TXT"
        return ""
    if not os.path.isfile("{0}{1}{2}".format(
            _meta_.lib_path, repo, "_repo/{0}".format(pkg_list))):
        return repo
    return ""
879021
function pkginfo() {
	var root, file;
	root = resolve();
	file = path.join( root, 'package.json' );
	return readJSON.sync( file );
}
520654
def search_index_file():
    """"""
    from metapack import Downloader
    from os import environ

    return environ.get('METAPACK_SEARCH_INDEX',
                       Downloader.get_instance().cache.getsyspath('index.json'))
773096
def _get_changes(rsync_out):
    '''
    
    '''
    copied = list()
    deleted = list()

    for line in rsync_out.split("\n\n")[0].split("\n")[1:]:
        if line.startswith("deleting "):
            deleted.append(line.split(" ", 1)[-1])
        else:
            copied.append(line)

    ret = {
        'copied': os.linesep.join(sorted(copied)) or "N/A",
        'deleted': os.linesep.join(sorted(deleted)) or "N/A",
    }

    # Return whether anything really changed
    ret['changed'] = not ((ret['copied'] == 'N/A') and (ret['deleted'] == 'N/A'))

    return ret
133047
function (done) {
      var p = clone(pkg);
      delete p.devDependencies;
      var content = JSON.stringify(p, null, 2);
      write_if_not_exists('package.json', content, done);
    }
73619
def list_of_installed(self, repo, name):
        
        all_installed_names = []
        all_installed_packages = find_package("", self.meta.pkg_path)
        for inst in all_installed_packages:
            if repo == "sbo" and inst.endswith("_SBo"):
                name = split_package(inst)[0]
                all_installed_names.append(name)
            else:
                if name:
                    all_installed_names.append(split_package(inst)[0])
                else:
                    all_installed_names.append(inst)
        return all_installed_names
125471
def get_library_meta(self):
        '''
        
        '''
        parent_dir = os.path.dirname(self.library_dir)
        if self.test_file_exists(os.path.join(self.library_dir,'meta'),['libraries.json']):
            with open(os.path.join(self.library_dir,'meta','libraries.json'),'r') as f:
                meta_data = json.load(f)
                if isinstance(meta_data,list):
                    for lib in meta_data:
                        if lib['key'] == self.library_key:
                            return lib
                elif 'key' in meta_data and meta_data['key'] == self.library_key:
                    return meta_data
        if not self.test_dir_exists(os.path.join(self.library_dir,'meta')) \
            and self.test_file_exists(os.path.join(parent_dir,'meta'),['libraries.json']):
            with open(os.path.join(parent_dir,'meta','libraries.json'),'r') as f:
                libraries_json = json.load(f)
                if isinstance(libraries_json,list):
                    for lib in libraries_json:
                        if lib['key'] == self.library_key:
                            return lib
        return None
354363
def run_json(self):
        
        checks = {}
        for file in self.files:
            try:
                results = self._check(file)
            except Error as e:
                checks[file] = {
                    "error": e.msg
                }
            else:
                checks[file] = {
                    "score": results.score,
                    "comments": results.comment_ratio >= results.COMMENT_MIN,
                    "diff": "<pre>{}</pre>".format("\n".join(self.html_diff(results.original, results.styled))),
                }

        json.dump(checks, sys.stdout, indent=4)
        print()
1003796
function getNotLoadPackedFiles(page, packedFiles, loadPackeFiles) {
    var existedMap = {};
    loadPackeFiles.forEach(function(item) {
        existedMap[item.id] = true;
    });

    var notExisteds = [];
    packedFiles.forEach(function(item) {
        var pkg = item.pkg;
        var host = item.host;
        if (!existedMap[pkg.id] && (host === page || host == null)) {
            notExisteds.push(pkg);
        }
    });

    return notExisteds;
}
609069
function diff(node) {
		var oldBundle = (cachedData.loader.bundle || []).slice();

		return getDependencies(node.load).then(function(result){
			var newBundle = (cachedData.loader.bundle || []).slice();

			// If the deps are the same we can return the existing graph.
			if(same(node.deps, result.deps) &&
			   same(oldBundle, newBundle)) {
				clean(node, result.source);

				if(result.virtualModules.length) {
					var promises = result.virtualModules.map(function(l){
						var node = cachedData.graph[l.name];
						node.load.source = l.source;
						node.load.metadata.useSource = true;
						return diff(node);
					});

					return Promise.all(promises).then(function(results){
						result.same = results.every(function(res){
							return res.same;
						});
						return result;
					});
				}

				result.same = true;
			}
			return result;
		});

	}
785633
function optimizePackageConfig(json) {
  if (json.systemjs)
    json = json.systemjs;

  // remove non SystemJS package config properties
  var loaderConfigProperties = ['baseDir', 'defaultExtension', 'format', 'meta', 'map', 'main'];
  for (var p in json)
    if (loaderConfigProperties.indexOf(p) == -1)
      delete json[p];

  if (json.map && !json.map['@env']) {
    Object.keys(json.map).forEach(function(target) {
      var mapped = json.map[target];

      if (typeof mapped == 'string' && mapped.substr(0, 6) == '@node/')
        delete json.map[target];

      if (typeof mapped == 'object') {
        Object.keys(mapped).forEach(function(condition) {
          if (condition == 'node')
            delete mapped[condition];
        });
        if (!hasProperties(mapped))
          delete json.map[target];
      }
    });

    if (!hasProperties(json.map))
      delete json.map;
  }

  return json;
}
1095510
function findPackages(path) {
  return new Promise(function (resolve, reject) {
    (0, _glob.glob)(path, function (err, res) {
      if (err) {
        reject(err);
      }
      resolve(res.filter(function (file) {
        return file.endsWith('.json');
      }));
    });
  });
}
51330
def find_usedby(self, depslock_file_path, property_validate=True):
        
        if depslock_file_path is None:
            self._raw = [self._params]
            self._raw[0]['repo'] = None
            self._raw[0]['server'] = None
        else:
            self._raw = [x for x in self._downloader.common_parser.iter_packages_params(depslock_file_path)]
        self.packages = self._downloader.get_usedby_packages({'raw': self._raw},
                                                             property_validate=property_validate)
951122
function getUpdatedEmittedFiles(emittedFiles, webpackRuntimeFiles) {
    let fallbackFiles = [];
    let hotHash;
    if (emittedFiles.some(x => x.endsWith('.hot-update.json'))) {
        let result = emittedFiles.slice();
        const hotUpdateScripts = emittedFiles.filter(x => x.endsWith('.hot-update.js'));
        hotUpdateScripts.forEach(hotUpdateScript => {
            const { name, hash } = parseHotUpdateChunkName(hotUpdateScript);
            hotHash = hash;
            // remove bundle/vendor.js files if there's a bundle.XXX.hot-update.js or vendor.XXX.hot-update.js
            result = result.filter(file => file !== `${name}.js`);
            if (webpackRuntimeFiles && webpackRuntimeFiles.length) {
                // remove files containing only the Webpack runtime (e.g. runtime.js)
                result = result.filter(file => webpackRuntimeFiles.indexOf(file) === -1);
            }
        });
        //if applying of hot update fails, we must fallback to the full files
        fallbackFiles = emittedFiles.filter(file => result.indexOf(file) === -1);
        return { emittedFiles: result, fallbackFiles, hash: hotHash };
    }
    else {
        return { emittedFiles, fallbackFiles };
    }
}
744028
def compare(self, snapshot):
		
		builds = snapshot.builds()

		diff_snapshot = DistributionSnapshot(self.distribution(), self.go_version)

		for package in list(set(self._builds.keys()) - set(builds.keys())):
			diff_snapshot.setRpms(package, self._builds[package]["build"], self._builds[package]["build_ts"], self._builds[package]["rpms"])

		for package in list(set(self._builds.keys()) & set(builds.keys())):
			if self._builds[package]["build"] != builds[package]["build"]:
				diff_snapshot.setRpms(package, self._builds[package]["build"], self._builds[package]["build_ts"], self._builds[package]["rpms"])

		# Assuming no package get ever removed (even if retired)
		return diff_snapshot
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')
      }
    })
}