(rootURL, targetURL)
| 2736 | exports.relative = relative; |
| 2737 | |
| 2738 | function 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 |
no test coverage detected
searching dependent graphs…