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({
function buildModuleResolverPreset() {
const expoReactNativePath = path.join(__dirname, 'react-native');
const expoReactPath = path.join(expoReactNativePath, 'node_modules/react');
return {
plugins: [
[
require('babel-plugin-module-resolver').default,
{
alias: {
react: expoReactPath,
'react-native': expoReactNativePath,
},
},
],
],
};
}
const buildAliasPreset = (reactNativePath, reactPath) => ({
plugins: [
[
require('babel-plugin-module-resolver').default,
{
alias: Object.assign(
{},
{
'react-native': path.resolve(
`${reactNativePath || './node_modules/react-native'}`
),
react: path.resolve(`${reactPath || './node_modules/react'}`),
},
require('babel-preset-exponent').plugins[0][1].alias
),
cwd: path.resolve(__dirname, '..'),
},
],
],
});
[
require('@babel/plugin-transform-runtime').default,
{
helpers: false,
regenerator: true,
corejs: false,
},
],
[
require('@babel/plugin-transform-regenerator').default,
{
async: false,
},
],
[
require('babel-plugin-module-resolver').default,
{
root: ['./app/javascript/'],
},
],
].filter(Boolean),
}
}
pre(file) {
this.types = types;
this.moduleResolverVisited = new Set();
this.normalizedOpts = normalizeOptions(file.opts.filename, this.opts);
const { luaRoot } = this.opts;
if (luaRoot == null) throw new Error('Required option `luaRoot` is not defined');
const optionalResolvePath = this.opts.resolvePath;
this.normalizedOpts.resolvePath = createResolver(luaRoot, optionalResolvePath);
},