Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const resolveComponentPath = (sourcePath, currentFile, opts) => {
const defaultPath = resolvePath(sourcePath, currentFile, opts)
try {
const resolved = resolve(dirname(currentFile), defaultPath)
if (statSync(resolved).isDirectory()) {
const ext = extname(sourcePath) || '.js'
const index = join(resolved, 'index' + ext)
const component = join(resolved, basename(resolved) + ext)
if (!existsSync(index) && existsSync(component)) {
return component
}
}
} catch (err) {
// ignore errors, simply return default resolved path.
}
// e.g. in .eslintrc file
// "import/resolver": {
// "babel-module": {
// "root": ["./src"],
// "extensions": [".js", ".jsx"]
// }
// }
cwd: options.cwd || projectRootDir,
root: options.root || [],
alias: options.alias || {},
extensions: options.extensions || defaultExtensions,
},
);
const finalSource = stripWebpack(source, pluginOptions.alias);
const src = resolvePath(finalSource, file, pluginOptions);
const extensions = options.extensions || pluginOptions.extensions;
return {
found: true,
path: resolve.sync(src || source, {
...options,
extensions,
basedir: path.dirname(file),
}),
};
} catch (e) {
return { found: false };
}
};
function resolvePath(sourcePath, currentFile, opts) {
if (sourcePath === 'markdown') {
const base = currentFile.substring(__dirname.length).slice(0, -3);
return `${__dirname}/docs/src/${base}/`;
}
return bpmr.resolvePath(sourcePath, currentFile, opts);
}
resolvePath(sourcePath, currentFile, opts) {
let name = ModuleResolver.resolvePath(sourcePath, currentFile, opts);
if (name) {
let full = path.join(path.dirname(currentFile), name);
let name2 = path.relative(config.projectRoot, full);
return name2.indexOf('..' + path.sep) > -1 ? name.replace('../', '') : name;
}
},
'alias': Options.merge({