@sublang/spex 4.2.0 → 5.0.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 +433 -89
- package/dist/cli.js +80 -42
- package/dist/commands/add.d.ts +12 -0
- package/dist/commands/add.js +138 -0
- package/dist/commands/auth-target.d.ts +11 -0
- package/dist/commands/auth-target.js +50 -0
- package/dist/commands/environment.d.ts +123 -0
- package/dist/commands/environment.js +411 -0
- package/dist/commands/export.d.ts +21 -0
- package/dist/commands/export.js +663 -0
- package/dist/commands/home.d.ts +56 -0
- package/dist/commands/home.js +215 -0
- package/dist/commands/install.d.ts +2 -0
- package/dist/commands/install.js +48 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +87 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +211 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +74 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +120 -0
- package/dist/commands/remove.d.ts +2 -0
- package/dist/commands/remove.js +34 -0
- package/dist/commands/run.d.ts +50 -0
- package/dist/commands/run.js +309 -0
- package/dist/commands/search.d.ts +2 -0
- package/dist/commands/search.js +34 -0
- package/dist/commands/settle.d.ts +124 -0
- package/dist/commands/settle.js +475 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +37 -0
- package/dist/commands/whoami.d.ts +2 -0
- package/dist/commands/whoami.js +75 -0
- package/dist/lib/environment/agent-folders.d.ts +14 -0
- package/dist/lib/environment/agent-folders.js +11 -0
- package/dist/lib/environment/archive.d.ts +26 -0
- package/dist/lib/environment/archive.js +91 -0
- package/dist/lib/environment/builtins.d.ts +112 -0
- package/dist/lib/environment/builtins.js +539 -0
- package/dist/lib/environment/citations.d.ts +75 -0
- package/dist/lib/environment/citations.js +267 -0
- package/dist/lib/environment/exports.d.ts +190 -0
- package/dist/lib/environment/exports.js +1029 -0
- package/dist/lib/environment/format.d.ts +133 -0
- package/dist/lib/environment/format.js +651 -0
- package/dist/lib/environment/git-source.d.ts +41 -0
- package/dist/lib/environment/git-source.js +159 -0
- package/dist/lib/environment/index.d.ts +20 -0
- package/dist/lib/environment/index.js +27 -0
- package/dist/lib/environment/install.d.ts +140 -0
- package/dist/lib/environment/install.js +694 -0
- package/dist/lib/environment/layout.d.ts +15 -0
- package/dist/lib/environment/layout.js +50 -0
- package/dist/lib/environment/lock.d.ts +87 -0
- package/dist/lib/environment/lock.js +305 -0
- package/dist/lib/environment/marker.d.ts +15 -0
- package/dist/lib/environment/marker.js +31 -0
- package/dist/lib/environment/own-paths.d.ts +59 -0
- package/dist/lib/environment/own-paths.js +174 -0
- package/dist/lib/environment/placed-record.d.ts +32 -0
- package/dist/lib/environment/placed-record.js +72 -0
- package/dist/lib/environment/registries.d.ts +25 -0
- package/dist/lib/environment/registries.js +75 -0
- package/dist/lib/environment/registry.d.ts +173 -0
- package/dist/lib/environment/registry.js +390 -0
- package/dist/lib/environment/requests.d.ts +108 -0
- package/dist/lib/environment/requests.js +403 -0
- package/dist/lib/environment/resolve.d.ts +70 -0
- package/dist/lib/environment/resolve.js +451 -0
- package/dist/lib/environment/semver.d.ts +30 -0
- package/dist/lib/environment/semver.js +130 -0
- package/dist/lib/environment/store.d.ts +23 -0
- package/dist/lib/environment/store.js +123 -0
- package/dist/lib/environment/tar.d.ts +27 -0
- package/dist/lib/environment/tar.js +219 -0
- package/dist/lib/files.d.ts +66 -0
- package/dist/lib/files.js +233 -0
- package/dist/lib/git-host.d.ts +579 -0
- package/dist/lib/git-host.js +1363 -0
- package/dist/lib/home-file.d.ts +124 -0
- package/dist/lib/home-file.js +288 -0
- package/dist/lib/instance.d.ts +63 -0
- package/dist/lib/instance.js +130 -0
- package/dist/lib/words.d.ts +32 -0
- package/dist/lib/words.js +27 -0
- package/dist/lint.js +8 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/standin-registry.d.ts +94 -0
- package/dist/testing/standin-registry.js +449 -0
- package/package.json +37 -3
- package/dist/attached-cli.d.ts +0 -13
- package/dist/attached-cli.js +0 -249
- package/dist/attached-client.d.ts +0 -53
- package/dist/attached-client.js +0 -237
- package/dist/generated-protocol.d.ts +0 -2
- package/dist/generated-protocol.js +0 -6
- package/dist/package-init.d.ts +0 -21
- package/dist/package-init.js +0 -442
package/dist/cli.js
CHANGED
|
@@ -1,57 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
4
5
|
import { lint } from "./lint.js";
|
|
5
6
|
import { scaffold } from "./scaffold.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
import { add } from "./commands/add.js";
|
|
8
|
+
import { exportPackage } from "./commands/export.js";
|
|
9
|
+
import { install } from "./commands/install.js";
|
|
10
|
+
import { list } from "./commands/list.js";
|
|
11
|
+
import { login } from "./commands/login.js";
|
|
12
|
+
import { publish } from "./commands/publish.js";
|
|
13
|
+
import { logout } from "./commands/logout.js";
|
|
14
|
+
import { remove } from "./commands/remove.js";
|
|
15
|
+
import { search } from "./commands/search.js";
|
|
16
|
+
import { update } from "./commands/update.js";
|
|
17
|
+
import { whoami } from "./commands/whoami.js";
|
|
18
|
+
import { commandHelp, commandNamed, runCommand, USAGE } from "./commands/run.js";
|
|
19
|
+
/** The commands run with the shared runner (cli-13): exit 0 on success,
|
|
20
|
+
* 1 with the cause on standard error, 130 on an interrupt. */
|
|
21
|
+
const COMMANDS = {
|
|
22
|
+
add, remove, rm: remove, install, i: install, update, list, ls: list, search, export: exportPackage, publish,
|
|
23
|
+
login, logout, whoami,
|
|
24
|
+
};
|
|
25
|
+
/** The commands keeping their own contracts and exits. */
|
|
26
|
+
const OWN = { scaffold, lint };
|
|
27
|
+
/** Print what was asked on standard output and exit 0 (cli-21). */
|
|
28
|
+
function say(text) {
|
|
29
|
+
process.stdout.write(`${text}\n`);
|
|
30
|
+
process.exitCode = 0;
|
|
31
|
+
}
|
|
32
|
+
/** Refuse a word naming no command, on one line, in the form a command's
|
|
33
|
+
* own refusal takes (cli-13). */
|
|
34
|
+
function unknown(word) {
|
|
35
|
+
process.stderr.write(`spex: ${word.startsWith("-") ? "unknown option" : "unknown command"} ${word} \u2014 spex --help\n`);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
}
|
|
38
|
+
/** The installed `@sublang/spex`'s version, from its package.json. */
|
|
39
|
+
function version() {
|
|
40
|
+
try {
|
|
41
|
+
const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
42
|
+
return typeof manifest.version === "string" ? manifest.version : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Whether a command's words ask for its help: `--help` or `-h` before
|
|
49
|
+
* any `--`. */
|
|
50
|
+
function asksHelp(args) {
|
|
51
|
+
const end = args.indexOf("--");
|
|
52
|
+
return (end < 0 ? args : args.slice(0, end)).some((arg) => arg === "--help" || arg === "-h");
|
|
53
|
+
}
|
|
26
54
|
async function main() {
|
|
27
55
|
const args = process.argv.slice(2);
|
|
28
56
|
const command = args[0];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
57
|
+
// The usage, a command's help and the version read and write nothing
|
|
58
|
+
// (cli-21).
|
|
59
|
+
if (command === undefined || command === "--help" || command === "-h")
|
|
60
|
+
return say(USAGE);
|
|
61
|
+
if (command === "--version" || command === "-V") {
|
|
62
|
+
const installed = version();
|
|
63
|
+
if (installed !== undefined)
|
|
64
|
+
return say(`spex ${installed}`);
|
|
65
|
+
process.stderr.write("spex: package.json cannot be read \u2014 reinstall @sublang/spex\n");
|
|
66
|
+
process.exitCode = 1;
|
|
37
67
|
return;
|
|
38
68
|
}
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
if (command === "help") {
|
|
70
|
+
const asked = args[1];
|
|
71
|
+
if (asked === undefined || asked === "--help" || asked === "-h")
|
|
72
|
+
return say(USAGE);
|
|
73
|
+
const help = commandHelp(asked);
|
|
74
|
+
return help === undefined ? unknown(asked) : say(help);
|
|
42
75
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
76
|
+
const named = Object.hasOwn(COMMANDS, command) || Object.hasOwn(OWN, command) ? commandNamed(command) : undefined;
|
|
77
|
+
if (named === undefined)
|
|
78
|
+
return unknown(command);
|
|
79
|
+
if (asksHelp(args.slice(1)))
|
|
80
|
+
return say(commandHelp(command));
|
|
81
|
+
const run = Object.hasOwn(COMMANDS, command) ? COMMANDS[command] : undefined;
|
|
82
|
+
if (run) {
|
|
83
|
+
const code = await runCommand(command, run, args.slice(1));
|
|
84
|
+
// An interrupted command ends now, once its words are out, whatever
|
|
85
|
+
// request it left pending (cli-13).
|
|
86
|
+
if (code === 130)
|
|
87
|
+
process.stdout.write("", () => process.stderr.write("", () => process.exit(code)));
|
|
88
|
+
else
|
|
89
|
+
process.exitCode = code;
|
|
90
|
+
return;
|
|
54
91
|
}
|
|
92
|
+
OWN[command](args.slice(1));
|
|
55
93
|
}
|
|
56
94
|
void main();
|
|
57
95
|
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Request } from "../lib/environment/index.js";
|
|
2
|
+
import { Environment } from "./environment.js";
|
|
3
|
+
import { type Command } from "./run.js";
|
|
4
|
+
/** Write one package into the environment's `spex.yaml`
|
|
5
|
+
* (environments-15): a file made new explicitly names the public
|
|
6
|
+
* registry (environments-2); comments and key order stay; a file changed
|
|
7
|
+
* meanwhile is refused. */
|
|
8
|
+
export declare function writeRequest(env: Environment, name: string, request: Request, made: boolean): Promise<void>;
|
|
9
|
+
/** Resolve, install and export, then say what was added, updated or
|
|
10
|
+
* removed, with where each package's skills went. */
|
|
11
|
+
export declare function settleAndTell(env: Environment, quiet?: string): Promise<void>;
|
|
12
|
+
export declare const add: Command;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
// `spex add <org>/<pkg>[@<version>]` and `spex add <org>/<pkg> --path
|
|
4
|
+
// <folder>` (cli-2, environments-15): write the package into
|
|
5
|
+
// `spex.yaml` — made explicitly naming the public registry where the
|
|
6
|
+
// root holds none — then resolve, install and export, printing each
|
|
7
|
+
// package added or updated, where its spec stands in `specs/` with the
|
|
8
|
+
// packages its links wait for, and where its skills went for the agents.
|
|
9
|
+
// Every refusal comes before any write: a folder given by `--path` holds
|
|
10
|
+
// the package named, its `meta.yaml` read, before `spex.yaml` is written.
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
13
|
+
import { compareVersions, editRequests, isPackageName, isVersion, KNOWN_FORMAT, packageNameRefusal, parseManifestText, parseVersion, requestIssues, RequestsError, setRequest, setRegistryIn, PUBLIC_REGISTRY_ORIGIN, } from "../lib/environment/index.js";
|
|
14
|
+
import { VersionConflictError } from "../lib/files.js";
|
|
15
|
+
import { actualPath, Environment, shown } from "./environment.js";
|
|
16
|
+
import { gainedLines, leftToAppLines, missingPathLines, settle } from "./settle.js";
|
|
17
|
+
import { parsed, Refusal } from "./run.js";
|
|
18
|
+
/** A refusal of `spex.yaml`'s edit in the CLI's words. */
|
|
19
|
+
function editRefusal(env, error) {
|
|
20
|
+
if (error instanceof VersionConflictError)
|
|
21
|
+
return new Refusal(`${shown(env.root, error.file)} changed meanwhile — retry`);
|
|
22
|
+
if (error instanceof RequestsError)
|
|
23
|
+
return new Refusal(`${error.message} — fix the file, then retry`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/** Write one package into the environment's `spex.yaml`
|
|
27
|
+
* (environments-15): a file made new explicitly names the public
|
|
28
|
+
* registry (environments-2); comments and key order stay; a file changed
|
|
29
|
+
* meanwhile is refused. */
|
|
30
|
+
export async function writeRequest(env, name, request, made) {
|
|
31
|
+
try {
|
|
32
|
+
if (made) {
|
|
33
|
+
await editRequests(env.requestsFile, (doc) => {
|
|
34
|
+
setRegistryIn(doc, PUBLIC_REGISTRY_ORIGIN);
|
|
35
|
+
doc.setIn(["packages", name], doc.createNode(request));
|
|
36
|
+
});
|
|
37
|
+
console.log(`Made spex.yaml in ${env.root}`);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await setRequest(env.requestsFile, name, request);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw editRefusal(env, error) ?? error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Resolve, install and export, then say what was added, updated or
|
|
48
|
+
* removed, with where each package's skills went. */
|
|
49
|
+
export async function settleAndTell(env, quiet = "Nothing changed.") {
|
|
50
|
+
const settled = await settle(env, "resolve");
|
|
51
|
+
if (settled === null)
|
|
52
|
+
return;
|
|
53
|
+
const added = new Set(Object.keys(env.readRequests()?.requests.packages ?? {}));
|
|
54
|
+
const lines = [...gainedLines(env.root, settled, added), ...missingPathLines(settled), ...leftToAppLines(env.root, settled)];
|
|
55
|
+
console.log(lines.length > 0 ? lines.join("\n") : quiet);
|
|
56
|
+
}
|
|
57
|
+
/** Why a folder given by `--path` holds no package of `name`, or
|
|
58
|
+
* nothing: no folder there, no `meta.yaml`, one that cannot be read, or
|
|
59
|
+
* another package's (cli-2). */
|
|
60
|
+
function folderRefusal(root, path, given, name) {
|
|
61
|
+
const dir = join(root, ...path.split("/"));
|
|
62
|
+
if (!existsSync(dir))
|
|
63
|
+
throw new Refusal(`--path ${given}: no folder there — give the folder holding the package's meta.yaml`);
|
|
64
|
+
const file = join(dir, "meta.yaml");
|
|
65
|
+
if (!existsSync(file))
|
|
66
|
+
throw new Refusal(`--path ${given} has no meta.yaml, so it is no package — spex export ${name} --spec <file> | --skill <folder> builds one`);
|
|
67
|
+
const { manifest, issues } = parseManifestText(readFileSync(file, "utf8"));
|
|
68
|
+
if (!manifest)
|
|
69
|
+
throw new Refusal(`--path ${given}: its meta.yaml cannot be read: ${issues.map((issue) => issue.message).join("; ")} — fix it, then retry`);
|
|
70
|
+
const found = `${manifest.org}/${manifest.name}`;
|
|
71
|
+
if (found !== name)
|
|
72
|
+
throw new Refusal(`--path ${given} holds ${found}, not ${name} — spex add ${found} --path ${given}`);
|
|
73
|
+
}
|
|
74
|
+
/** The newest listed version that is no prerelease and is neither yanked
|
|
75
|
+
* nor suppressed. */
|
|
76
|
+
function newestRelease(versions) {
|
|
77
|
+
return versions
|
|
78
|
+
.filter((entry) => entry.format === KNOWN_FORMAT && isVersion(entry.version) && !entry.yanked && !entry.suppressed && parseVersion(entry.version).prerelease.length === 0)
|
|
79
|
+
.map((entry) => entry.version)
|
|
80
|
+
.sort((a, b) => compareVersions(b, a))[0];
|
|
81
|
+
}
|
|
82
|
+
export const add = async (args) => {
|
|
83
|
+
const { values, positionals } = parsed("add", args, { path: { type: "string" } }, { min: 1, max: 1 });
|
|
84
|
+
const spec = positionals[0];
|
|
85
|
+
const at = spec.indexOf("@");
|
|
86
|
+
const name = at < 0 ? spec : spec.slice(0, at);
|
|
87
|
+
const version = at < 0 ? undefined : spec.slice(at + 1);
|
|
88
|
+
if (!isPackageName(name))
|
|
89
|
+
throw new Refusal(packageNameRefusal(name));
|
|
90
|
+
if (version !== undefined && values.path !== undefined)
|
|
91
|
+
throw new Refusal("a version and --path together — give one");
|
|
92
|
+
const env = new Environment();
|
|
93
|
+
const read = env.readRequests();
|
|
94
|
+
let request;
|
|
95
|
+
if (values.path !== undefined) {
|
|
96
|
+
// The folder as given from here, recorded relative to the root.
|
|
97
|
+
// The two compare as text where spelled alike, else as the file
|
|
98
|
+
// system spells them, so a short name and its long one are one.
|
|
99
|
+
const out = (path) => path === "" || isAbsolute(path) || path === ".." || path.startsWith(`..${sep}`);
|
|
100
|
+
let inside = relative(env.root, resolve(values.path));
|
|
101
|
+
if (out(inside))
|
|
102
|
+
inside = relative(actualPath(env.root), actualPath(resolve(values.path)));
|
|
103
|
+
if (out(inside))
|
|
104
|
+
throw new Refusal(`--path ${values.path} leads out of this project folder, ${env.root} — use a folder inside it`);
|
|
105
|
+
request = { path: inside.split(sep).join("/") };
|
|
106
|
+
folderRefusal(env.root, request.path, values.path, name);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (version !== undefined) {
|
|
110
|
+
const malformed = requestIssues(name, { version });
|
|
111
|
+
if (malformed.length > 0)
|
|
112
|
+
throw new Refusal(malformed.map((issue) => issue.message).join("; "));
|
|
113
|
+
}
|
|
114
|
+
const target = env.registryOf(read?.requests ?? null);
|
|
115
|
+
let versions;
|
|
116
|
+
try {
|
|
117
|
+
versions = (await env.registryAt(target.origin, target.scope).index(name)).versions;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw await env.registryRefusal(error, { origin: target.origin, scope: target.scope });
|
|
121
|
+
}
|
|
122
|
+
if (version !== undefined) {
|
|
123
|
+
request = { version };
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const newest = newestRelease(versions);
|
|
127
|
+
if (newest === undefined)
|
|
128
|
+
throw new Refusal(`${name} has no released version at ${await env.registryName(target.origin)} — name one: spex add ${name}@<version>`);
|
|
129
|
+
request = { version: `^${newest}` };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const issues = requestIssues(name, request);
|
|
133
|
+
if (issues.length > 0)
|
|
134
|
+
throw new Refusal(issues.map((issue) => issue.message).join("; "));
|
|
135
|
+
await writeRequest(env, name, request, read === null);
|
|
136
|
+
await settleAndTell(env);
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HomeFile, HomeInstance } from "../lib/home-file.js";
|
|
2
|
+
import type { AuthScope } from "../lib/git-host.js";
|
|
3
|
+
/** The auth default is registry purpose, including for a legacy source.
|
|
4
|
+
* Merely signing in never migrates that source or upgrades a Space slot. */
|
|
5
|
+
export declare function authTarget(home: HomeFile | null, values: {
|
|
6
|
+
space?: string;
|
|
7
|
+
registry?: string;
|
|
8
|
+
}): {
|
|
9
|
+
target: HomeInstance;
|
|
10
|
+
scope: AuthScope;
|
|
11
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { environmentRegistry, readRequestsFile, RequestsError } from "../lib/environment/requests.js";
|
|
5
|
+
import { canonicalOrigin, OriginRefused } from "../lib/instance.js";
|
|
6
|
+
import { addressRefusal, defaultInstance, namedInstance } from "./home.js";
|
|
7
|
+
import { Refusal } from "./run.js";
|
|
8
|
+
/** The `spex.yaml` nearest the current folder, null where none stands;
|
|
9
|
+
* one that does not read refuses the command (cli-13). */
|
|
10
|
+
function nearestRequests() {
|
|
11
|
+
for (let dir = process.cwd();; dir = dirname(dir)) {
|
|
12
|
+
let read;
|
|
13
|
+
try {
|
|
14
|
+
read = readRequestsFile(join(dir, "spex.yaml"));
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof RequestsError && error.newerFormat !== undefined)
|
|
18
|
+
throw new Refusal("spex.yaml is from a newer Spex — update Spex");
|
|
19
|
+
if (error instanceof RequestsError)
|
|
20
|
+
throw new Refusal(`${error.message} — fix the file, then retry`);
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
if (read)
|
|
24
|
+
return read.requests;
|
|
25
|
+
if (dirname(dir) === dir)
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The auth default is registry purpose, including for a legacy source.
|
|
30
|
+
* Merely signing in never migrates that source or upgrades a Space slot. */
|
|
31
|
+
export function authTarget(home, values) {
|
|
32
|
+
if (values.space !== undefined && values.registry !== undefined)
|
|
33
|
+
throw new Refusal("--registry and --space together — give one");
|
|
34
|
+
if (values.space !== undefined)
|
|
35
|
+
return { target: namedInstance(home, values.space), scope: "space" };
|
|
36
|
+
let origin = values.registry;
|
|
37
|
+
if (origin === undefined) {
|
|
38
|
+
origin = environmentRegistry(nearestRequests(), { origin: defaultInstance(home).origin, instances: home?.instances ?? [] }).origin;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
origin = canonicalOrigin(origin);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error instanceof OriginRefused)
|
|
45
|
+
throw addressRefusal("--registry", origin, error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
return { target: { origin, clientId: "spex" }, scope: "registry" };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=auth-target.js.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ContentStore, type EnvironmentRegistry, RegistryClient, type GitSource, type Lock, type RegistrySource, type RegistrySourceLock, type Requests } from "../lib/environment/index.js";
|
|
2
|
+
import { type FileVersion } from "../lib/files.js";
|
|
3
|
+
import type { AuthScope } from "../lib/git-host.js";
|
|
4
|
+
import { type HomeFile } from "../lib/home-file.js";
|
|
5
|
+
import { Refusal } from "./run.js";
|
|
6
|
+
/** Where a path is on disk, spelled as the file system spells it: its
|
|
7
|
+
* nearest standing ancestor with every link resolved and every short
|
|
8
|
+
* name made long, and the rest as written. */
|
|
9
|
+
export declare function actualPath(path: string): string;
|
|
10
|
+
/** Why a folder cannot be an environment's root (cli-1), or null: the
|
|
11
|
+
* user's home folder, a folder inside the Spex home other than a seat's
|
|
12
|
+
* project below `projects/`, and a folder whose `.spex` holds the home. */
|
|
13
|
+
export declare function refusedRoot(dir: string, home: string): string | null;
|
|
14
|
+
/** The environment root of a command run in `cwd` (cli-1), spelled as
|
|
15
|
+
* `cwd` is, so a path given from `cwd` compares with it as text. A
|
|
16
|
+
* `spex.yaml` in a folder that cannot be a root is passed over; a root
|
|
17
|
+
* that cannot be one refuses the command. */
|
|
18
|
+
export declare function environmentRoot(cwd?: string, home?: string): string;
|
|
19
|
+
/** A file of the environment as read, with the version it was read at. */
|
|
20
|
+
export interface ReadRequests {
|
|
21
|
+
requests: Requests;
|
|
22
|
+
text: string;
|
|
23
|
+
version: FileVersion;
|
|
24
|
+
}
|
|
25
|
+
export interface ReadLock {
|
|
26
|
+
lock: Lock;
|
|
27
|
+
text: string;
|
|
28
|
+
version: FileVersion;
|
|
29
|
+
}
|
|
30
|
+
/** A path under the root as a reader sees it, `/`-separated. */
|
|
31
|
+
export declare function shown(root: string, path: string): string;
|
|
32
|
+
export declare class Environment {
|
|
33
|
+
readonly root: string;
|
|
34
|
+
readonly homeDir: string;
|
|
35
|
+
/** `home.yaml` as it stood when the command began; null where none. */
|
|
36
|
+
readonly home: HomeFile | null;
|
|
37
|
+
readonly requestsFile: string;
|
|
38
|
+
readonly lockFile: string;
|
|
39
|
+
readonly store: ContentStore;
|
|
40
|
+
readonly cache: string;
|
|
41
|
+
readonly git: GitSource;
|
|
42
|
+
private readonly registries;
|
|
43
|
+
private readonly clients;
|
|
44
|
+
private builtin?;
|
|
45
|
+
constructor(cwd?: string);
|
|
46
|
+
/** `spex.yaml` as it stands, null where absent; one that does not read
|
|
47
|
+
* refuses the command saying why and what to do (environments-2,
|
|
48
|
+
* cli-13). */
|
|
49
|
+
readRequests(): ReadRequests | null;
|
|
50
|
+
/** `spex.lock` as it stands, null where absent; one from a newer Spex,
|
|
51
|
+
* or one that does not read, refuses the command saying what to do
|
|
52
|
+
* (environments-3, cli-13): `spex update` writes it again, where the
|
|
53
|
+
* Packages tab, whose Update refuses a lock that does not read, says
|
|
54
|
+
* to remove it first. */
|
|
55
|
+
readLock(): ReadLock | null;
|
|
56
|
+
/** `spex.lock` as `spex update` reads it: one that does not read stands
|
|
57
|
+
* with its version and no lock, for the update to rewrite under that
|
|
58
|
+
* version; one from a newer Spex still refuses the command, as this
|
|
59
|
+
* Spex would lose what it records. */
|
|
60
|
+
readLockForUpdate(): (Omit<ReadLock, "lock"> & {
|
|
61
|
+
lock: Lock | null;
|
|
62
|
+
cause?: string;
|
|
63
|
+
}) | null;
|
|
64
|
+
/** The home's default instance (storage-2). */
|
|
65
|
+
defaultOrigin(): string;
|
|
66
|
+
/** The environment's instance (environments-2): the `space` the
|
|
67
|
+
* requests name, else the home's default instance. */
|
|
68
|
+
instanceOf(requests: Pick<Requests, "space"> | null): string;
|
|
69
|
+
registryOf(requests: Pick<Requests, "space" | "registry"> | null): EnvironmentRegistry;
|
|
70
|
+
/** A registry as the reader knows it (cli-22): its descriptor's
|
|
71
|
+
* display name, else its host; never a Space entry's name. */
|
|
72
|
+
registryName(origin: string): Promise<string>;
|
|
73
|
+
/** The login a registry call presents at an origin, for a refusal to
|
|
74
|
+
* name (cli-13): null where this computer holds no sign-in for that
|
|
75
|
+
* purpose there; undefined where it holds one whose login cannot be
|
|
76
|
+
* read now. A Space's login is its home entry's; a registry's is read
|
|
77
|
+
* from its account API. */
|
|
78
|
+
loginAt(origin: string, scope: AuthScope): Promise<string | null | undefined>;
|
|
79
|
+
/** A registry's refusal or failure as one phrase ending in what to do
|
|
80
|
+
* (cli-13): the registry named as cli-22 names it, a private package by
|
|
81
|
+
* the sign-in state, a 403 by the operation refused. */
|
|
82
|
+
registryRefusal(error: unknown, context: {
|
|
83
|
+
origin: string;
|
|
84
|
+
scope: AuthScope;
|
|
85
|
+
operation?: "read" | "publish";
|
|
86
|
+
version?: string;
|
|
87
|
+
}): Promise<Refusal>;
|
|
88
|
+
/** A Space as the reader knows it: its display name where the home
|
|
89
|
+
* holds one, else its host. */
|
|
90
|
+
nameOf(origin: string): string;
|
|
91
|
+
/** Whether the device is signed in at an instance: the home lists it
|
|
92
|
+
* with its account, not signed out. */
|
|
93
|
+
signedInAt(origin: string): boolean;
|
|
94
|
+
/** Every instance the home is signed in to, in its order. */
|
|
95
|
+
signedIn(): string[];
|
|
96
|
+
/** The app token a registry call presents at an instance
|
|
97
|
+
* (environments-12): its access secret, kept current by its client,
|
|
98
|
+
* where the device is signed in there; none otherwise. */
|
|
99
|
+
tokenAt(origin: string, scope?: AuthScope): Promise<string | null>;
|
|
100
|
+
/** An instance's client, one per command: a refresh the instance
|
|
101
|
+
* refuses removes its token and marks it signed out in `home.yaml` in
|
|
102
|
+
* one step, as the app's sign-out does (git-host-4). */
|
|
103
|
+
private clientAt;
|
|
104
|
+
private markSignedOut;
|
|
105
|
+
/** The built-in spec package as this device's seed holds it
|
|
106
|
+
* (environments-7, environments-11): what the app seeded into the
|
|
107
|
+
* shared store, read from `cache/builtins/`; the command line ships
|
|
108
|
+
* none of its own. */
|
|
109
|
+
seed(): RegistrySource;
|
|
110
|
+
/** The registry answering under an instance's origin, presenting its
|
|
111
|
+
* app token where the device is signed in there; a refusal that signs
|
|
112
|
+
* the device out there marks it signed out in `home.yaml`
|
|
113
|
+
* (environments-12, git-host-4). The built-in spec package is answered
|
|
114
|
+
* from this device's seed first, as the app answers it. */
|
|
115
|
+
private registry;
|
|
116
|
+
registryAt(origin: string, scope?: AuthScope): RegistrySource;
|
|
117
|
+
registryClientAt(origin: string, scope?: AuthScope): RegistryClient;
|
|
118
|
+
/** The registries an install asks for a registry package's files, in
|
|
119
|
+
* the library's order (environments-7). */
|
|
120
|
+
installRegistries(instance: string, source: RegistrySourceLock, scope?: AuthScope): RegistrySource[];
|
|
121
|
+
}
|
|
122
|
+
/** Whether a folder stands at a path. */
|
|
123
|
+
export declare function isDirectory(path: string): boolean;
|