Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Search finished
if (absSearchDir.is(absSearchTopDir)) {
return undefined;
}
// Look up in hierachy
alias = this._getAliasForLocal(
absSearchTopDir,
absSearchDir.dirname(),
absSearchDir.basename().join(searchRelModuleName)
);
// Rebase to current folder
if (
alias !== undefined &&
getAliasToType(alias) === AliasToType.LOCAL
) {
alias = new FilePath(`../${alias}`, {posix: true}).normalize()
.asPosix;
}
return alias;
}
);
// Then, if not found, recursively from target module up
if (alias === undefined) {
const moduleDir = absFileDir.join(requiredModule.dirname());
const moduleBasename = requiredModule.basename();
alias = this._getAliasForLocal(
_absRootDir,
moduleDir,
moduleBasename
);
if (
alias !== undefined &&
getAliasToType(alias) === AliasToType.LOCAL
) {
alias = absFileDir
.relative(moduleDir)
.join(new FilePath(alias, {posix: true})).asPosix;
if (!alias.startsWith('.')) {
alias = `./${alias}`;
}
}
}
} else {
alias = this._getAliasForExternal(absFileDir, requiredModule);
}
return alias === undefined ? requiredModuleName : alias;
}
// Search finished
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;
}
if (unrolledAliases.length > 1) {
throw new Error(
'Unrolled aliases map has unresolved collisions'
);
}
const alias = unrolledAliases[0];
const absFromFile = new FilePath(absFromPath);
const rootRelAbsDirPosixPath = absRootDir.relative(alias.absDir)
.asPosix;
const rootRelFilePosixPath = absRootDir.relative(absFromFile)
.asPosix;
switch (getAliasToType(alias.to)) {
case AliasToType.IGNORE: {
rewriteFile(
absFromFile,
`/* ignored by alias field(s) configured in ${rootRelAbsDirPosixPath} */`
);
log.info(
'replace-browser-modules',
`Emptied file '${rootRelFilePosixPath}' as ` +
`configured in '${rootRelAbsDirPosixPath}'`
).linkToCode(1);
break;
}
case AliasToType.EXTERNAL: {
rewriteFile(