<commit_before>const async = require('async');
const isPlainObject = require('lodash/isPlainObject');
const npa = require('npm-package-arg');
const { getJSON, JSONtoBuffer, fileToJSON } = require('../utils');
const registryUrl = require('registry-url')();

const logger = require('../logger');

const PKG_TEST_REGEXP = /-?umeboshi-?/;

module.exports = (files, metalsmith, done) => {

    const pgkFile = files['package.json'];

    if (!pgkFile) {
        logger.verbose('[pkg-resolve] File "package.json" not found. Skipping...');
        done();
        return;
    }

    try {

        const pkg = fileToJSON(files, 'package.json');
        const { devDependencies = {} } = pkg;

        const collection = Object.keys(devDependencies).filter((p) => PKG_TEST_REGEXP.test(p));

        if (collection.length === 0) {
            logger.verbose('[pkg-resolve] No Umeboshi peer dependencies found. Skip...');
            done();
            return;
        }

        logger.verbose('[pkg-resolve] collecting peer dependencies...');

        const newDeps = {};


        async.eachSeries(collection, (packageName, next) => {

            const { escapedName } = npa(packageName);
            const version = devDependencies[packageName];
            const pkgUrl = `${registryUrl}/${escapedName}/${version}`;

            getJSON(pkgUrl).then(
                ({ peerDependencies = {} }) => {
                    if (isPlainObject(peerDependencies) && Object.keys(peerDependencies).length > 0) {
                        logger.verbose(`[pkg-resolve] ${packageName}@${version} - found peerDependencies: ${JSON.stringify(peerDependencies)}`);
                        Object.assign(newDeps, peerDependencies);

                    }
                    next();
                },
                (errStatus) => {
                    logger.verbose(`[pkg-resolve] unable to load data for ${pkgUrl}. ${errStatus}`);
                    next();
                }
            );

        }, (err) => {

            if (err) {
                logger.error(`[pkg-resolve] Unable to process "package.json". ${err.toString()}`);
                done();
                return;
            }


            if (Object.keys(newDeps).length > 0) {
                logger.verbose([`[pkg-resolve] Added the following devDependencies: ${JSON.stringify(newDeps)}`]);<commit_msg>fix wrong npm registry api call<commit_after>const async = require('async');
const semver = require('semver');
const isPlainObject = require('lodash/isPlainObject');
const npa = require('npm-package-arg');
const { getJSON, JSONtoBuffer, fileToJSON } = require('../utils');
const registryUrl = require('registry-url')();

const logger = require('../logger');

const PKG_TEST_REGEXP = /-?umeboshi-?/;

module.exports = (files, metalsmith, done) => {

    const pgkFile = files['package.json'];

    if (!pgkFile) {
        logger.verbose('[pkg-resolve] File "package.json" not found. Skipping...');
        done();
        return;
    }

    try {

        const pkg = fileToJSON(files, 'package.json');
        const { devDependencies = {} } = pkg;

        const collection = Object.keys(devDependencies).filter((p) => PKG_TEST_REGEXP.test(p));

        if (collection.length === 0) {
            logger.verbose('[pkg-resolve] No Umeboshi peer dependencies found. Skip...');
            done();
            return;
        }

        logger.verbose('[pkg-resolve] collecting peer dependencies...');

        const newDeps = {};


        async.eachSeries(collection, (packageName, next) => {

            const { escapedName } = npa(packageName);
            const range = devDependencies[packageName];
            const pkgUrl = `${registryUrl}/${escapedName}/`.replace('//', '/');

            getJSON(pkgUrl).then(({ versions }) => {
                if (!semver.validRange(range)) {
                    return Promise.reject(`Invalid range ${range}`);
                }
                const version = semver.maxSatisfying(Object.keys(versions), range);
                if (!version) {
                    return Promise.reject(`Invalid range ${range}`);
                }
                return getJSON(pkgUrl + version);
            }).then(
                ({ peerDependencies = {} }) => {
                    if (isPlainObject(peerDependencies) && Object.keys(peerDependencies).length > 0) {
                        logger.verbose(`[pkg-resolve] ${packageName}@${version} - found peerDependencies: ${JSON.stringify(peerDependencies)}`);
                        Object.assign(newDeps, peerDependencies);

                    }
                    next();
                },
                (errStatus) => {
                    logger.verbose(`[pkg-resolve] unable to load data for ${pkgUrl}. ${errStatus}`);
                    next();
                }
            );

        }, (err) => {

            if (err) {
                logger.error(`[pkg-resolve] Unable to process "package.json". ${err.toString()}`);
                done();
                return;
            }


            if (Object.keys(newDeps).length > 0) {
                logger.verbose([`[pkg-resolve] Added the following devDependencies: ${JSON.stringify(newDeps)}`]);
{'fraction_non_alphanumeric': 0.15061396776669225, 'fraction_numerical': 0.0011511895625479663, 'mean_word_length': 1.940214326001128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4127013', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1351, 'n_words': 280}