Sha256: 5253a1933bfac8bc5c0988eb1065a163bcc1d8d96b0b367826e985a7f8b5eeb4

Contents?: true

Size: 729 Bytes

Versions: 74

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

74 entries across 74 versions & 1 rubygems

Version Path
coveragebook_components-0.8.5 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.4 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.3 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.2 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.0 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.0.beta.3 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.0.beta.2 lib/scripts/map-aliased-path.js
coveragebook_components-0.8.0.beta.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.10 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.9 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.8 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.7 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.6 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.5 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.4 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.3 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.2 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.1 lib/scripts/map-aliased-path.js
coveragebook_components-0.7.0 lib/scripts/map-aliased-path.js