
const path = require('path');
const fs = require('fs');

const pathMyRootNodeModules = path.resolve(__dirname, '../node_modules');
const pathWorkspaceNodeModules = path.resolve(process.cwd(), './node_modules');

exports.getLoaderAbsolutePath = function getLoaderAbsolutePath(loaderName) {
    let loaderPath = path.join(pathMyRootNodeModules, loaderName);
    if (fs.existsSync(loaderPath)) {
        return loaderPath;
    }

    loaderPath = path.join(pathWorkspaceNodeModules, loaderName);
    if (fs.existsSync(loaderPath)) {
        return loaderPath;
    }

    return loaderName;
};