@g3nomaly/core 0.3.0 → 0.3.2
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/LICENSE +95 -0
- package/dist/cli/commands/add.d.ts +37 -0
- package/dist/cli/commands/add.d.ts.map +1 -0
- package/dist/cli/commands/add.js +99 -0
- package/dist/cli/commands/add.js.map +1 -0
- package/dist/cli/commands/conflict.d.ts +52 -0
- package/dist/cli/commands/conflict.d.ts.map +1 -0
- package/dist/cli/commands/conflict.js +88 -0
- package/dist/cli/commands/conflict.js.map +1 -0
- package/dist/cli/commands/installFromSources.d.ts +78 -0
- package/dist/cli/commands/installFromSources.d.ts.map +1 -0
- package/dist/cli/commands/installFromSources.js +187 -0
- package/dist/cli/commands/installFromSources.js.map +1 -0
- package/dist/cli/commands/ls.d.ts +26 -0
- package/dist/cli/commands/ls.d.ts.map +1 -0
- package/dist/cli/commands/ls.js +85 -0
- package/dist/cli/commands/ls.js.map +1 -0
- package/dist/cli/commands/remove.d.ts +19 -0
- package/dist/cli/commands/remove.d.ts.map +1 -0
- package/dist/cli/commands/remove.js +123 -0
- package/dist/cli/commands/remove.js.map +1 -0
- package/dist/cli/commands/sources.d.ts +69 -0
- package/dist/cli/commands/sources.d.ts.map +1 -0
- package/dist/cli/commands/sources.js +103 -0
- package/dist/cli/commands/sources.js.map +1 -0
- package/dist/cli/commands/update.d.ts +17 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +110 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/dialogue.d.ts +126 -0
- package/dist/cli/dialogue.d.ts.map +1 -0
- package/dist/cli/dialogue.js +156 -0
- package/dist/cli/dialogue.js.map +1 -0
- package/dist/cli/index.d.ts +19 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +16 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/installDialogues.d.ts +23 -0
- package/dist/cli/installDialogues.d.ts.map +1 -0
- package/dist/cli/installDialogues.js +89 -0
- package/dist/cli/installDialogues.js.map +1 -0
- package/dist/cli/pick.d.ts +23 -0
- package/dist/cli/pick.d.ts.map +1 -0
- package/dist/cli/pick.js +44 -0
- package/dist/cli/pick.js.map +1 -0
- package/dist/cli/report.d.ts +58 -0
- package/dist/cli/report.d.ts.map +1 -0
- package/dist/cli/report.js +92 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/theme.d.ts +27 -0
- package/dist/cli/theme.d.ts.map +1 -0
- package/dist/cli/theme.js +29 -0
- package/dist/cli/theme.js.map +1 -0
- package/dist/cli/types.d.ts +96 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/config.d.ts +55 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +107 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +182 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +51 -0
- package/dist/config/types.js.map +1 -0
- package/dist/hash/hash.d.ts +23 -0
- package/dist/hash/hash.d.ts.map +1 -0
- package/dist/hash/hash.js +43 -0
- package/dist/hash/hash.js.map +1 -0
- package/dist/hash/index.d.ts +2 -0
- package/dist/hash/index.d.ts.map +1 -0
- package/dist/hash/index.js +3 -0
- package/dist/hash/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/installer/classify.d.ts +33 -0
- package/dist/installer/classify.d.ts.map +1 -0
- package/dist/installer/classify.js +82 -0
- package/dist/installer/classify.js.map +1 -0
- package/dist/installer/files.d.ts +19 -0
- package/dist/installer/files.d.ts.map +1 -0
- package/dist/installer/files.js +23 -0
- package/dist/installer/files.js.map +1 -0
- package/dist/installer/index.d.ts +19 -0
- package/dist/installer/index.d.ts.map +1 -0
- package/dist/installer/index.js +14 -0
- package/dist/installer/index.js.map +1 -0
- package/dist/installer/install.d.ts +25 -0
- package/dist/installer/install.d.ts.map +1 -0
- package/dist/installer/install.js +74 -0
- package/dist/installer/install.js.map +1 -0
- package/dist/installer/io.d.ts +9 -0
- package/dist/installer/io.d.ts.map +1 -0
- package/dist/installer/io.js +23 -0
- package/dist/installer/io.js.map +1 -0
- package/dist/installer/manifest.d.ts +69 -0
- package/dist/installer/manifest.d.ts.map +1 -0
- package/dist/installer/manifest.js +70 -0
- package/dist/installer/manifest.js.map +1 -0
- package/dist/installer/manifestSources.d.ts +32 -0
- package/dist/installer/manifestSources.d.ts.map +1 -0
- package/dist/installer/manifestSources.js +50 -0
- package/dist/installer/manifestSources.js.map +1 -0
- package/dist/installer/marketplace.d.ts +46 -0
- package/dist/installer/marketplace.d.ts.map +1 -0
- package/dist/installer/marketplace.js +72 -0
- package/dist/installer/marketplace.js.map +1 -0
- package/dist/installer/origin.d.ts +59 -0
- package/dist/installer/origin.d.ts.map +1 -0
- package/dist/installer/origin.js +29 -0
- package/dist/installer/origin.js.map +1 -0
- package/dist/installer/remove.d.ts +26 -0
- package/dist/installer/remove.d.ts.map +1 -0
- package/dist/installer/remove.js +49 -0
- package/dist/installer/remove.js.map +1 -0
- package/dist/installer/resolve.d.ts +127 -0
- package/dist/installer/resolve.d.ts.map +1 -0
- package/dist/installer/resolve.js +251 -0
- package/dist/installer/resolve.js.map +1 -0
- package/dist/installer/sourceRegistry.d.ts +96 -0
- package/dist/installer/sourceRegistry.d.ts.map +1 -0
- package/dist/installer/sourceRegistry.js +86 -0
- package/dist/installer/sourceRegistry.js.map +1 -0
- package/dist/installer/types.d.ts +133 -0
- package/dist/installer/types.d.ts.map +1 -0
- package/dist/installer/types.js +31 -0
- package/dist/installer/types.js.map +1 -0
- package/dist/registry/index.d.ts +8 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +9 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/registry.handlers.d.ts +16 -0
- package/dist/registry/registry.handlers.d.ts.map +1 -0
- package/dist/registry/registry.handlers.js +13 -0
- package/dist/registry/registry.handlers.js.map +1 -0
- package/dist/registry/registry.io.d.ts +38 -0
- package/dist/registry/registry.io.d.ts.map +1 -0
- package/dist/registry/registry.io.js +101 -0
- package/dist/registry/registry.io.js.map +1 -0
- package/dist/registry/registry.mutations.d.ts +19 -0
- package/dist/registry/registry.mutations.d.ts.map +1 -0
- package/dist/registry/registry.mutations.js +29 -0
- package/dist/registry/registry.mutations.js.map +1 -0
- package/dist/registry/registry.selectors.d.ts +68 -0
- package/dist/registry/registry.selectors.d.ts.map +1 -0
- package/dist/registry/registry.selectors.js +91 -0
- package/dist/registry/registry.selectors.js.map +1 -0
- package/dist/registry/registry.store.d.ts +47 -0
- package/dist/registry/registry.store.d.ts.map +1 -0
- package/dist/registry/registry.store.js +36 -0
- package/dist/registry/registry.store.js.map +1 -0
- package/dist/registry/registry.template.d.ts +29 -0
- package/dist/registry/registry.template.d.ts.map +1 -0
- package/dist/registry/registry.template.js +70 -0
- package/dist/registry/registry.template.js.map +1 -0
- package/dist/registry/types.d.ts +47 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +35 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/security/index.d.ts +2 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +3 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/securityParser.d.ts +15 -0
- package/dist/security/securityParser.d.ts.map +1 -0
- package/dist/security/securityParser.js +79 -0
- package/dist/security/securityParser.js.map +1 -0
- package/dist/security/securityWorker.d.ts +19 -0
- package/dist/security/securityWorker.d.ts.map +1 -0
- package/dist/security/securityWorker.js +137 -0
- package/dist/security/securityWorker.js.map +1 -0
- package/dist/sources/checkout.d.ts +20 -0
- package/dist/sources/checkout.d.ts.map +1 -0
- package/dist/sources/checkout.js +33 -0
- package/dist/sources/checkout.js.map +1 -0
- package/dist/sources/git.d.ts +11 -0
- package/dist/sources/git.d.ts.map +1 -0
- package/dist/sources/git.js +24 -0
- package/dist/sources/git.js.map +1 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +6 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/local.d.ts +12 -0
- package/dist/sources/local.d.ts.map +1 -0
- package/dist/sources/local.js +22 -0
- package/dist/sources/local.js.map +1 -0
- package/dist/sources/npm.d.ts +16 -0
- package/dist/sources/npm.d.ts.map +1 -0
- package/dist/sources/npm.js +162 -0
- package/dist/sources/npm.js.map +1 -0
- package/dist/sources/packageJson.d.ts +3 -0
- package/dist/sources/packageJson.d.ts.map +1 -0
- package/dist/sources/packageJson.js +13 -0
- package/dist/sources/packageJson.js.map +1 -0
- package/dist/sources/parse.d.ts +42 -0
- package/dist/sources/parse.d.ts.map +1 -0
- package/dist/sources/parse.js +114 -0
- package/dist/sources/parse.js.map +1 -0
- package/dist/sources/process.d.ts +21 -0
- package/dist/sources/process.d.ts.map +1 -0
- package/dist/sources/process.js +46 -0
- package/dist/sources/process.js.map +1 -0
- package/dist/sources/register.d.ts +31 -0
- package/dist/sources/register.d.ts.map +1 -0
- package/dist/sources/register.js +52 -0
- package/dist/sources/register.js.map +1 -0
- package/dist/sources/types.d.ts +108 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +53 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +11 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge.d.ts +12 -0
- package/dist/utils/merge.d.ts.map +1 -0
- package/dist/utils/merge.js +28 -0
- package/dist/utils/merge.js.map +1 -0
- package/dist/utils/packageMeta.d.ts +26 -0
- package/dist/utils/packageMeta.d.ts.map +1 -0
- package/dist/utils/packageMeta.js +24 -0
- package/dist/utils/packageMeta.js.map +1 -0
- package/dist/utils/paths.d.ts +27 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +51 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/prompt.d.ts +8 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +13 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/version.d.ts +14 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +140 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +64 -3
- package/README.md +0 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// packages/core/src/sources/parse.ts
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { GIT_URL, GitSourceSpecSchema, LocalSourceSpecSchema, NpmSourceSpecSchema } from "./types";
|
|
5
|
+
const NPM_PREFIX = "npm:";
|
|
6
|
+
const LOCAL_PREFIX = "local:";
|
|
7
|
+
const GITHUB_SHORTHAND = /^[\w.-]+\/[\w.-]+$/;
|
|
8
|
+
/**
|
|
9
|
+
* @brief Reads a source as typed on the command line.
|
|
10
|
+
*
|
|
11
|
+
* `npm:<pkg>[@version]` and `@scope/pkg[@version]` are npm packages, git URLs are git repositories,
|
|
12
|
+
* `local:<path>` and paths starting with `.`, `/` or `~` are local folders, and `owner/repo` is a GitHub repository.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Text as typed, e.g. `npm:@g3nomaly/g3n-skills@^1`, `git@github.com:me/skills.git`, `./my-skills`.
|
|
15
|
+
* @param options - `ref` pins a git source to a branch or tag.
|
|
16
|
+
* @returns The spec for the first form the input matches.
|
|
17
|
+
* @throws {Error} When the input matches no form, or `ref` is given for a source that is not git.
|
|
18
|
+
*/
|
|
19
|
+
export function parseSourceSpec(input, options = {}) {
|
|
20
|
+
const value = input.trim();
|
|
21
|
+
const spec = specFor(value, options.ref);
|
|
22
|
+
if (options.ref !== undefined && spec.kind !== "git") {
|
|
23
|
+
throw new Error(`--ref applies to git sources only, "${value}" is ${spec.kind}`);
|
|
24
|
+
}
|
|
25
|
+
return spec;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @brief Builds the spec for one trimmed input, by the first form it matches.
|
|
29
|
+
*
|
|
30
|
+
* @param value - Trimmed input.
|
|
31
|
+
* @param ref - Branch or tag for a git spec. Ignored for other kinds.
|
|
32
|
+
* @returns The spec.
|
|
33
|
+
* @throws {Error} When the input matches no form.
|
|
34
|
+
*/
|
|
35
|
+
function specFor(value, ref) {
|
|
36
|
+
if (value.startsWith(NPM_PREFIX))
|
|
37
|
+
return npmSpec(value.slice(NPM_PREFIX.length));
|
|
38
|
+
if (value.startsWith(LOCAL_PREFIX))
|
|
39
|
+
return LocalSourceSpecSchema.parse({ kind: "local", path: value.slice(LOCAL_PREFIX.length) });
|
|
40
|
+
if (GIT_URL.test(value))
|
|
41
|
+
return GitSourceSpecSchema.parse({ kind: "git", url: value, ref });
|
|
42
|
+
if (value.startsWith(".") || value.startsWith("~") || path.isAbsolute(value)) {
|
|
43
|
+
return LocalSourceSpecSchema.parse({ kind: "local", path: value });
|
|
44
|
+
}
|
|
45
|
+
if (value.startsWith("@"))
|
|
46
|
+
return npmSpec(value);
|
|
47
|
+
if (GITHUB_SHORTHAND.test(value)) {
|
|
48
|
+
return GitSourceSpecSchema.parse({ kind: "git", url: `https://github.com/${value.replace(/\.git$/, "")}.git`, ref });
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`"${value}" is not a source: use a git URL, owner/repo, npm:<package>, @scope/package or a local path`);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @brief Builds an npm spec from `pkg`, `pkg@1.2.0` or `@scope/pkg@^1`.
|
|
54
|
+
*
|
|
55
|
+
* The version follows the last `@` that is not the scope's.
|
|
56
|
+
*
|
|
57
|
+
* @param value - Package text, with an optional version.
|
|
58
|
+
* @returns The npm spec.
|
|
59
|
+
*/
|
|
60
|
+
function npmSpec(value) {
|
|
61
|
+
const at = value.lastIndexOf("@");
|
|
62
|
+
const hasVersion = at > 0;
|
|
63
|
+
return NpmSourceSpecSchema.parse({
|
|
64
|
+
kind: "npm",
|
|
65
|
+
package: hasVersion ? value.slice(0, at) : value,
|
|
66
|
+
version: hasVersion ? value.slice(at + 1) : undefined,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @brief Derives the name a source registers under when none is given: the repository name for git,
|
|
71
|
+
* the package name without its scope for npm, the folder name for local.
|
|
72
|
+
*
|
|
73
|
+
* @param spec - Spec to derive the name from.
|
|
74
|
+
* @returns A valid source name, e.g. `skills` for `git@github.com:g3nomaly/skills.git`.
|
|
75
|
+
* @throws {Error} When no name can be derived. The caller must then ask for one.
|
|
76
|
+
*/
|
|
77
|
+
export function defaultSourceName(spec) {
|
|
78
|
+
const raw = (() => {
|
|
79
|
+
switch (spec.kind) {
|
|
80
|
+
case "git": return spec.url.replace(/\/+$/, "").split(/[/:]/).pop()?.replace(/\.git$/, "") ?? "";
|
|
81
|
+
case "npm": return spec.package.split("/").pop() ?? spec.package;
|
|
82
|
+
case "local": return path.basename(path.resolve(spec.path));
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
const name = raw.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+/, "");
|
|
86
|
+
if (name === "")
|
|
87
|
+
throw new Error("could not derive a name for the source, pass one with --name");
|
|
88
|
+
return name;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @brief Replaces a leading `~` with the home folder.
|
|
92
|
+
*
|
|
93
|
+
* @param localPath - Path that may start with `~`.
|
|
94
|
+
* @returns The path with the home folder in place of `~`. Any other path is returned unchanged.
|
|
95
|
+
*/
|
|
96
|
+
export function expandHome(localPath) {
|
|
97
|
+
return localPath.startsWith("~") ? path.join(os.homedir(), localPath.slice(1)) : localPath;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @brief Stores a local path the way it is read back: relative to the project root, or absolute when the
|
|
101
|
+
* manifest is shared by every project (a user scope). Other kinds are returned unchanged.
|
|
102
|
+
*
|
|
103
|
+
* @param spec - Spec to anchor. Only `local` specs change.
|
|
104
|
+
* @param cwd - Absolute folder the path was typed in.
|
|
105
|
+
* @param projectRoot - Absolute project root, or `null` to store the path absolute.
|
|
106
|
+
* @returns The spec with its path anchored.
|
|
107
|
+
*/
|
|
108
|
+
export function anchorLocalSpec(spec, cwd, projectRoot) {
|
|
109
|
+
if (spec.kind !== "local")
|
|
110
|
+
return spec;
|
|
111
|
+
const absolute = path.resolve(cwd, expandHome(spec.path));
|
|
112
|
+
return { kind: "local", path: projectRoot === null ? absolute : path.relative(projectRoot, absolute) || "." };
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/sources/parse.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnG,MAAM,UAAU,GAAK,MAAM,CAAC;AAC5B,MAAM,YAAY,GAAG,QAAQ,CAAC;AAC9B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,OAAO,GAAqB,EAAE;IAC3E,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAI,OAAO,CAAC,KAAK,EAAE,OA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ository fails instead of hanging.
|
|
5
|
+
*
|
|
6
|
+
* @param argv - Command and its arguments.
|
|
7
|
+
* @param cwd - Folder to run in. The current folder when absent.
|
|
8
|
+
* @returns Trimmed stdout.
|
|
9
|
+
* @throws {Error} With the command's stderr when it exits non-zero.
|
|
10
|
+
*/
|
|
11
|
+
export declare function runCommand(argv: string[], cwd?: string): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* @brief Creates an empty temporary folder that is also removed at process exit, so a command that bails out early leaves nothing behind.
|
|
14
|
+
*
|
|
15
|
+
* @param label - Part of the folder name, e.g. `git` gives `/tmp/g3n-source-git-XXXXXX`.
|
|
16
|
+
* @returns Absolute path of the folder.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createTempDir(label: string): string;
|
|
19
|
+
/** Deletes a folder and everything in it; a missing folder is not an error. */
|
|
20
|
+
export declare function removeDir(dir: string): void;
|
|
21
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/sources/process.ts"],"names":[],"mappings":"AAKA;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAc9E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAInD;AAED,+EAA+E;AAC/E,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// packages/core/src/sources/process.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* @brief Runs a command to completion and returns its trimmed stdout.
|
|
7
|
+
*
|
|
8
|
+
* Prompts are switched off for git, so a private repository fails instead of hanging.
|
|
9
|
+
*
|
|
10
|
+
* @param argv - Command and its arguments.
|
|
11
|
+
* @param cwd - Folder to run in. The current folder when absent.
|
|
12
|
+
* @returns Trimmed stdout.
|
|
13
|
+
* @throws {Error} With the command's stderr when it exits non-zero.
|
|
14
|
+
*/
|
|
15
|
+
export async function runCommand(argv, cwd) {
|
|
16
|
+
const proc = Bun.spawn(argv, {
|
|
17
|
+
cwd,
|
|
18
|
+
stdout: "pipe",
|
|
19
|
+
stderr: "pipe",
|
|
20
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
|
|
21
|
+
});
|
|
22
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
23
|
+
new Response(proc.stdout).text(),
|
|
24
|
+
new Response(proc.stderr).text(),
|
|
25
|
+
proc.exited,
|
|
26
|
+
]);
|
|
27
|
+
if (exitCode !== 0)
|
|
28
|
+
throw new Error(stderr.trim() !== "" ? stderr.trim() : `${argv.slice(0, 2).join(" ")} exited with ${exitCode}`);
|
|
29
|
+
return stdout.trim();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @brief Creates an empty temporary folder that is also removed at process exit, so a command that bails out early leaves nothing behind.
|
|
33
|
+
*
|
|
34
|
+
* @param label - Part of the folder name, e.g. `git` gives `/tmp/g3n-source-git-XXXXXX`.
|
|
35
|
+
* @returns Absolute path of the folder.
|
|
36
|
+
*/
|
|
37
|
+
export function createTempDir(label) {
|
|
38
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `g3n-source-${label}-`));
|
|
39
|
+
process.once("exit", () => removeDir(dir));
|
|
40
|
+
return dir;
|
|
41
|
+
}
|
|
42
|
+
/** Deletes a folder and everything in it; a missing folder is not an error. */
|
|
43
|
+
export function removeDir(dir) {
|
|
44
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.js","sourceRoot":"","sources":["../../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IAC3E,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RegisteredSource, SourceRecord, SourceSpec } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Lists built-in sources first, then the registered ones, each group sorted by name.
|
|
4
|
+
*
|
|
5
|
+
* @param record - Registered sources of one manifest.
|
|
6
|
+
* @param builtins - Sources shipped with the installer.
|
|
7
|
+
* @returns Every source, flagged `builtin` when it ships with the installer.
|
|
8
|
+
*/
|
|
9
|
+
export declare function listSources(record: SourceRecord, builtins: SourceRecord): RegisteredSource[];
|
|
10
|
+
/**
|
|
11
|
+
* @brief Registers a source under a name.
|
|
12
|
+
*
|
|
13
|
+
* @param record - Registered sources to add to. Not changed.
|
|
14
|
+
* @param name - Name to register under. Must match `SourceNameSchema`.
|
|
15
|
+
* @param spec - Where the source is read from.
|
|
16
|
+
* @param builtins - Sources shipped with the installer. Their names cannot be registered.
|
|
17
|
+
* @returns A new record with the source added.
|
|
18
|
+
* @throws {Error} When the name is invalid, belongs to a built-in source, or is already registered.
|
|
19
|
+
*/
|
|
20
|
+
export declare function addSource(record: SourceRecord, name: string, spec: SourceSpec, builtins: SourceRecord): SourceRecord;
|
|
21
|
+
/**
|
|
22
|
+
* @brief Removes a registered source.
|
|
23
|
+
*
|
|
24
|
+
* @param record - Registered sources to remove from. Not changed.
|
|
25
|
+
* @param name - Name of the source to remove.
|
|
26
|
+
* @param builtins - Sources shipped with the installer. They cannot be removed.
|
|
27
|
+
* @returns A new record without the source.
|
|
28
|
+
* @throws {Error} When `name` is a built-in source or is not registered.
|
|
29
|
+
*/
|
|
30
|
+
export declare function removeSource(record: SourceRecord, name: string, builtins: SourceRecord): SourceRecord;
|
|
31
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/sources/register.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,GAAG,gBAAgB,EAAE,CAM5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,GAAG,YAAY,CAKpH;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,YAAY,CAKrG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// packages/core/src/sources/register.ts
|
|
2
|
+
import { SourceNameSchema, SourceSpecSchema } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* @brief Lists built-in sources first, then the registered ones, each group sorted by name.
|
|
5
|
+
*
|
|
6
|
+
* @param record - Registered sources of one manifest.
|
|
7
|
+
* @param builtins - Sources shipped with the installer.
|
|
8
|
+
* @returns Every source, flagged `builtin` when it ships with the installer.
|
|
9
|
+
*/
|
|
10
|
+
export function listSources(record, builtins) {
|
|
11
|
+
const sorted = (r) => Object.entries(r).sort(([a], [b]) => a.localeCompare(b));
|
|
12
|
+
return [
|
|
13
|
+
...sorted(builtins).map(([name, spec]) => ({ name, spec, builtin: true })),
|
|
14
|
+
...sorted(record).filter(([name]) => builtins[name] === undefined).map(([name, spec]) => ({ name, spec, builtin: false })),
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @brief Registers a source under a name.
|
|
19
|
+
*
|
|
20
|
+
* @param record - Registered sources to add to. Not changed.
|
|
21
|
+
* @param name - Name to register under. Must match `SourceNameSchema`.
|
|
22
|
+
* @param spec - Where the source is read from.
|
|
23
|
+
* @param builtins - Sources shipped with the installer. Their names cannot be registered.
|
|
24
|
+
* @returns A new record with the source added.
|
|
25
|
+
* @throws {Error} When the name is invalid, belongs to a built-in source, or is already registered.
|
|
26
|
+
*/
|
|
27
|
+
export function addSource(record, name, spec, builtins) {
|
|
28
|
+
const valid = SourceNameSchema.parse(name);
|
|
29
|
+
if (builtins[valid] !== undefined)
|
|
30
|
+
throw new Error(`"${valid}" is a built-in source and is always registered`);
|
|
31
|
+
if (record[valid] !== undefined)
|
|
32
|
+
throw new Error(`a source named "${valid}" is already registered`);
|
|
33
|
+
return { ...record, [valid]: SourceSpecSchema.parse(spec) };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @brief Removes a registered source.
|
|
37
|
+
*
|
|
38
|
+
* @param record - Registered sources to remove from. Not changed.
|
|
39
|
+
* @param name - Name of the source to remove.
|
|
40
|
+
* @param builtins - Sources shipped with the installer. They cannot be removed.
|
|
41
|
+
* @returns A new record without the source.
|
|
42
|
+
* @throws {Error} When `name` is a built-in source or is not registered.
|
|
43
|
+
*/
|
|
44
|
+
export function removeSource(record, name, builtins) {
|
|
45
|
+
if (builtins[name] !== undefined)
|
|
46
|
+
throw new Error(`"${name}" is a built-in source and cannot be removed`);
|
|
47
|
+
if (record[name] === undefined)
|
|
48
|
+
throw new Error(`no source named "${name}" is registered`);
|
|
49
|
+
const { [name]: _removed, ...rest } = record;
|
|
50
|
+
return rest;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js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,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,KAAK,yBAAyB,CAAC,CAAC;IACpG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,IAAY,EAAE,QAAsB;IACrF,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,8CAA8C,CAAC,CAAC;IAC1G,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,iBAAiB,CAAC,CAAC;IAC3F,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Clone URLs `git` accepts without a prompt: https://, ssh://, git://, file:// or scp-style `git@host:path`. */
|
|
3
|
+
export declare const GIT_URL: RegExp;
|
|
4
|
+
/** npm package names, scoped or not, e.g. `@g3nomaly/g3n-skills`. */
|
|
5
|
+
export declare const NPM_PACKAGE: RegExp;
|
|
6
|
+
/** Name a source is registered under, e.g. `g3n-skills`. */
|
|
7
|
+
export declare const SourceNameSchema: z.ZodString;
|
|
8
|
+
/**
|
|
9
|
+
* @brief Spec of a git source: a clone of a repository.
|
|
10
|
+
*
|
|
11
|
+
* @property kind - Always `git`.
|
|
12
|
+
* @property url - Clone URL.
|
|
13
|
+
* @property ref - Branch or tag to check out. The default branch when absent.
|
|
14
|
+
*/
|
|
15
|
+
export declare const GitSourceSpecSchema: z.ZodObject<{
|
|
16
|
+
kind: z.ZodLiteral<"git">;
|
|
17
|
+
url: z.ZodString;
|
|
18
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
/**
|
|
21
|
+
* @brief Spec of an npm source: a published package.
|
|
22
|
+
*
|
|
23
|
+
* @property kind - Always `npm`.
|
|
24
|
+
* @property package - Package name, scoped or not.
|
|
25
|
+
* @property version - Exact version, semver range or dist-tag. When absent, any installed copy is accepted, else `latest`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const NpmSourceSpecSchema: z.ZodObject<{
|
|
28
|
+
kind: z.ZodLiteral<"npm">;
|
|
29
|
+
package: z.ZodString;
|
|
30
|
+
version: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
/**
|
|
33
|
+
* @brief Spec of a local source: a folder on disk.
|
|
34
|
+
*
|
|
35
|
+
* @property kind - Always `local`.
|
|
36
|
+
* @property path - Folder holding the source, absolute or relative to the project root.
|
|
37
|
+
*/
|
|
38
|
+
export declare const LocalSourceSpecSchema: z.ZodObject<{
|
|
39
|
+
kind: z.ZodLiteral<"local">;
|
|
40
|
+
path: z.ZodString;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
/** Where a source's files come from: a git, npm or local spec. */
|
|
43
|
+
export declare const SourceSpecSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
44
|
+
kind: z.ZodLiteral<"git">;
|
|
45
|
+
url: z.ZodString;
|
|
46
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
47
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
48
|
+
kind: z.ZodLiteral<"npm">;
|
|
49
|
+
package: z.ZodString;
|
|
50
|
+
version: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
52
|
+
kind: z.ZodLiteral<"local">;
|
|
53
|
+
path: z.ZodString;
|
|
54
|
+
}, z.core.$strip>], "kind">;
|
|
55
|
+
/** Registered sources by name, as an installer manifest stores them under its `sources` key. */
|
|
56
|
+
export declare const SourceRecordSchema: z.ZodRecord<z.ZodString, z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"git">;
|
|
58
|
+
url: z.ZodString;
|
|
59
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
60
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
61
|
+
kind: z.ZodLiteral<"npm">;
|
|
62
|
+
package: z.ZodString;
|
|
63
|
+
version: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
65
|
+
kind: z.ZodLiteral<"local">;
|
|
66
|
+
path: z.ZodString;
|
|
67
|
+
}, z.core.$strip>], "kind">>;
|
|
68
|
+
/** Git source spec, inferred from `GitSourceSpecSchema`. */
|
|
69
|
+
export type GitSourceSpec = z.infer<typeof GitSourceSpecSchema>;
|
|
70
|
+
/** npm source spec, inferred from `NpmSourceSpecSchema`. */
|
|
71
|
+
export type NpmSourceSpec = z.infer<typeof NpmSourceSpecSchema>;
|
|
72
|
+
/** Local source spec, inferred from `LocalSourceSpecSchema`. */
|
|
73
|
+
export type LocalSourceSpec = z.infer<typeof LocalSourceSpecSchema>;
|
|
74
|
+
/** Any source spec, inferred from `SourceSpecSchema`. */
|
|
75
|
+
export type SourceSpec = z.infer<typeof SourceSpecSchema>;
|
|
76
|
+
/** Registered sources by name, inferred from `SourceRecordSchema`. */
|
|
77
|
+
export type SourceRecord = z.infer<typeof SourceRecordSchema>;
|
|
78
|
+
/**
|
|
79
|
+
* @brief One source an installer can read from, either built into its code or registered by the user.
|
|
80
|
+
*
|
|
81
|
+
* @property name - Name the source is listed under.
|
|
82
|
+
* @property spec - Where the source's files come from.
|
|
83
|
+
* @property builtin - Built into the installer. Always listed and never removable.
|
|
84
|
+
*/
|
|
85
|
+
export interface RegisteredSource {
|
|
86
|
+
name: string;
|
|
87
|
+
spec: SourceSpec;
|
|
88
|
+
builtin: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @brief A source resolved to a folder on disk. Call `dispose` once its files have been read.
|
|
92
|
+
*
|
|
93
|
+
* @property name - Name of the source.
|
|
94
|
+
* @property spec - Spec the checkout was made from.
|
|
95
|
+
* @property dir - Absolute root of the source's files.
|
|
96
|
+
* @property commit - Commit the git clone resolved to. Absent for npm and local sources.
|
|
97
|
+
* @property version - Package version for npm sources, or the `version` in a local source's package.json.
|
|
98
|
+
* @property dispose - Removes a temporary checkout. A no-op for folders the checkout did not create.
|
|
99
|
+
*/
|
|
100
|
+
export interface SourceCheckout {
|
|
101
|
+
name: string;
|
|
102
|
+
spec: SourceSpec;
|
|
103
|
+
dir: string;
|
|
104
|
+
commit?: string;
|
|
105
|
+
version?: string;
|
|
106
|
+
dispose: () => void;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sources/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,iHAAiH;AACjH,eAAO,MAAM,OAAO,QAAwD,CAAC;AAE7E,qEAAqE;AACrE,eAAO,MAAM,WAAW,QAAuD,CAAC;AAEhF,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,aAEyF,CAAC;AAEvH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;iBAGhC,CAAC;AAEH,kEAAkE;AAClE,eAAO,MAAM,gBAAgB;;;;;;;;;;;2BAI3B,CAAC;AAEH,gGAAgG;AAChG,eAAO,MAAM,kBAAkB;;;;;;;;;;;4BAA+C,CAAC;AAE/E,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAK,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,4DAA4D;AAC5D,MAAM,MAAM,aAAa,GAAK,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,gEAAgE;AAChE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAQ,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC/D,sEAAsE;AACtE,MAAM,MAAM,YAAY,GAAM,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAK,MAAM,CAAC;IAChB,IAAI,EAAK,UAAU,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAM,MAAM,CAAC;IACjB,IAAI,EAAM,UAAU,CAAC;IACrB,GAAG,EAAO,MAAM,CAAC;IACjB,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAG,MAAM,IAAI,CAAC;CACtB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// packages/core/src/sources/types.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Clone URLs `git` accepts without a prompt: https://, ssh://, git://, file:// or scp-style `git@host:path`. */
|
|
4
|
+
export const GIT_URL = /^(https?:\/\/|ssh:\/\/|git:\/\/|file:\/\/|git@)\S+$/;
|
|
5
|
+
/** npm package names, scoped or not, e.g. `@g3nomaly/g3n-skills`. */
|
|
6
|
+
export const NPM_PACKAGE = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
7
|
+
/** Name a source is registered under, e.g. `g3n-skills`. */
|
|
8
|
+
export const SourceNameSchema = z
|
|
9
|
+
.string()
|
|
10
|
+
.regex(/^[a-z0-9][a-z0-9._-]*$/, "use lowercase letters, digits, `.`, `_` and `-`, starting with a letter or digit");
|
|
11
|
+
/**
|
|
12
|
+
* @brief Spec of a git source: a clone of a repository.
|
|
13
|
+
*
|
|
14
|
+
* @property kind - Always `git`.
|
|
15
|
+
* @property url - Clone URL.
|
|
16
|
+
* @property ref - Branch or tag to check out. The default branch when absent.
|
|
17
|
+
*/
|
|
18
|
+
export const GitSourceSpecSchema = z.object({
|
|
19
|
+
kind: z.literal("git"),
|
|
20
|
+
url: z.string().regex(GIT_URL, "is not a git URL (https://, ssh://, git://, file:// or git@)"),
|
|
21
|
+
ref: z.string().min(1).optional(),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* @brief Spec of an npm source: a published package.
|
|
25
|
+
*
|
|
26
|
+
* @property kind - Always `npm`.
|
|
27
|
+
* @property package - Package name, scoped or not.
|
|
28
|
+
* @property version - Exact version, semver range or dist-tag. When absent, any installed copy is accepted, else `latest`.
|
|
29
|
+
*/
|
|
30
|
+
export const NpmSourceSpecSchema = z.object({
|
|
31
|
+
kind: z.literal("npm"),
|
|
32
|
+
package: z.string().regex(NPM_PACKAGE, "is not an npm package name"),
|
|
33
|
+
version: z.string().min(1).optional(),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* @brief Spec of a local source: a folder on disk.
|
|
37
|
+
*
|
|
38
|
+
* @property kind - Always `local`.
|
|
39
|
+
* @property path - Folder holding the source, absolute or relative to the project root.
|
|
40
|
+
*/
|
|
41
|
+
export const LocalSourceSpecSchema = z.object({
|
|
42
|
+
kind: z.literal("local"),
|
|
43
|
+
path: z.string().min(1),
|
|
44
|
+
});
|
|
45
|
+
/** Where a source's files come from: a git, npm or local spec. */
|
|
46
|
+
export const SourceSpecSchema = z.discriminatedUnion("kind", [
|
|
47
|
+
GitSourceSpecSchema,
|
|
48
|
+
NpmSourceSpecSchema,
|
|
49
|
+
LocalSourceSpecSchema,
|
|
50
|
+
]);
|
|
51
|
+
/** Registered sources by name, as an installer manifest stores them under its `sources` key. */
|
|
52
|
+
export const SourceRecordSchema = z.record(SourceNameSchema, SourceSpecSchema);
|
|
53
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sources/types.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,iHAAiH;AACjH,MAAM,CAAC,MAAM,OAAO,GAAG,qDAAqD,CAAC;AAE7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,WAAW,GAAG,oDAAoD,CAAC;AAEhF,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC;KAC9B,MAAM,EAAE;KACR,KAAK,CAAC,wBAAwB,EAAE,kFAAkF,CAAC,CAAC;AAEvH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACtB,GAAG,EAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,8DAA8D,CAAC;IAC/F,GAAG,EAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACnC,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,4BAA4B,CAAC;IACpE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IACxB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACxB,CAAC,CAAC;AAEH,kEAAkE;AAClE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IAC3D,mBAAmB;IACnB,mBAAmB;IACnB,qBAAqB;CACtB,CAAC,CAAC;AAEH,gGAAgG;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Returns the message of a thrown value, whether or not it is an `Error`.
|
|
3
|
+
*
|
|
4
|
+
* @param error - Thrown value of any type, e.g. an `Error` or a string.
|
|
5
|
+
* @returns The `message` of an `Error`, or the value converted to a string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function errorMessage(error: unknown): string;
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// packages/core/src/utils/errors.ts
|
|
2
|
+
/**
|
|
3
|
+
* @brief Returns the message of a thrown value, whether or not it is an `Error`.
|
|
4
|
+
*
|
|
5
|
+
* @param error - Thrown value of any type, e.g. an `Error` or a string.
|
|
6
|
+
* @returns The `message` of an `Error`, or the value converted to a string.
|
|
7
|
+
*/
|
|
8
|
+
export function errorMessage(error) {
|
|
9
|
+
return error instanceof Error ? error.message : String(error);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { findPackageRoot, findUp, findGitRoot } from "./paths";
|
|
2
|
+
export { warnIfOutdated } from "./version";
|
|
3
|
+
export { guardCancel } from "./prompt";
|
|
4
|
+
export { errorMessage } from "./errors";
|
|
5
|
+
export { readPackageMeta } from "./packageMeta";
|
|
6
|
+
export type { PackageMetadata } from "./packageMeta";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// packages/core/src/utils/index.ts
|
|
2
|
+
export { findPackageRoot, findUp, findGitRoot } from "./paths";
|
|
3
|
+
export { warnIfOutdated } from "./version";
|
|
4
|
+
export { guardCancel } from "./prompt";
|
|
5
|
+
export { errorMessage } from "./errors";
|
|
6
|
+
export { readPackageMeta } from "./packageMeta";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Recursively merges `patch` into `base` without mutating either.
|
|
3
|
+
*
|
|
4
|
+
* Plain objects merge key by key. Arrays and primitives in `patch` replace the
|
|
5
|
+
* value in `base`, and keys whose value is `undefined` are skipped.
|
|
6
|
+
*
|
|
7
|
+
* @param base - Value to merge into. Its type is the type of the result.
|
|
8
|
+
* @param patch - Overrides, usually a partial of `base`. Any type.
|
|
9
|
+
* @returns A new value with `patch` applied.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deepMerge<T>(base: T, patch: unknown): T;
|
|
12
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAUvD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// packages/core/src/utils/merge.ts
|
|
2
|
+
/** Tells whether a value is a non-null object that is not an array. */
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @brief Recursively merges `patch` into `base` without mutating either.
|
|
8
|
+
*
|
|
9
|
+
* Plain objects merge key by key. Arrays and primitives in `patch` replace the
|
|
10
|
+
* value in `base`, and keys whose value is `undefined` are skipped.
|
|
11
|
+
*
|
|
12
|
+
* @param base - Value to merge into. Its type is the type of the result.
|
|
13
|
+
* @param patch - Overrides, usually a partial of `base`. Any type.
|
|
14
|
+
* @returns A new value with `patch` applied.
|
|
15
|
+
*/
|
|
16
|
+
export function deepMerge(base, patch) {
|
|
17
|
+
if (!isPlainObject(base) || !isPlainObject(patch)) {
|
|
18
|
+
return (patch === undefined ? base : patch);
|
|
19
|
+
}
|
|
20
|
+
const out = { ...base };
|
|
21
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
continue;
|
|
24
|
+
out[key] = deepMerge(out[key], value);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,uEAAuE;AACvE,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAI,IAAO,EAAE,KAAc;IAClD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAM,CAAC;IACnD,CAAC;IACD,MAAM,GAAG,GAA4B,EAAE,GAAG,IAAI,EAAE,CAAC;IACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name, version, description and license of a package, as its `package.json` states them.
|
|
3
|
+
*
|
|
4
|
+
* Built by `readPackageMeta`. The `mods`, `skills` and `ui` CLIs read it to name themselves.
|
|
5
|
+
*
|
|
6
|
+
* @property name - Package name, e.g. `@g3nomaly/core`, or `""` when missing.
|
|
7
|
+
* @property version - Package version, e.g. `1.2.3`, or `"0.0.0"` when missing.
|
|
8
|
+
* @property description - One-line description, or `""` when missing.
|
|
9
|
+
* @property license - SPDX license id, e.g. `MIT`, or `""` when missing.
|
|
10
|
+
*/
|
|
11
|
+
export interface PackageMetadata {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
description: string;
|
|
15
|
+
license: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @brief Reads the metadata of the package that owns `entryUrl`.
|
|
19
|
+
*
|
|
20
|
+
* Reads `package.json` on every call, so the result is never stale.
|
|
21
|
+
*
|
|
22
|
+
* @param entryUrl - File URL of a module in the package, pass `import.meta.url`.
|
|
23
|
+
* @returns Metadata of that package. Missing fields come back as empty strings, and a missing version as `"0.0.0"`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readPackageMeta(entryUrl: string): PackageMetadata;
|
|
26
|
+
//# sourceMappingURL=packageMeta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageMeta.d.ts","sourceRoot":"","sources":["../../src/utils/packageMeta.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAS,MAAM,CAAC;IACpB,OAAO,EAAM,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAM,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,CASjE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// packages/core/src/utils/packageMeta.ts
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { findPackageRoot } from "./paths";
|
|
6
|
+
/**
|
|
7
|
+
* @brief Reads the metadata of the package that owns `entryUrl`.
|
|
8
|
+
*
|
|
9
|
+
* Reads `package.json` on every call, so the result is never stale.
|
|
10
|
+
*
|
|
11
|
+
* @param entryUrl - File URL of a module in the package, pass `import.meta.url`.
|
|
12
|
+
* @returns Metadata of that package. Missing fields come back as empty strings, and a missing version as `"0.0.0"`.
|
|
13
|
+
*/
|
|
14
|
+
export function readPackageMeta(entryUrl) {
|
|
15
|
+
const root = findPackageRoot(dirname(fileURLToPath(entryUrl)));
|
|
16
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
17
|
+
return {
|
|
18
|
+
name: typeof pkg.name === "string" ? pkg.name : "",
|
|
19
|
+
version: typeof pkg.version === "string" ? pkg.version : "0.0.0",
|
|
20
|
+
description: typeof pkg.description === "string" ? pkg.description : "",
|
|
21
|
+
license: typeof pkg.license === "string" ? pkg.license : "",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=packageMeta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageMeta.js","sourceRoot":"","sources":["../../src/utils/packageMeta.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAmB1C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAA4B,CAAC;IACpG,OAAO;QACL,IAAI,EAAS,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QACzD,OAAO,EAAM,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO;QACpE,WAAW,EAAE,OAAO,GAAG,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE;QACvE,OAAO,EAAM,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;KAChE,CAAC;AACJ,CAAC"}
|