@intentius/chant 0.124.96 → 0.124.98
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/dist/audit/core.d.ts +29 -0
- package/dist/audit/core.d.ts.map +1 -1
- package/dist/audit/core.js +48 -11
- package/dist/audit/identity.d.ts +27 -0
- package/dist/audit/identity.d.ts.map +1 -0
- package/dist/audit/identity.js +36 -0
- package/dist/audit/report-html.d.ts +3 -1
- package/dist/audit/report-html.d.ts.map +1 -1
- package/dist/audit/report-html.js +1 -1
- package/dist/audit/report-model.d.ts +16 -0
- package/dist/audit/report-model.d.ts.map +1 -1
- package/dist/audit/report-model.js +5 -1
- package/dist/change-set-graph.d.ts +3 -1
- package/dist/change-set-graph.d.ts.map +1 -1
- package/dist/change-set-graph.js +7 -1
- package/dist/change-set.d.ts +5 -2
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -3
- package/dist/ci-agent.d.ts +17 -0
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +32 -0
- package/dist/ci-comment-allow.d.ts +88 -0
- package/dist/ci-comment-allow.d.ts.map +1 -0
- package/dist/ci-comment-allow.js +178 -0
- package/dist/ci-comment-commands.d.ts +12 -0
- package/dist/ci-comment-commands.d.ts.map +1 -1
- package/dist/ci-comment-commands.js +22 -0
- package/dist/ci-control.d.ts +6 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +6 -1
- package/dist/ci-product.d.ts +3 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +3 -0
- package/dist/cli/commands/audit.d.ts +3 -1
- package/dist/cli/commands/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +23 -6
- package/dist/cli/commands/import.d.ts +8 -1
- package/dist/cli/commands/import.d.ts.map +1 -1
- package/dist/cli/commands/import.js +31 -6
- package/dist/cli/handlers/agent.d.ts.map +1 -1
- package/dist/cli/handlers/agent.js +12 -2
- package/dist/cli/handlers/pr-comment.d.ts +6 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
- package/dist/cli/handlers/pr-comment.js +12 -0
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +53 -6
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +29 -6
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +23 -0
- package/dist/cli/registry.d.ts +8 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/cloud-lister/mask.d.ts +30 -1
- package/dist/cloud-lister/mask.d.ts.map +1 -1
- package/dist/cloud-lister/mask.js +66 -3
- package/dist/components/driver.d.ts +8 -1
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/driver.js +1 -0
- package/dist/components/product-pipeline.d.ts +23 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +40 -7
- package/dist/components/product-plan.d.ts +20 -0
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +11 -1
- package/dist/control/applied.d.ts +8 -1
- package/dist/control/applied.d.ts.map +1 -1
- package/dist/control/applied.js +18 -2
- package/dist/control/dispatch.d.ts +52 -0
- package/dist/control/dispatch.d.ts.map +1 -1
- package/dist/control/dispatch.js +140 -4
- package/dist/control/train.d.ts +198 -0
- package/dist/control/train.d.ts.map +1 -0
- package/dist/control/train.js +294 -0
- package/dist/deep-observation.js +2 -2
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +7 -1
- package/dist/graph-detail.d.ts +9 -0
- package/dist/graph-detail.d.ts.map +1 -1
- package/dist/graph-detail.js +38 -13
- package/dist/graph-refs.d.ts +233 -3
- package/dist/graph-refs.d.ts.map +1 -1
- package/dist/graph-refs.js +106 -15
- package/dist/lint/post-synth.d.ts +22 -0
- package/dist/lint/post-synth.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
- package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
- package/dist/lint/rules/declarable-naming-convention.js +38 -8
- package/dist/lint/rules/imported-source.d.ts +20 -0
- package/dist/lint/rules/imported-source.d.ts.map +1 -0
- package/dist/lint/rules/imported-source.js +27 -0
- package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
- package/dist/lint/rules/no-unused-declarable.js +3 -0
- package/dist/op/gate.d.ts +2 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +8 -1
- package/dist/pr-forge-reads.d.ts +17 -0
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +55 -0
- package/dist/reconcile.d.ts +9 -0
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/release-floors.d.ts +9 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +10 -2
- package/dist/repo-path.d.ts +29 -0
- package/dist/repo-path.d.ts.map +1 -0
- package/dist/repo-path.js +81 -0
- package/dist/sensitive-key.d.ts +23 -0
- package/dist/sensitive-key.d.ts.map +1 -1
- package/dist/sensitive-key.js +37 -0
- package/dist/terraform/hcl2json.d.ts +7 -0
- package/dist/terraform/hcl2json.d.ts.map +1 -1
- package/dist/terraform/hcl2json.js +7 -0
- package/dist/wave-runtime.mjs +352 -345
- package/dist/workspace/catalog-edges.d.ts +147 -0
- package/dist/workspace/catalog-edges.d.ts.map +1 -0
- package/dist/workspace/catalog-edges.js +461 -0
- package/dist/workspace/compose-graph.d.ts +73 -3
- package/dist/workspace/compose-graph.d.ts.map +1 -1
- package/dist/workspace/declaration.d.ts +2 -0
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +1 -0
- package/dist/workspace/declaration.schema.json +6 -0
- package/dist/workspace/discover.d.ts +134 -0
- package/dist/workspace/discover.d.ts.map +1 -0
- package/dist/workspace/discover.js +372 -0
- package/dist/workspace/graph-cli.d.ts +20 -0
- package/dist/workspace/graph-cli.d.ts.map +1 -1
- package/dist/workspace/graph-cli.js +178 -20
- package/dist/workspace/graph.schema.json +195 -2
- package/dist/workspace/release-train.d.ts +214 -3
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +552 -16
- package/dist/workspace/repo-ref.d.ts +14 -0
- package/dist/workspace/repo-ref.d.ts.map +1 -1
- package/dist/workspace/repo-ref.js +26 -1
- package/dist/workspace/workspace-gates.d.ts +24 -0
- package/dist/workspace/workspace-gates.d.ts.map +1 -1
- package/dist/workspace/workspace-gates.js +29 -5
- package/dist/workspace/workspace-ledger.d.ts +31 -5
- package/dist/workspace/workspace-ledger.d.ts.map +1 -1
- package/dist/workspace/workspace-ledger.js +2 -1
- package/dist/workspace/workspace-run.d.ts +14 -0
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -2
- package/dist/yaml.d.ts.map +1 -1
- package/dist/yaml.js +33 -8
- package/package.json +1 -1
- package/src/audit/core.test.ts +64 -1
- package/src/audit/core.ts +75 -10
- package/src/audit/identity.test.ts +31 -0
- package/src/audit/identity.ts +43 -0
- package/src/audit/report-html.ts +4 -2
- package/src/audit/report-model.ts +21 -1
- package/src/change-set-graph.test.ts +33 -1
- package/src/change-set-graph.ts +7 -1
- package/src/change-set.ts +6 -3
- package/src/ci-agent.test.ts +32 -0
- package/src/ci-agent.ts +42 -0
- package/src/ci-comment-allow.test.ts +380 -0
- package/src/ci-comment-allow.ts +184 -0
- package/src/ci-comment-commands.ts +25 -0
- package/src/ci-control.ts +42 -0
- package/src/ci-product.ts +3 -0
- package/src/cli/commands/audit-parser-notice.test.ts +74 -0
- package/src/cli/commands/audit.test.ts +12 -0
- package/src/cli/commands/audit.ts +25 -7
- package/src/cli/commands/import-layout.test.ts +2 -1
- package/src/cli/commands/import.ts +29 -6
- package/src/cli/handlers/agent.ts +13 -2
- package/src/cli/handlers/pr-before-merge.test.ts +18 -0
- package/src/cli/handlers/pr-comment.ts +12 -0
- package/src/cli/handlers/promote.test.ts +68 -0
- package/src/cli/handlers/promote.ts +52 -6
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +29 -6
- package/src/cli/parse-args.ts +18 -0
- package/src/cli/registry.ts +8 -0
- package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
- package/src/cloud-lister/mask-references.test.ts +132 -0
- package/src/cloud-lister/mask.ts +68 -3
- package/src/components/driver.ts +9 -1
- package/src/components/product-pipeline.ts +57 -7
- package/src/components/product-plan.ts +27 -2
- package/src/control/applied.ts +33 -3
- package/src/control/dispatch.ts +156 -5
- package/src/control/train.test.ts +215 -0
- package/src/control/train.ts +413 -0
- package/src/deep-observation.ts +2 -2
- package/src/floor-table.data.ts +7 -1
- package/src/graph-detail.ts +37 -12
- package/src/graph-refs.test.ts +45 -1
- package/src/graph-refs.ts +321 -14
- package/src/lint/post-synth.ts +20 -0
- package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
- package/src/lint/rules/declarable-naming-convention.ts +35 -8
- package/src/lint/rules/imported-source.test.ts +22 -0
- package/src/lint/rules/imported-source.ts +31 -0
- package/src/lint/rules/no-unused-declarable.test.ts +16 -0
- package/src/lint/rules/no-unused-declarable.ts +7 -0
- package/src/op/gate.ts +10 -2
- package/src/pr-forge-reads.ts +62 -0
- package/src/reconcile.ts +9 -0
- package/src/release-floors.ts +14 -2
- package/src/repo-path.test.ts +72 -0
- package/src/repo-path.ts +103 -0
- package/src/sensitive-key.ts +38 -0
- package/src/terraform/hcl2json.ts +8 -0
- package/src/workspace/application-set.e2e.test.ts +405 -0
- package/src/workspace/catalog-edges.ts +507 -0
- package/src/workspace/ci-green-workflow.test.ts +2 -2
- package/src/workspace/cluster-join.e2e.test.ts +150 -0
- package/src/workspace/compose-graph.ts +74 -5
- package/src/workspace/declaration.schema.json +6 -0
- package/src/workspace/declaration.ts +3 -0
- package/src/workspace/discover.e2e.test.ts +122 -0
- package/src/workspace/discover.test.ts +225 -0
- package/src/workspace/discover.ts +406 -0
- package/src/workspace/drift-reader.test.ts +3 -3
- package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
- package/src/workspace/external-secret-catalog.test.ts +142 -0
- package/src/workspace/graph-cli.ts +207 -21
- package/src/workspace/graph-contract.test.ts +92 -0
- package/src/workspace/graph.schema.json +195 -2
- package/src/workspace/helm-references.e2e.test.ts +135 -0
- package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
- package/src/workspace/identity-annotation-catalog.test.ts +139 -0
- package/src/workspace/release-train-repos.test.ts +304 -0
- package/src/workspace/release-train.test.ts +296 -0
- package/src/workspace/release-train.ts +631 -16
- package/src/workspace/repo-ref.ts +26 -1
- package/src/workspace/runs-on.test.ts +45 -0
- package/src/workspace/workspace-gates.ts +48 -5
- package/src/workspace/workspace-ledger.ts +28 -5
- package/src/workspace/workspace-run.test.ts +1 -1
- package/src/workspace/workspace-run.ts +2 -2
- package/src/yaml.test.ts +96 -8
- package/src/yaml.ts +36 -8
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant workspace graph <dir> --discover` (#5095): the graph of a directory
|
|
3
|
+
* that has no `chant.workspace.json`, read as if a declaration listed what
|
|
4
|
+
* the kinds' probes find there. Nothing is written inside the directory.
|
|
5
|
+
*
|
|
6
|
+
* The walk visits every directory under `<dir>`, leaving out `node_modules`
|
|
7
|
+
* and directories whose names start with a dot (`.git` among them), and
|
|
8
|
+
* resolves each with {@link resolveKind}, by probe and precedence. What it
|
|
9
|
+
* finds becomes a declaration held in memory, which {@link discoveredTree}
|
|
10
|
+
* lays over the files as `chant.workspace.json` at the root. The read then
|
|
11
|
+
* goes through the same path as a declared one: the same plan, reader
|
|
12
|
+
* projects, member cache and composition.
|
|
13
|
+
*
|
|
14
|
+
* A claimed directory is a member unless one of these holds, and each case is
|
|
15
|
+
* listed in `discovered` with its outcome:
|
|
16
|
+
*
|
|
17
|
+
* - `tie`: two or more kinds share the highest precedence. It is not read.
|
|
18
|
+
* - `module`: a `.tf` file under `<dir>` calls it through a local `source`
|
|
19
|
+
* (`./` or `../`) in a `module` block, so it is a module, read with the root
|
|
20
|
+
* that calls it.
|
|
21
|
+
* - `inside-member`: it sits inside another member's directory. Members don't
|
|
22
|
+
* nest (#2524 D2), except inside the root member `.`.
|
|
23
|
+
*
|
|
24
|
+
* Kinds come from the built-in kinds and from the `@intentius` packages that
|
|
25
|
+
* publish a `./workspace-kinds` file and are installed beside the running
|
|
26
|
+
* chant ({@link discoveryKinds}). A `node_modules` inside `<dir>` supplies
|
|
27
|
+
* none, so discovering a directory loads no package it carries.
|
|
28
|
+
*
|
|
29
|
+
* A member's name comes from its path relative to `<dir>`
|
|
30
|
+
* ({@link discoveredMemberNames}), so it stays the same across revisions.
|
|
31
|
+
*/
|
|
32
|
+
import { createHash } from "node:crypto";
|
|
33
|
+
import { lstatSync, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
34
|
+
import { basename, dirname, join, posix, relative, resolve } from "node:path";
|
|
35
|
+
import { CHANT_INSTALL, dataExportTarget } from "./class-data.js";
|
|
36
|
+
import { DECLARATION_FILES, isInside, WorkspaceReadError } from "./declaration.js";
|
|
37
|
+
import { createKindRegistry, KINDS_SUBPATH, readPackageKinds, resolveKind } from "./kinds.js";
|
|
38
|
+
import { gitTop, gitTree, joinPath, resolveCommit, skippedDir, workingTree } from "./tree.js";
|
|
39
|
+
/** Paths are kept with `/`, as a tree's are. */
|
|
40
|
+
const toPosix = (p) => p.split("\\").join("/");
|
|
41
|
+
/**
|
|
42
|
+
* Every `@intentius` package that publishes `./workspace-kinds`, found the way
|
|
43
|
+
* Node resolves a bare import from `from`: in `node_modules/@intentius` of
|
|
44
|
+
* `from` and each directory above it, the nearest copy of a name winning.
|
|
45
|
+
* Sorted by name.
|
|
46
|
+
*/
|
|
47
|
+
export function kindPackagesBeside(from = CHANT_INSTALL) {
|
|
48
|
+
const found = new Map();
|
|
49
|
+
for (let at = resolve(from);; at = dirname(at)) {
|
|
50
|
+
const scope = join(at, "node_modules", "@intentius");
|
|
51
|
+
let names = [];
|
|
52
|
+
try {
|
|
53
|
+
names = readdirSync(scope);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// No scope here.
|
|
57
|
+
}
|
|
58
|
+
for (const n of names.sort()) {
|
|
59
|
+
const dir = join(scope, n);
|
|
60
|
+
try {
|
|
61
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
62
|
+
if (typeof pkg.name !== "string" || typeof pkg.version !== "string" || found.has(pkg.name))
|
|
63
|
+
continue;
|
|
64
|
+
if (typeof dataExportTarget(pkg, KINDS_SUBPATH) !== "string")
|
|
65
|
+
continue;
|
|
66
|
+
found.set(pkg.name, { package: pkg.name, version: pkg.version, dir });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Not a package, or not readable: it supplies nothing.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (dirname(at) === at)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return [...found.values()].sort((a, b) => (a.package < b.package ? -1 : 1));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The registry a discovery reads with: the built-in kinds and every kind the
|
|
79
|
+
* packages beside the running chant supply. A name two packages both supply
|
|
80
|
+
* is left out, as `loadKindRegistry` leaves it out. Never throws.
|
|
81
|
+
*/
|
|
82
|
+
export function discoveryKinds(from = CHANT_INSTALL) {
|
|
83
|
+
const packages = kindPackagesBeside(from);
|
|
84
|
+
const problems = [];
|
|
85
|
+
const owner = new Map();
|
|
86
|
+
const clashing = new Set();
|
|
87
|
+
const extra = [];
|
|
88
|
+
for (const p of packages) {
|
|
89
|
+
const read = readPackageKinds(p.dir, p.package);
|
|
90
|
+
problems.push(...read.problems);
|
|
91
|
+
for (const k of read.kinds) {
|
|
92
|
+
const first = owner.get(k.name);
|
|
93
|
+
if (first) {
|
|
94
|
+
clashing.add(k.name);
|
|
95
|
+
problems.push(`kind ${k.name} is supplied by both ${first} and ${p.package}; a kind name has one source`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
owner.set(k.name, p.package);
|
|
99
|
+
extra.push(k);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { registry: createKindRegistry(extra.filter((k) => !clashing.has(k.name))), packages, problems };
|
|
103
|
+
}
|
|
104
|
+
/** Text with HCL comments removed and string contents kept, so a brace in a comment doesn't count. */
|
|
105
|
+
function withoutComments(text) {
|
|
106
|
+
let out = "";
|
|
107
|
+
for (let i = 0; i < text.length; i++) {
|
|
108
|
+
const c = text[i];
|
|
109
|
+
if (c === '"') {
|
|
110
|
+
const start = i;
|
|
111
|
+
for (i++; i < text.length && text[i] !== '"' && text[i] !== "\n"; i++)
|
|
112
|
+
if (text[i] === "\\")
|
|
113
|
+
i++;
|
|
114
|
+
out += text.slice(start, i + 1);
|
|
115
|
+
}
|
|
116
|
+
else if (c === "#" || (c === "/" && text[i + 1] === "/")) {
|
|
117
|
+
while (i < text.length && text[i] !== "\n")
|
|
118
|
+
i++;
|
|
119
|
+
out += "\n";
|
|
120
|
+
}
|
|
121
|
+
else if (c === "/" && text[i + 1] === "*") {
|
|
122
|
+
const end = text.indexOf("*/", i + 2);
|
|
123
|
+
i = end < 0 ? text.length : end + 1;
|
|
124
|
+
out += " ";
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
out += c;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The local `source` of every `module` block in HCL `text`: the ones that
|
|
134
|
+
* start with `./` or `../`, as written. A registry or git source is not
|
|
135
|
+
* local. HCL is not parsed: a `module "<name>" {` opener is found, its body
|
|
136
|
+
* runs to the matching brace, and `source = "<path>"` is read at the body's
|
|
137
|
+
* own level.
|
|
138
|
+
*/
|
|
139
|
+
export function localModuleSources(text) {
|
|
140
|
+
const src = withoutComments(text);
|
|
141
|
+
const out = [];
|
|
142
|
+
const opener = /(^|\n)\s*module\s+"[^"\n]*"\s*\{/g;
|
|
143
|
+
for (let m = opener.exec(src); m; m = opener.exec(src)) {
|
|
144
|
+
let depth = 1;
|
|
145
|
+
let i = m.index + m[0].length;
|
|
146
|
+
let body = "";
|
|
147
|
+
for (; i < src.length && depth > 0; i++) {
|
|
148
|
+
const c = src[i];
|
|
149
|
+
if (c === '"') {
|
|
150
|
+
const start = i;
|
|
151
|
+
for (i++; i < src.length && src[i] !== '"' && src[i] !== "\n"; i++)
|
|
152
|
+
if (src[i] === "\\")
|
|
153
|
+
i++;
|
|
154
|
+
if (depth === 1)
|
|
155
|
+
body += src.slice(start, i + 1);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (c === "{")
|
|
159
|
+
depth++;
|
|
160
|
+
else if (c === "}")
|
|
161
|
+
depth--;
|
|
162
|
+
if (depth === 1 && c !== "}")
|
|
163
|
+
body += c;
|
|
164
|
+
}
|
|
165
|
+
const source = /(?:^|\n)\s*source\s*=\s*"([^"\n]*)"/.exec(body)?.[1];
|
|
166
|
+
if (source && (source.startsWith("./") || source.startsWith("../")))
|
|
167
|
+
out.push(source);
|
|
168
|
+
opener.lastIndex = i;
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
/** Lowercase letters, digits and hyphens, as a member name allows. */
|
|
173
|
+
function nameOf(dir) {
|
|
174
|
+
return (dir
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
177
|
+
.replace(/^-+|-+$/g, "") || "member");
|
|
178
|
+
}
|
|
179
|
+
const NAME_MAX = 40;
|
|
180
|
+
function hashed(dir, base, length = 6) {
|
|
181
|
+
const digest = createHash("sha256").update(dir).digest("hex").slice(0, length);
|
|
182
|
+
return `${base.slice(0, NAME_MAX - length - 1).replace(/-+$/, "")}-${digest}`;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A member name for each directory, from its path relative to `<dir>`. Every
|
|
186
|
+
* run of characters a name can't hold, `/` among them, becomes one `-`, and
|
|
187
|
+
* letters are lowercased: `infra/net` is `infra-net`. `.` is `root`. A name
|
|
188
|
+
* longer than 40 characters, or one that two directories would share, keeps
|
|
189
|
+
* its first characters and ends in `-` and six hex digits of the SHA-256 of
|
|
190
|
+
* the path, so it still depends on the path alone.
|
|
191
|
+
*/
|
|
192
|
+
export function discoveredMemberNames(dirs) {
|
|
193
|
+
const plain = new Map(dirs.map((d) => [d, d === "." ? "root" : nameOf(d)]));
|
|
194
|
+
const count = new Map();
|
|
195
|
+
for (const n of plain.values())
|
|
196
|
+
count.set(n, (count.get(n) ?? 0) + 1);
|
|
197
|
+
const out = new Map();
|
|
198
|
+
const taken = new Set();
|
|
199
|
+
for (const d of dirs) {
|
|
200
|
+
const n = plain.get(d);
|
|
201
|
+
let name = n.length > NAME_MAX || count.get(n) > 1 ? hashed(d, n) : n;
|
|
202
|
+
// Two paths whose digests share a prefix: take more of the digest.
|
|
203
|
+
for (let length = 7; taken.has(name) && length <= 16; length++)
|
|
204
|
+
name = hashed(d, n, length);
|
|
205
|
+
taken.add(name);
|
|
206
|
+
out.set(d, name);
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
const claimOf = (k) => ({ kind: k.name, precedence: k.precedence, source: k.source });
|
|
211
|
+
/** The parts of a probe its kinds file states, without what chant adds. */
|
|
212
|
+
function probeOf(k) {
|
|
213
|
+
return structuredClone(k.probe);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Walk `tree` and work out the members a declaration for it would list, the
|
|
217
|
+
* `discovered` entries, and the declaration itself. `name` is the workspace's
|
|
218
|
+
* name. `runsOn` sets a discovered member's `runsOn` field by member name
|
|
219
|
+
* (#5101), as `--runs-on` does. Reads the tree only.
|
|
220
|
+
*/
|
|
221
|
+
export function discover(tree, kinds, name, runsOn = {}) {
|
|
222
|
+
const claimed = [];
|
|
223
|
+
const modules = new Map();
|
|
224
|
+
const walk = (dir) => {
|
|
225
|
+
const entries = tree.list(dir) ?? [];
|
|
226
|
+
// The root's own declaration would make it a nested workspace of itself; a declared root never gets here, but --at may hold one below.
|
|
227
|
+
const r = resolveKind(kinds.registry, tree, dir, dir === "" ? ["workspace"] : []);
|
|
228
|
+
if (r.claims.length > 0)
|
|
229
|
+
claimed.push({ dir, claims: r.claims, winner: r.winner });
|
|
230
|
+
for (const e of entries) {
|
|
231
|
+
if (e.type !== "file" || !e.name.endsWith(".tf"))
|
|
232
|
+
continue;
|
|
233
|
+
let text;
|
|
234
|
+
try {
|
|
235
|
+
text = tree.read(joinPath(dir, e.name));
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
for (const source of localModuleSources(text)) {
|
|
241
|
+
const target = posix.normalize(posix.join(dir || ".", source)).replace(/\/+$/, "");
|
|
242
|
+
if (target === ".." || target.startsWith("../"))
|
|
243
|
+
continue;
|
|
244
|
+
const key = target === "." ? "" : target;
|
|
245
|
+
if (key === dir)
|
|
246
|
+
continue;
|
|
247
|
+
const callers = modules.get(key) ?? new Set();
|
|
248
|
+
callers.add(dir || ".");
|
|
249
|
+
modules.set(key, callers);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
for (const e of entries.sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
253
|
+
if (e.type === "dir" && !skippedDir(e.name))
|
|
254
|
+
walk(joinPath(dir, e.name));
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
walk("");
|
|
258
|
+
claimed.sort((a, b) => (a.dir < b.dir ? -1 : a.dir > b.dir ? 1 : 0));
|
|
259
|
+
const shown = (d) => d || ".";
|
|
260
|
+
const entries = [];
|
|
261
|
+
const memberDirs = [];
|
|
262
|
+
for (const c of claimed) {
|
|
263
|
+
const base = {
|
|
264
|
+
dir: shown(c.dir),
|
|
265
|
+
member: null,
|
|
266
|
+
kind: c.winner?.name ?? null,
|
|
267
|
+
source: c.winner?.source ?? null,
|
|
268
|
+
probe: c.winner ? probeOf(c.winner) : null,
|
|
269
|
+
claims: c.claims.map(claimOf),
|
|
270
|
+
};
|
|
271
|
+
const callers = modules.get(c.dir);
|
|
272
|
+
if (callers) {
|
|
273
|
+
entries.push({ ...base, outcome: "module", note: `called as a module through a local source by ${[...callers].sort().join(", ")}` });
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (!c.winner) {
|
|
277
|
+
const tied = c.claims.filter((k) => k.precedence === c.claims[0].precedence);
|
|
278
|
+
entries.push({ ...base, outcome: "tie", note: `kinds ${tied.map((k) => k.name).join(" and ")} claim it at precedence ${tied[0].precedence}; name its kind in a declaration to read it` });
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const outer = memberDirs.find((m) => m !== "" && isInside(c.dir, m));
|
|
282
|
+
if (outer !== undefined) {
|
|
283
|
+
entries.push({ ...base, outcome: "inside-member", note: `inside member directory ${outer}; members don't nest, except inside the root member .` });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
memberDirs.push(c.dir);
|
|
287
|
+
entries.push({ ...base, outcome: "member", note: null });
|
|
288
|
+
}
|
|
289
|
+
const names = discoveredMemberNames(memberDirs.map(shown));
|
|
290
|
+
for (const e of entries)
|
|
291
|
+
if (e.outcome === "member")
|
|
292
|
+
e.member = names.get(e.dir);
|
|
293
|
+
const known = [...names.values()].sort();
|
|
294
|
+
const unknown = Object.keys(runsOn).filter((m) => !known.includes(m));
|
|
295
|
+
if (unknown.length > 0) {
|
|
296
|
+
throw new WorkspaceReadError("declaration-invalid", `--runs-on names ${unknown.map((m) => JSON.stringify(m)).join(", ")}, which is not a discovered member${known.length > 0 ? ` (the members are ${known.join(", ")})` : ""}`);
|
|
297
|
+
}
|
|
298
|
+
const members = entries.filter((e) => e.outcome === "member").map((e) => ({ name: e.member, dir: e.dir, kind: e.kind, ...(runsOn[e.member] !== undefined ? { runsOn: runsOn[e.member] } : {}) }));
|
|
299
|
+
const used = new Set(entries.filter((e) => e.outcome === "member").map((e) => e.source));
|
|
300
|
+
const pins = kinds.packages.filter((p) => used.has(p.package)).map((p) => ({ package: p.package, version: p.version }));
|
|
301
|
+
const declaration = { name, schema: 1, ...(pins.length > 0 ? { pins } : {}), members };
|
|
302
|
+
return { declaration: `${JSON.stringify(declaration, null, 2)}\n`, entries };
|
|
303
|
+
}
|
|
304
|
+
/** The file the in-memory declaration is shown as. */
|
|
305
|
+
export const DISCOVERED_DECLARATION = DECLARATION_FILES[0];
|
|
306
|
+
/**
|
|
307
|
+
* `base` with the in-memory declaration shown as `chant.workspace.json` at
|
|
308
|
+
* its root. Every other path reads through to `base`. Nothing is written.
|
|
309
|
+
*/
|
|
310
|
+
export function discoveredTree(base, declaration) {
|
|
311
|
+
const file = DISCOVERED_DECLARATION;
|
|
312
|
+
return {
|
|
313
|
+
label: base.label,
|
|
314
|
+
stat: (path) => (path === file ? "file" : base.stat(path)),
|
|
315
|
+
list: (path) => {
|
|
316
|
+
const entries = base.list(path);
|
|
317
|
+
if (path !== "" || !entries)
|
|
318
|
+
return entries;
|
|
319
|
+
return [...entries.filter((e) => e.name !== file), { name: file, type: "file" }];
|
|
320
|
+
},
|
|
321
|
+
read: (path) => (path === file ? declaration : base.read(path)),
|
|
322
|
+
bytes: (path) => (path === file ? new TextEncoder().encode(declaration) : base.bytes ? base.bytes(path) : new TextEncoder().encode(base.read(path))),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/** Whether `tree` holds a declaration at its root. */
|
|
326
|
+
export function declares(tree) {
|
|
327
|
+
return DECLARATION_FILES.some((f) => tree.stat(f) === "file");
|
|
328
|
+
}
|
|
329
|
+
/** The workspace name a discovered read gives `dir`: its base name, made a valid name. */
|
|
330
|
+
export function discoveredWorkspaceName(dir) {
|
|
331
|
+
return nameOf(basename(dir)).slice(0, NAME_MAX).replace(/-+$/, "") || "workspace";
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* The working tree under `root` without the symbolic links to directories, so
|
|
335
|
+
* the walk stays inside `root` and can't go round a loop. A link to a file is
|
|
336
|
+
* kept.
|
|
337
|
+
*/
|
|
338
|
+
function withoutDirLinks(tree, root) {
|
|
339
|
+
return {
|
|
340
|
+
...tree,
|
|
341
|
+
list: (path) => tree.list(path)?.filter((e) => {
|
|
342
|
+
if (e.type !== "dir")
|
|
343
|
+
return true;
|
|
344
|
+
try {
|
|
345
|
+
return !lstatSync(join(root, ...joinPath(path, e.name).split("/"))).isSymbolicLink();
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Where a discovered read of `dir` reads: the working tree, or for `at` the
|
|
355
|
+
* commit's tree under `dir`, before the declaration is laid over it. Throws
|
|
356
|
+
* a {@link WorkspaceReadError}: for `at`, `not-a-git-repository` and
|
|
357
|
+
* `revision-unknown`.
|
|
358
|
+
*/
|
|
359
|
+
export function locateDiscovered(dir, at) {
|
|
360
|
+
const rootOnDisk = resolve(dir);
|
|
361
|
+
const top = gitTop(rootOnDisk);
|
|
362
|
+
const rel = top ? toPosix(relative(top, realpathSync(rootOnDisk))) : undefined;
|
|
363
|
+
const root = rel === undefined || rel.startsWith("..") ? rootOnDisk : rel === "" ? "." : rel;
|
|
364
|
+
if (at === undefined)
|
|
365
|
+
return { base: withoutDirLinks(workingTree(rootOnDisk), rootOnDisk), root, rootOnDisk, at: null, top };
|
|
366
|
+
if (!top)
|
|
367
|
+
throw new WorkspaceReadError("not-a-git-repository", "--at reads git objects, and this directory is not in a git repository");
|
|
368
|
+
const commit = resolveCommit(top, at);
|
|
369
|
+
if (!commit)
|
|
370
|
+
throw new WorkspaceReadError("revision-unknown", `--at ${at} names no commit in this repository`);
|
|
371
|
+
return { base: gitTree(top, commit, root === "." ? "" : root), root, rootOnDisk, at: commit, top };
|
|
372
|
+
}
|
|
@@ -29,6 +29,7 @@ import { type WorkspaceGraph } from "./compose-graph.js";
|
|
|
29
29
|
import { type Declaration, type ErrorLocation } from "./declaration.js";
|
|
30
30
|
import { type MemberArgv, type MemberPlan, type Toolchain, type UnitResult } from "./member-commands.js";
|
|
31
31
|
import { type KindRegistry } from "./kinds.js";
|
|
32
|
+
import { type DiscoveredEntry } from "./discover.js";
|
|
32
33
|
import { type LocatedWorkspace } from "./which-chant.js";
|
|
33
34
|
/** The version of the `graph` document this chant writes. */
|
|
34
35
|
export declare const GRAPH_CONTRACT_VERSION = 1;
|
|
@@ -50,6 +51,7 @@ interface Head {
|
|
|
50
51
|
export type GraphDocument = (Head & {
|
|
51
52
|
at: string | null;
|
|
52
53
|
plantable: Plantable;
|
|
54
|
+
discovered?: DiscoveredEntry[];
|
|
53
55
|
} & WorkspaceGraph) | (Head & {
|
|
54
56
|
error: {
|
|
55
57
|
code: GraphErrorCode;
|
|
@@ -94,6 +96,20 @@ export interface GraphQuery {
|
|
|
94
96
|
}[]) => Promise<void>;
|
|
95
97
|
/** Read every member, leaving the per-member cache unread and unwritten (`--no-cache`, #2876). */
|
|
96
98
|
noCache?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Read `cwd` with no declaration (#5095): the kinds' probes find the
|
|
101
|
+
* members, as `discover.ts` describes, and nothing is written inside it.
|
|
102
|
+
* When `cwd` holds a declaration itself, that declaration is read instead.
|
|
103
|
+
*/
|
|
104
|
+
discover?: boolean;
|
|
105
|
+
/** With `discover`: the cluster resource a discovered member runs on, by member name (#5101), as a declaration's `runsOn`. */
|
|
106
|
+
runsOn?: Record<string, string>;
|
|
107
|
+
/**
|
|
108
|
+
* Run the lexicons' reference catalogs over the composed graph (#5097,
|
|
109
|
+
* `./catalog-edges.ts`). A source read only: with `--live` each member's
|
|
110
|
+
* own chant has run its catalog already. `chant workspace graph` sets it.
|
|
111
|
+
*/
|
|
112
|
+
catalog?: boolean;
|
|
97
113
|
}
|
|
98
114
|
export interface GraphResult {
|
|
99
115
|
doc: GraphDocument;
|
|
@@ -127,6 +143,8 @@ export interface MemberReads {
|
|
|
127
143
|
stamps: ReadonlyMap<string, string>;
|
|
128
144
|
/** With {@link GraphQuery.components}: each member's component graph run. */
|
|
129
145
|
components?: UnitResult[];
|
|
146
|
+
/** For a discovered read (#5095), every directory a kind claims. */
|
|
147
|
+
discovered?: DiscoveredEntry[];
|
|
130
148
|
}
|
|
131
149
|
export interface MemberReadOptions {
|
|
132
150
|
/** The command line each member runs; `chant graph --format ir` and the verb's flags by default. */
|
|
@@ -150,6 +168,8 @@ export interface MemberReadOptions {
|
|
|
150
168
|
export declare function readMembers(query: GraphQuery, options: MemberReadOptions): Promise<MemberReads>;
|
|
151
169
|
/** Read and compose the graph, and build the document. Never throws a {@link WorkspaceReadError}. */
|
|
152
170
|
export declare function workspaceGraph(query: GraphQuery): Promise<GraphResult>;
|
|
171
|
+
/** A repository URL with its scheme, credentials, `.git` and case taken off, so two spellings of one repository compare equal. */
|
|
172
|
+
export declare function repoKey(url: string): string;
|
|
153
173
|
export declare function runWorkspaceGraph(ctx: CommandContext): Promise<number>;
|
|
154
174
|
export {};
|
|
155
175
|
//# sourceMappingURL=graph-cli.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-cli.d.ts","sourceRoot":"","sources":["../../src/workspace/graph-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AASH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAA2F,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-cli.d.ts","sourceRoot":"","sources":["../../src/workspace/graph-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AASH,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,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