Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolveTarget(file, path, ensureTargetIsProcessed) {
var name = void 0;
if (opts.globals != null && (name = opts.globals[path]) != null) {
return name;
} else {
var resolvedPath = resolve(path, opts);
if (resolvedPath === emptyModule) {
return false;
}
file.metadata.required.push(resolvedPath);
// Check if the path is under sourceRoot
var root = file.opts.sourceRoot;
if (!rootRegex.test(resolvedPath)) {
throw new Error("Cannot find module '" + path + "' from '" + dirname(file.opts.filename) + "' under '" + root + "'");
}
if (/\.coffee$/.test(resolvedPath)) {
// If it's a coffee script file, look for global variable assignments.
return findDeclarationInCoffeeFile(resolvedPath, ensureTargetIsProcessed);
} else {
path: string,
currentPath: string,
defaultExtensions: Array = ['js', 'jsx', 'json']
): Module {
const aliasedPath = this.getAliasedDependencyPath(path, currentPath);
const shimmedPath = coreLibraries[aliasedPath] || aliasedPath;
const pathId = path + currentPath;
const cachedPath = this.cachedPaths[pathId];
try {
let resolvedPath;
if (cachedPath) {
resolvedPath = cachedPath;
} else {
resolvedPath = resolve.sync(shimmedPath, {
filename: currentPath,
extensions: defaultExtensions.map(ext => '.' + ext),
isFile: this.isFile,
readFileSync: this.readFileSync,
});
this.cachedPaths[pathId] = resolvedPath;
}
if (NODE_LIBS.includes(shimmedPath)) {
return {
path: pathUtils.join('/node_modules', resolvedPath),
code: `// empty`,
requires: [],
};
}
Module._resolveFilename = function devtoolResolveFilename (filename, parent) {
try {
// Try to use a browser resolver first...
return browserResolve.sync(filename, {
filename: parent.filename,
paths: parent.paths
});
} catch (e) {
// Otherwise fall back to native; e.g. for Electron requires
return nativeResolve.call(Module, filename, parent);
}
};
}
new Promise((resolve, reject) => {
bresolve(newDep, bresolveOpts, (e, file) => {
if (e) {
reject(e);
} else {
row.deps[oldDep] = file; // eslint-disable-line no-param-reassign
resolve();
}
});
});
return new Promise((r, reject) => {
resolve(
usedPath,
{
filename: path,
extensions: ['.scss', '.css', '.sass'],
moduleDirectory: ['node_modules'],
isFile: async (pp, cb) => {
const exists = !!(await getExistingPath(fs, pp));
if (!exists) {
const err = new Error('Could not find ' + pp);
// $FlowIssue
err.code = 'ENOENT';
return cb(err);
}
return new Promise((r, reject) => {
resolve(
usedPath,
{
filename: path,
extensions: ['.scss', '.css', '.sass'],
moduleDirectory: ['node_modules'],
isFile: async (pp, cb) => {
const exists = !!(await getExistingPath(fs, pp));
if (!exists) {
const err = new Error('Could not find ' + pp);
// $FlowIssue
err.code = 'ENOENT';
return cb(err);
}
return new Promise((r, reject) => {
resolve(
usedPath,
{
filename: path,
extensions: ['.scss', '.css', '.sass'],
moduleDirectory: ['node_modules'],
isFile: async (pp, cb) => {
const exists = !!(await getExistingPath(fs, pp));
if (!exists) {
const err = new Error('Could not find ' + pp);
// $FlowIssue
err.code = 'ENOENT';
return cb(err);
}
modules.forEach(function(mod, i) {
if (typeof mod === 'string') {
mod = {
require: mod,
expose: mod
};
}
var id = bresolve.sync(mod.require, rOpts);
shortIDLabels[id] = mod.expose;
modules[i] = id;
b.require(id, {entry: true});
});
});
}
const preset =
availablePresets[requirePath] ||
availablePresets[requirePath.replace('babel-preset-', '')] ||
availablePresets[requirePath.replace('@babel/preset-', '')];
if (preset && requirePath !== 'react') {
return preset;
}
const dirName = dirname(path);
cachedPaths[dirName] = cachedPaths[dirName] || {};
const resolvedPath =
cachedPaths[dirName][requirePath] ||
resolve.sync(requirePath, {
filename: path,
extensions: ['.js', '.json'],
moduleDirectory: ['node_modules'],
});
cachedPaths[dirName][requirePath] = resolvedPath;
const resolvedCode = fs.readFileSync(resolvedPath).toString();
const id = hashsum(resolvedCode + resolvedPath);
if (cache[id]) {
return cache[id].exports;
}
cache[id] = {};
requires.map(async foundR => {
if (foundR.type === 'direct') {
if (foundR.path === 'babel-plugin-macros') {
return;
}
try {
resolve.sync(foundR.path, {
filename: r.path,
extensions: ['.js', '.json'],
moduleDirectory: ['node_modules'],
});
} catch (e) {
await downloadFromError(e);
}
}
})
);