@containerbase/base 14.62.0 → 14.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/url.d.ts +27 -0
- package/dist/url.js +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,20 @@ replaceUrl(
|
|
|
121
121
|
);
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
`replaceUrl` replaces the first occurrence of a `from` anywhere in the url; the next major only matches at the start of the url, see [#8160](https://github.com/containerbase/base/issues/8160).
|
|
125
|
+
`replaceUrlPrefix(url, rules)` already does: the rules apply in order, each to the result of the previous ones, and only when the url starts with its `from`.
|
|
126
|
+
It has no cdn step and returns the replaced url with the rules that matched, other fields of the rules are kept.
|
|
127
|
+
End `from` and `to` with a `/`, like `https://example.com/`, so a rule only matches that host: `https://example.com` also matches `https://example.com.test/`.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { replaceUrlPrefix } from '@containerbase/base';
|
|
131
|
+
|
|
132
|
+
const { url, applied } = replaceUrlPrefix('https://registry.npmjs.org/foo', [
|
|
133
|
+
{ from: 'https://registry.npmjs.org/', to: 'https://npm.example.test/' },
|
|
134
|
+
]);
|
|
135
|
+
// url: 'https://npm.example.test/foo', applied: [the rule]
|
|
136
|
+
```
|
|
137
|
+
|
|
124
138
|
A tool's data may list `minCb` ranges, the oldest containerbase version which can install a version and every version above it.
|
|
125
139
|
`filterByMinCb(data, cbVersion)` returns the `versions` the given containerbase version can install, in the order of the data, and the `cb` values of the unmet ranges as `needed`.
|
|
126
140
|
A `cbVersion` which isn't a release, like `0.0.0-PLACEHOLDER` (see `isReleaseVersion(version)`), skips the filter:
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export { configure, getLogger, isConfigured } from './logger.ts';
|
|
|
8
8
|
export { filterByMinCb, minCbByVersion } from './min-cb.ts';
|
|
9
9
|
export { isReleaseVersion } from './release-version.ts';
|
|
10
10
|
export { isToolVersionsFormat, toolVersionsFormat, toolVersionsFormatPath, } from './tool-versions-format.ts';
|
|
11
|
-
export type { UrlReplacement, UrlReplacements } from './url.ts';
|
|
12
|
-
export { getUrlReplacements, replaceUrl } from './url.ts';
|
|
11
|
+
export type { UrlPrefixResult, UrlPrefixRule, UrlReplacement, UrlReplacements, } from './url.ts';
|
|
12
|
+
export { getUrlReplacements, replaceUrl, replaceUrlPrefix } from './url.ts';
|
|
13
13
|
export { tools };
|
|
14
14
|
/**
|
|
15
15
|
* The Ubuntu release the default containerbase image is built from, the
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { configure, getLogger, isConfigured } from "./logger.js";
|
|
|
4
4
|
export { filterByMinCb, minCbByVersion } from "./min-cb.js";
|
|
5
5
|
export { isReleaseVersion } from "./release-version.js";
|
|
6
6
|
export { isToolVersionsFormat, toolVersionsFormat, toolVersionsFormatPath, } from "./tool-versions-format.js";
|
|
7
|
-
export { getUrlReplacements, replaceUrl } from "./url.js";
|
|
7
|
+
export { getUrlReplacements, replaceUrl, replaceUrlPrefix } from "./url.js";
|
|
8
8
|
export { tools };
|
|
9
9
|
/**
|
|
10
10
|
* The Ubuntu release the default containerbase image is built from, the
|
package/dist/url.d.ts
CHANGED
|
@@ -29,3 +29,30 @@ export declare function getUrlReplacements(env?: Record<string, string | undefin
|
|
|
29
29
|
* @returns the replaced url
|
|
30
30
|
*/
|
|
31
31
|
export declare function replaceUrl(url: string, replacements: readonly UrlReplacement[], cdn?: string): string;
|
|
32
|
+
/** A url prefix replacement rule, other fields are kept as they are. */
|
|
33
|
+
export interface UrlPrefixRule {
|
|
34
|
+
/** The url prefix to replace. */
|
|
35
|
+
from: string;
|
|
36
|
+
/** Its replacement. */
|
|
37
|
+
to: string;
|
|
38
|
+
}
|
|
39
|
+
/** The result of `replaceUrlPrefix`. */
|
|
40
|
+
export interface UrlPrefixResult<T extends UrlPrefixRule> {
|
|
41
|
+
/** The replaced url. */
|
|
42
|
+
url: string;
|
|
43
|
+
/** The rules which matched, in order. */
|
|
44
|
+
applied: T[];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Replaces url prefixes: the rules are applied in order, each one to the
|
|
48
|
+
* result of the previous ones, and a rule only applies when the url starts
|
|
49
|
+
* with its `from`, which is then replaced by its `to`. Unlike `replaceUrl`,
|
|
50
|
+
* a `from` elsewhere in the url never matches, and there is no cdn. End `from`
|
|
51
|
+
* and `to` with a `/`, like `https://example.com/`, so a rule only matches that
|
|
52
|
+
* host: `https://example.com` also matches `https://example.com.test/`.
|
|
53
|
+
*
|
|
54
|
+
* @param url the url to replace
|
|
55
|
+
* @param rules the rules, in order
|
|
56
|
+
* @returns the replaced url and the rules which matched
|
|
57
|
+
*/
|
|
58
|
+
export declare function replaceUrlPrefix<T extends UrlPrefixRule>(url: string, rules: readonly T[]): UrlPrefixResult<T>;
|
package/dist/url.js
CHANGED
|
@@ -37,6 +37,7 @@ export function getUrlReplacements(env = process.env) {
|
|
|
37
37
|
* @param cdn the cdn url, eg. from `CONTAINERBASE_CDN`, skipped when empty
|
|
38
38
|
* @returns the replaced url
|
|
39
39
|
*/
|
|
40
|
+
// TODO: match only at the start of the url in the next major, like `replaceUrlPrefix` (#8160)
|
|
40
41
|
export function replaceUrl(url, replacements, cdn) {
|
|
41
42
|
let result = url;
|
|
42
43
|
if (cdn) {
|
|
@@ -47,3 +48,26 @@ export function replaceUrl(url, replacements, cdn) {
|
|
|
47
48
|
}
|
|
48
49
|
return result;
|
|
49
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Replaces url prefixes: the rules are applied in order, each one to the
|
|
53
|
+
* result of the previous ones, and a rule only applies when the url starts
|
|
54
|
+
* with its `from`, which is then replaced by its `to`. Unlike `replaceUrl`,
|
|
55
|
+
* a `from` elsewhere in the url never matches, and there is no cdn. End `from`
|
|
56
|
+
* and `to` with a `/`, like `https://example.com/`, so a rule only matches that
|
|
57
|
+
* host: `https://example.com` also matches `https://example.com.test/`.
|
|
58
|
+
*
|
|
59
|
+
* @param url the url to replace
|
|
60
|
+
* @param rules the rules, in order
|
|
61
|
+
* @returns the replaced url and the rules which matched
|
|
62
|
+
*/
|
|
63
|
+
export function replaceUrlPrefix(url, rules) {
|
|
64
|
+
let result = url;
|
|
65
|
+
const applied = [];
|
|
66
|
+
for (const rule of rules) {
|
|
67
|
+
if (result.startsWith(rule.from)) {
|
|
68
|
+
result = rule.to + result.slice(rule.from.length);
|
|
69
|
+
applied.push(rule);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { url: result, applied };
|
|
73
|
+
}
|