import path from "path"; import hq from "alias-hq"; function escapeStringRegexp(string) { return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d"); } export default hq.get(({ rootUrl, baseUrl, paths }) => { return (importPath) => { if (!importPath.includes("@")) { return importPath; } const basePath = path.join(rootUrl, baseUrl); for (const [aliasedPath, replacements] of Object.entries(paths)) { const regexp = new RegExp( "(^|.*/)" + escapeStringRegexp(aliasedPath).replace("\\*", "(.*)") ); importPath = importPath.replace( regexp, path.join(basePath, replacements[0]).replace("*", "$2") ); } return importPath; }; });