MCPcopy
hub / github.com/vercel/next.js / relativeIfPossible

Function relativeIfPossible

packages/next/src/compiled/source-map08/source-map.js:2738–2767  ·  view source on GitHub ↗
(rootURL, targetURL)

Source from the content-addressed store, hash-verified

2736exports.relative = relative;
2737
2738function relativeIfPossible(rootURL, targetURL) {
2739 const urlType = getURLType(rootURL);
2740 if (urlType !== getURLType(targetURL)) {
2741 return null;
2742 }
2743
2744 const base = buildSafeBase(rootURL + targetURL);
2745 const root = new URL(rootURL, base);
2746 const target = new URL(targetURL, base);
2747
2748 try {
2749 new URL("", target.toString());
2750 } catch (err) {
2751 // Bail if the URL doesn't support things being relative to it,
2752 // For example, data: and blob: URLs.
2753 return null;
2754 }
2755
2756 if (
2757 target.protocol !== root.protocol ||
2758 target.user !== root.user ||
2759 target.password !== root.password ||
2760 target.hostname !== root.hostname ||
2761 target.port !== root.port
2762 ) {
2763 return null;
2764 }
2765
2766 return computeRelativeURL(root, target);
2767}
2768
2769/**
2770 * Compute the URL of a source given the the source root, the source's

Callers 1

relativeFunction · 0.85

Calls 4

buildSafeBaseFunction · 0.85
computeRelativeURLFunction · 0.85
getURLTypeFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…