Sha256: 5253a1933bfac8bc5c0988eb1065a163bcc1d8d96b0b367826e985a7f8b5eeb4

Contents?: true

Size: 729 Bytes

Versions: 73

Compression:

Stored size: 729 Bytes

Contents

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;
  };
});

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.7 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.6 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.5 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.4 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.3 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.2 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.1 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.19.0 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.18.8 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.18.7 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.18.0 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.7 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.6 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.5 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.4 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.3 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.2 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.1 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.17.0 lib/scripts/map-aliased-path.mjs