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.16.0 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.15.0 lib/scripts/map-aliased-path.mjs
coveragebook_components-0.14.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.13.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.13.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.12.2 lib/scripts/map-aliased-path.js
coveragebook_components-0.12.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.12.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.11.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.10.1.beta.2 lib/scripts/map-aliased-path.js
coveragebook_components-0.10.1.beta.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.10.1.beta.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.10.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.9.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.9.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.9 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.8 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.7 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.6 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.5 lib/scripts/map-aliased-path.js