Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (absSearchDir.is(_absRootDir)) {
return undefined;
}
// Look up in hierachy
alias = this._getAliasForExternal(
absSearchDir.dirname(),
requiredModule
);
// Rebase to current folder
if (
alias !== undefined &&
getAliasToType(alias) === AliasToType.LOCAL
) {
alias = new FilePath(`../${alias}`, {posix: true}).normalize()
.asPosix;
}
return alias;
}
return;
}
const {npmbundlerrc} = new Project(pkgJsonDir);
if (npmbundlerrc.config && npmbundlerrc.config.imports) {
npmbundlerrc.config.imports = normalizeImportsConfig(
npmbundlerrc.config.imports,
true
);
}
projects[pkgJson.name] = {
name: pkgJson.name,
dir: new FilePath(pkgJsonDir),
pkgJson,
npmbundlerrc,
};
_msg(1, pkgJsonDir);
} catch (err) {
// Swallow.
}
});
`/* redirected by alias field(s) in ${rootRelAbsDirPosixPath} */`,
`module.exports = require('${alias.to}');`
);
log.info(
'replace-browser-modules',
`Redirected file '${rootRelFilePosixPath}' to ` +
`'${alias.to}' as configured in ` +
`'${rootRelAbsDirPosixPath}'`
).linkToCode(2);
break;
}
case AliasToType.LOCAL: {
const absToFile = alias.absDir.join(
new FilePath(alias.to as string, {posix: true})
);
const fromRelToFile = absFromFile
.dirname()
.relative(absToFile);
rewriteFile(
absFromFile,
`/* redirected by alias field(s) in ${rootRelAbsDirPosixPath} */`,
`module.exports = require('./${fromRelToFile.asPosix}');`
);
log.info(
'replace-browser-modules',
`Redirected file '${rootRelFilePosixPath}' to ` +
`'./${fromRelToFile.asPosix}' as configured in ` +
`'${rootRelAbsDirPosixPath}'`
.map(baseDirRelPath => new FilePath(baseDirRelPath, {posix: true}));
.map(posixPath => new FilePath(posixPath, {posix: true}))
.forEach(file => {
});
if (extension !== undefined) {
const extname = path.extname(filePath);
if (extname == '') {
filePath = `${filePath}.${extension}`;
} else {
filePath = filePath.replace(
new RegExp(`\\${extname}$`),
`${extension}`
);
}
}
filePath = new FilePath(filePath).asPosix;
return `${pathModule}${webContextPath}/${filePath}`;
}
function getModuleName(prjRelfilePath: string, removePrefix: string): string {
const absFile = new FilePath(prjRelfilePath);
const pkgDir = new FilePath(babelUtil.getPackageDir(prjRelfilePath));
let moduleName: string = pkgDir.relative(absFile).asPosix;
if (moduleName.toLowerCase().endsWith('.js')) {
moduleName = moduleName.substring(0, moduleName.length - 3);
}
if (moduleName.startsWith(removePrefix)) {
moduleName = moduleName.substring(removePrefix.length);
}
const pkgJson = readJsonSync(pkgDir.join('package.json').asNative);
return `${pkgJson.name}@${pkgJson.version}/${moduleName}`;
}