@containerbase/base 14.47.0 → 14.50.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 +15 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +3 -0
- package/dist/tool-versions-schema.d.ts +4 -0
- package/dist/tool-versions-schema.js +10 -0
- package/dist/tool-versions-types.d.ts +10 -0
- package/dist/types.d.ts +4 -0
- package/dist/url.d.ts +31 -0
- package/dist/url.js +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -106,6 +106,21 @@ if (isContainerbase()) {
|
|
|
106
106
|
}
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
+
Containerbase replaces the urls it downloads from with the `CONTAINERBASE_CDN` and `URL_REPLACE_<n>_FROM` / `URL_REPLACE_<n>_TO` variables, see [custom registries](https://github.com/containerbase/base/blob/main/docs/custom-registries.md).
|
|
110
|
+
A reader can replace its urls the same way, so a mirror configured for containerbase works for it too:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { getUrlReplacements, replaceUrl } from '@containerbase/base';
|
|
114
|
+
|
|
115
|
+
const { replacements, invalid } = getUrlReplacements(); // reads `process.env`
|
|
116
|
+
// `invalid` lists the `URL_REPLACE_<n>_FROM` variables without a value or `_TO` counterpart
|
|
117
|
+
replaceUrl(
|
|
118
|
+
'https://containerbase.github.io/tool-versions/v1/node.json',
|
|
119
|
+
replacements,
|
|
120
|
+
process.env.CONTAINERBASE_CDN,
|
|
121
|
+
);
|
|
122
|
+
```
|
|
123
|
+
|
|
109
124
|
The schemas ignore unknown keys and accept any arch name, so additive changes of the format don't break a reader; readers ignore files of an arch they don't know.
|
|
110
125
|
|
|
111
126
|
## Contents
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { tools } from './data.ts';
|
|
2
2
|
import type { DistroCode } from './types.ts';
|
|
3
|
-
export type { DistroCode, InstallToolType, ToolMetadata, ToolType, } from './types.ts';
|
|
3
|
+
export type { Arch, DistroCode, InstallToolType, ToolMetadata, ToolType, } from './types.ts';
|
|
4
4
|
export type { FileIntegrity, FileReference, FormatIndex, ToolFile, ToolIndex, ToolVersion, ToolVersions, VersionFiles, VersionIntegrity, } from './tool-versions-types.ts';
|
|
5
5
|
export { containerbaseVersionFile, isCompatibleVersion, isContainerbase, packageVersion, toolVersionsPath, validateContainerbaseVersion, } from './containerbase.ts';
|
|
6
6
|
export { isToolVersionsFormat, toolVersionsFormat, toolVersionsFormatPath, } from './tool-versions-format.ts';
|
|
7
|
+
export type { UrlReplacement, UrlReplacements } from './url.ts';
|
|
8
|
+
export { getUrlReplacements, replaceUrl } from './url.ts';
|
|
7
9
|
export { tools };
|
|
8
10
|
/**
|
|
9
11
|
* The Ubuntu release the default containerbase image is built from, the
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { tools } from "./data.js";
|
|
2
2
|
export { containerbaseVersionFile, isCompatibleVersion, isContainerbase, packageVersion, toolVersionsPath, validateContainerbaseVersion, } from "./containerbase.js";
|
|
3
3
|
export { isToolVersionsFormat, toolVersionsFormat, toolVersionsFormatPath, } from "./tool-versions-format.js";
|
|
4
|
+
export { getUrlReplacements, replaceUrl } from "./url.js";
|
|
4
5
|
export { tools };
|
|
5
6
|
/**
|
|
6
7
|
* The Ubuntu release the default containerbase image is built from, the
|
package/dist/schema.d.ts
CHANGED
package/dist/schema.js
CHANGED
|
@@ -8,6 +8,9 @@ export const ToolType = z
|
|
|
8
8
|
export const DistroCode = z
|
|
9
9
|
.enum(['jammy', 'noble', 'resolute'])
|
|
10
10
|
.describe('an Ubuntu release supported by containerbase, by codename');
|
|
11
|
+
export const Arch = z
|
|
12
|
+
.enum(['amd64', 'arm64'])
|
|
13
|
+
.describe('a CPU architecture supported by containerbase');
|
|
11
14
|
/**
|
|
12
15
|
* Schema of a single entry of `tools.json`.
|
|
13
16
|
*
|
|
@@ -29,6 +29,8 @@ export declare const ToolVersion: z.ZodObject<{
|
|
|
29
29
|
distro: z.ZodExactOptional<z.ZodString>;
|
|
30
30
|
}, z.core.$strip>>>;
|
|
31
31
|
constraints: z.ZodExactOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
32
|
+
archs: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
+
distros: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
|
|
32
34
|
}, z.core.$strip>;
|
|
33
35
|
/** The content of a `<tool>.json` file. */
|
|
34
36
|
export declare const ToolVersions: z.ZodObject<{
|
|
@@ -58,6 +60,8 @@ export declare const ToolVersions: z.ZodObject<{
|
|
|
58
60
|
distro: z.ZodExactOptional<z.ZodString>;
|
|
59
61
|
}, z.core.$strip>>>;
|
|
60
62
|
constraints: z.ZodExactOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
63
|
+
archs: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
distros: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
|
|
61
65
|
}, z.core.$strip>>;
|
|
62
66
|
}, z.core.$strip>;
|
|
63
67
|
/** The content of a `<tool>/<version>.json` file: the files of one version. */
|
|
@@ -52,6 +52,16 @@ export const ToolVersion = z.object({
|
|
|
52
52
|
* present when the registry has one
|
|
53
53
|
*/
|
|
54
54
|
constraints: z.record(z.string().min(1), z.string().min(1)).exactOptional(),
|
|
55
|
+
/**
|
|
56
|
+
* sorted, the archs which have a file of this version, only in the
|
|
57
|
+
* `<tool>.json` files and only for versions with arch specific files
|
|
58
|
+
*/
|
|
59
|
+
archs: z.array(z.string().min(1)).min(1).exactOptional(),
|
|
60
|
+
/**
|
|
61
|
+
* sorted, the distro codenames which have a file of this version, only in
|
|
62
|
+
* the `<tool>.json` files and only for versions with distro specific files
|
|
63
|
+
*/
|
|
64
|
+
distros: z.array(z.string().min(1)).min(1).exactOptional(),
|
|
55
65
|
});
|
|
56
66
|
/**
|
|
57
67
|
* The url of the json schema of a published file, which identifies its format.
|
|
@@ -53,6 +53,16 @@ export interface ToolVersion {
|
|
|
53
53
|
* present when the registry has one.
|
|
54
54
|
*/
|
|
55
55
|
constraints?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* Sorted, the archs which have a file of this version, only in the
|
|
58
|
+
* `<tool>.json` files and only for versions with arch specific files.
|
|
59
|
+
*/
|
|
60
|
+
archs?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Sorted, the distro codenames which have a file of this version, only in
|
|
63
|
+
* the `<tool>.json` files and only for versions with distro specific files.
|
|
64
|
+
*/
|
|
65
|
+
distros?: string[];
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* The content of a `<tool>.json` file.
|
package/dist/types.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export type ToolType = 'gem' | 'npm' | 'pip' | 'dotnet';
|
|
|
10
10
|
* The Ubuntu releases containerbase supports, by codename.
|
|
11
11
|
*/
|
|
12
12
|
export type DistroCode = 'jammy' | 'noble' | 'resolute';
|
|
13
|
+
/**
|
|
14
|
+
* The CPU architectures containerbase supports.
|
|
15
|
+
*/
|
|
16
|
+
export type Arch = 'amd64' | 'arm64';
|
|
13
17
|
/**
|
|
14
18
|
* What containerbase knows about a supported tool.
|
|
15
19
|
*/
|
package/dist/url.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** A url replacement: the text to replace and its replacement. */
|
|
2
|
+
export type UrlReplacement = [from: string, to: string];
|
|
3
|
+
/** The url replacements read from the environment. */
|
|
4
|
+
export interface UrlReplacements {
|
|
5
|
+
/** The valid replacements, in numerical order. */
|
|
6
|
+
replacements: UrlReplacement[];
|
|
7
|
+
/**
|
|
8
|
+
* The `URL_REPLACE_<n>_FROM` variables which are ignored, because they or
|
|
9
|
+
* their `URL_REPLACE_<n>_TO` counterpart are empty or missing.
|
|
10
|
+
*/
|
|
11
|
+
invalid: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reads the url replacements from the `URL_REPLACE_<n>_FROM` and
|
|
15
|
+
* `URL_REPLACE_<n>_TO` variables, in numerical order of `<n>`.
|
|
16
|
+
*
|
|
17
|
+
* @param env the environment to read, `process.env` by default
|
|
18
|
+
*/
|
|
19
|
+
export declare function getUrlReplacements(env?: Record<string, string | undefined>): UrlReplacements;
|
|
20
|
+
/**
|
|
21
|
+
* Replaces a url the way containerbase does for its downloads: with a `cdn`,
|
|
22
|
+
* `https://` is replaced by it first, eg. `https://example.com/file` becomes
|
|
23
|
+
* `<cdn>/example.com/file`. Then every replacement is applied in order, each
|
|
24
|
+
* replacing the first occurrence of its `from` text.
|
|
25
|
+
*
|
|
26
|
+
* @param url the url to replace
|
|
27
|
+
* @param replacements the replacements, see `getUrlReplacements`
|
|
28
|
+
* @param cdn the cdn url, eg. from `CONTAINERBASE_CDN`, skipped when empty
|
|
29
|
+
* @returns the replaced url
|
|
30
|
+
*/
|
|
31
|
+
export declare function replaceUrl(url: string, replacements: readonly UrlReplacement[], cdn?: string): string;
|
package/dist/url.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const fromRe = /^URL_REPLACE_\d+_FROM$/;
|
|
2
|
+
const collator = new Intl.Collator('en', {
|
|
3
|
+
sensitivity: 'base',
|
|
4
|
+
numeric: true,
|
|
5
|
+
});
|
|
6
|
+
/**
|
|
7
|
+
* Reads the url replacements from the `URL_REPLACE_<n>_FROM` and
|
|
8
|
+
* `URL_REPLACE_<n>_TO` variables, in numerical order of `<n>`.
|
|
9
|
+
*
|
|
10
|
+
* @param env the environment to read, `process.env` by default
|
|
11
|
+
*/
|
|
12
|
+
export function getUrlReplacements(env = process.env) {
|
|
13
|
+
const result = { replacements: [], invalid: [] };
|
|
14
|
+
for (const from of Object.keys(env)
|
|
15
|
+
.filter((key) => fromRe.test(key))
|
|
16
|
+
.sort((a, b) => collator.compare(a, b))) {
|
|
17
|
+
const to = from.replace(/_FROM$/, '_TO');
|
|
18
|
+
const fromValue = env[from];
|
|
19
|
+
const toValue = env[to];
|
|
20
|
+
if (fromValue && toValue) {
|
|
21
|
+
result.replacements.push([fromValue, toValue]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
result.invalid.push(from);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Replaces a url the way containerbase does for its downloads: with a `cdn`,
|
|
31
|
+
* `https://` is replaced by it first, eg. `https://example.com/file` becomes
|
|
32
|
+
* `<cdn>/example.com/file`. Then every replacement is applied in order, each
|
|
33
|
+
* replacing the first occurrence of its `from` text.
|
|
34
|
+
*
|
|
35
|
+
* @param url the url to replace
|
|
36
|
+
* @param replacements the replacements, see `getUrlReplacements`
|
|
37
|
+
* @param cdn the cdn url, eg. from `CONTAINERBASE_CDN`, skipped when empty
|
|
38
|
+
* @returns the replaced url
|
|
39
|
+
*/
|
|
40
|
+
export function replaceUrl(url, replacements, cdn) {
|
|
41
|
+
let result = url;
|
|
42
|
+
if (cdn) {
|
|
43
|
+
result = result.replace(/^https:\//, cdn.replace(/\/$/, ''));
|
|
44
|
+
}
|
|
45
|
+
for (const [from, to] of replacements) {
|
|
46
|
+
result = result.replace(from, to);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|