1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const index_1 = require("../index");
|
17 | const fs_url_resolver_1 = require("./fs-url-resolver");
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | class IndirectUrlResolver extends fs_url_resolver_1.FsUrlResolver {
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | constructor(rootPath, packagePath, indirectionMap, protocol = 'https') {
|
40 | super(packagePath);
|
41 | this.protocol = protocol;
|
42 | const rootResolver = new fs_url_resolver_1.FsUrlResolver(rootPath);
|
43 | const urlspaceToFilesystem = new Map();
|
44 | const filesystemToUrlspace = new Map();
|
45 | for (const [u, fsPath] of indirectionMap) {
|
46 | const url = u;
|
47 | const fsUrl = rootResolver.resolve(this.brandAsPackageRelative(fsPath));
|
48 | if (fsUrl === undefined) {
|
49 | throw new Error(`Invalid fs path in indirection map: ${fsPath}`);
|
50 | }
|
51 | urlspaceToFilesystem.set(url, fsUrl);
|
52 | filesystemToUrlspace.set(fsUrl, url);
|
53 | }
|
54 | this.runtimeUrlToResolvedUrl = urlspaceToFilesystem;
|
55 | this.resolvedUrlToRuntimeUrl = filesystemToUrlspace;
|
56 | }
|
57 | resolve(firstHref, secondHref) {
|
58 | const [baseUrl, unresolvedHref] = this.getBaseAndUnresolved(firstHref, secondHref);
|
59 |
|
60 | if (baseUrl === undefined) {
|
61 | return super.resolve(this.brandAsPackageRelative(unresolvedHref));
|
62 | }
|
63 | const url = this.brandAsFileRelative(unresolvedHref);
|
64 | const runtimeBaseUrl = this.resolvedUrlToRuntimeUrl.get(baseUrl);
|
65 | if (runtimeBaseUrl === undefined) {
|
66 | return super.resolve(baseUrl, url);
|
67 | }
|
68 | const runtimeUrl = this.runtimeResolve(url, runtimeBaseUrl);
|
69 | const resolvedUrl = this.runtimeUrlToResolvedUrl.get(runtimeUrl);
|
70 | if (resolvedUrl === undefined) {
|
71 | return super.resolve(baseUrl, url);
|
72 | }
|
73 | return resolvedUrl;
|
74 | }
|
75 | runtimeResolve(url, runtimeBaseUrl) {
|
76 | const resolved = this.simpleUrlResolve(this.brandAsResolved(runtimeBaseUrl), url, this.protocol);
|
77 | return brandAsRuntimeUrl(resolved);
|
78 | }
|
79 | relative(fromOrTo, maybeTo, _kind) {
|
80 | const [from, to] = (maybeTo !== undefined) ? [fromOrTo, maybeTo] :
|
81 | [this.packageUrl, fromOrTo];
|
82 | return this.relativeImpl(from, to);
|
83 | }
|
84 | relativeImpl(from, to) {
|
85 | const fromWeb = this.resolvedUrlToRuntimeUrl.get(from);
|
86 | const toWeb = this.resolvedUrlToRuntimeUrl.get(to);
|
87 | if (fromWeb === undefined || toWeb === undefined) {
|
88 | return this.simpleUrlRelative(from, to);
|
89 | }
|
90 | return this.simpleUrlRelative(this.brandAsResolved(fromWeb), this.brandAsResolved(toWeb));
|
91 | }
|
92 | }
|
93 | exports.IndirectUrlResolver = IndirectUrlResolver;
|
94 | function brandAsRuntimeUrl(resolved) {
|
95 | const str = resolved;
|
96 | return str;
|
97 | }
|
98 |
|
\ | No newline at end of file |