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 url_1 = require("url");
|
17 | const url_resolver_1 = require("./url-resolver");
|
18 |
|
19 |
|
20 |
|
21 | class RedirectResolver extends url_resolver_1.UrlResolver {
|
22 | constructor(packageUrl, _redirectFrom, _redirectTo) {
|
23 | super();
|
24 | this.packageUrl = packageUrl;
|
25 | this._redirectFrom = _redirectFrom;
|
26 | this._redirectTo = _redirectTo;
|
27 | }
|
28 | resolve(firstUrl, secondUrl, _import) {
|
29 | const [baseUrl = this.packageUrl, unresolvedUrl] = this.getBaseAndUnresolved(firstUrl, secondUrl);
|
30 | const packageRelativeUrl = this.brandAsResolved(url_1.resolve(baseUrl, unresolvedUrl));
|
31 | if (packageRelativeUrl.startsWith(this._redirectFrom)) {
|
32 | return this.brandAsResolved(this._redirectTo +
|
33 | packageRelativeUrl.slice(this._redirectFrom.length));
|
34 | }
|
35 | if (packageRelativeUrl.startsWith(this._redirectTo)) {
|
36 | return packageRelativeUrl;
|
37 | }
|
38 | return undefined;
|
39 | }
|
40 | relative(fromOrTo, maybeTo, _kind) {
|
41 | let from, to;
|
42 | if (maybeTo === undefined) {
|
43 | from = this.packageUrl;
|
44 | to = fromOrTo;
|
45 | }
|
46 | else {
|
47 | from = fromOrTo;
|
48 | to = maybeTo;
|
49 | }
|
50 | if (!from.startsWith(this._redirectTo) && to.startsWith(this._redirectTo)) {
|
51 | to = this.brandAsResolved(this._redirectFrom + to.slice(this._redirectTo.length));
|
52 | }
|
53 | const result = this.simpleUrlRelative(from, to);
|
54 | if (maybeTo === undefined) {
|
55 | return this.brandAsPackageRelative(result);
|
56 | }
|
57 | else {
|
58 | return result;
|
59 | }
|
60 | }
|
61 | }
|
62 | exports.RedirectResolver = RedirectResolver;
|
63 |
|
\ | No newline at end of file |