<commit_before>"use strict";

const path    = require('path');
const _       = require('lodash');
const resolve = require('resolve');
const utl     = require('./utl');

function isRelativeModuleName(pString) {
    return pString.startsWith(".");
}

function resolveCJSModule(pModuleName, pBaseDir, pFileDir) {
    let lRetval = {
        resolved: pModuleName,
        coreModule: false,
        followable: false
    };
    if(resolve.isCore(pModuleName)){
        lRetval.coreModule = true;
    } else {
        try {
            lRetval.resolved = path.relative(
                pBaseDir,
                resolve.sync(pModuleName, {basedir: pFileDir})
            );
            lRetval.followable = !(lRetval.resolved.endsWith(".json"));
        } catch (e) {
            // intentionally left blank
        }
    }
    return lRetval;
}

function resolveAMDModule(pModuleName, pBaseDir, pFileDir) {
    // TODO resolution of non-relative AMD modules
    //      AMD de gakste!!
    // lookups:
    // - could be relative in the end (sorta implemented now)
    // - require.config kerfuffle
    // - maybe use mrjoelkemp/module-lookup-amd ?
    let lProbablePath = path.relative(
        pBaseDir,
        path.join(pFileDir, `${pModuleName}.js`)
    );
    return {
        resolved: utl.fileExists(lProbablePath) ? lProbablePath: pModuleName,
        coreModule: !!resolve.isCore(pModuleName),
        followable: utl.fileExists(lProbablePath)
    };
}

exports.resolveModuleToPath = function (pDependency, pBaseDir, pFileDir) {
    if(isRelativeModuleName(pDependency.moduleName)){
        return resolveCJSModule(pDependency.moduleName, pBaseDir, pFileDir);
    } else {
        if(_.includes(["cjs", "es6"], pDependency.moduleSystem)){
            return resolveCJSModule(pDependency.moduleName, pBaseDir, pFileDir);
        } else {
            return resolveAMDModule(pDependency.moduleName, pBaseDir, pFileDir);
        }
    }
};<commit_msg>updates todo comment in AMD resolver<commit_after>"use strict";

const path    = require('path');
const _       = require('lodash');
const resolve = require('resolve');
const utl     = require('./utl');

let isRelativeModuleName = pString => pString.startsWith(".");

function resolveCJSModule(pModuleName, pBaseDir, pFileDir) {
    let lRetval = {
        resolved: pModuleName,
        coreModule: false,
        followable: false
    };
    if(resolve.isCore(pModuleName)){
        lRetval.coreModule = true;
    } else {
        try {
            lRetval.resolved = path.relative(
                pBaseDir,
                resolve.sync(pModuleName, {basedir: pFileDir})
            );
            lRetval.followable = !(lRetval.resolved.endsWith(".json"));
        } catch (e) {
            // intentionally left blank
        }
    }
    return lRetval;
}

function resolveAMDModule(pModuleName, pBaseDir, pFileDir) {
    // TODO resolution of non-relative AMD modules
    // lookups:
    // - could be relative in the end (implemented)
    // - require.config kerfuffle (command line, html, file, ...)
    // - maybe use mrjoelkemp/module-lookup-amd ?
    let lProbablePath = path.relative(
        pBaseDir,
        path.join(pFileDir, `${pModuleName}.js`)
    );
    return {
        resolved: utl.fileExists(lProbablePath) ? lProbablePath: pModuleName,
        coreModule: !!resolve.isCore(pModuleName),
        followable: utl.fileExists(lProbablePath)
    };
}

exports.resolveModuleToPath = function (pDependency, pBaseDir, pFileDir) {
    if(isRelativeModuleName(pDependency.moduleName)){
        return resolveCJSModule(pDependency.moduleName, pBaseDir, pFileDir);
    } else {
        if(_.includes(["cjs", "es6"], pDependency.moduleSystem)){
            return resolveCJSModule(pDependency.moduleName, pBaseDir, pFileDir);
        } else {
            return resolveAMDModule(pDependency.moduleName, pBaseDir, pFileDir);
        }
    }
};
{'fraction_non_alphanumeric': 0.11793297518546943, 'fraction_numerical': 0.0005116398055768739, 'mean_word_length': 2.5970561177552898, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2433888', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1176, 'n_words': 234}