@miadi/relational-git-repository-mapper 0.5.1 → 0.6.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 +33 -3
- package/dist/capabilities.d.ts +2 -102
- package/dist/capabilities.js +20 -248
- package/dist/cli.js +8 -4
- package/dist/commit.d.ts +67 -0
- package/dist/commit.js +209 -0
- package/dist/impact.d.ts +2 -89
- package/dist/impact.js +8 -167
- package/dist/index.d.ts +4 -3
- package/dist/index.js +13 -2
- package/dist/join.d.ts +28 -1
- package/dist/join.js +69 -10
- package/dist/lineage.d.ts +4 -4
- package/dist/read.d.ts +20 -3
- package/dist/read.js +38 -5
- package/dist/scan.d.ts +2 -19
- package/dist/scan.js +7 -80
- package/dist/shipped-capabilities.js +1081 -826
- package/dist/types.d.ts +3 -1
- package/package.json +4 -4
package/dist/join.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// The join, pure: inventory records grouped by the repository they name, and a
|
|
3
|
-
// repository's mapping rows beside its sessions. The
|
|
4
|
-
// `repo` (owner/name)
|
|
3
|
+
// repository's mapping rows beside its sessions. The keys are the record's
|
|
4
|
+
// `repo` (owner/name) and the repository of each commit its `links.trace`
|
|
5
|
+
// names (owner/name@sha), case-folded, matched to repository:<owner>/<name>:
|
|
5
6
|
// GitHub names are case-insensitive, and records write them as they found them.
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
exports.dayOf = dayOf;
|
|
@@ -9,7 +10,11 @@ exports.teamOf = teamOf;
|
|
|
9
10
|
exports.dispositionOf = dispositionOf;
|
|
10
11
|
exports.sessionOf = sessionOf;
|
|
11
12
|
exports.repositoryKey = repositoryKey;
|
|
13
|
+
exports.parseTraceRef = parseTraceRef;
|
|
14
|
+
exports.repositoriesOfRecord = repositoriesOfRecord;
|
|
12
15
|
exports.sessionsByRepository = sessionsByRepository;
|
|
16
|
+
exports.capabilityKey = capabilityKey;
|
|
17
|
+
exports.capabilitySessions = capabilitySessions;
|
|
13
18
|
exports.repositoryView = repositoryView;
|
|
14
19
|
exports.listRepositories = listRepositories;
|
|
15
20
|
const developer_repository_mapping_1 = require("@medicine-wheel/developer-repository-mapping");
|
|
@@ -33,7 +38,7 @@ function dispositionOf(snapshot) {
|
|
|
33
38
|
const decided = text(d?.decided);
|
|
34
39
|
return proposed || decided ? { ...(proposed ? { proposed } : {}), ...(decided ? { decided } : {}) } : undefined;
|
|
35
40
|
}
|
|
36
|
-
function sessionOf(sessionId, snapshot) {
|
|
41
|
+
function sessionOf(sessionId, snapshot, commits = []) {
|
|
37
42
|
const team = teamOf(snapshot);
|
|
38
43
|
const disposition = dispositionOf(snapshot);
|
|
39
44
|
const date = dayOf(snapshot.date);
|
|
@@ -52,6 +57,7 @@ function sessionOf(sessionId, snapshot) {
|
|
|
52
57
|
...(disposition ? { disposition } : {}),
|
|
53
58
|
...(snapshot.evidence?.length ? { evidence: snapshot.evidence } : {}),
|
|
54
59
|
...(episode ? { episode } : {}),
|
|
60
|
+
...(commits.length ? { commits: [...commits] } : {}),
|
|
55
61
|
modified_at: snapshot.modified_at,
|
|
56
62
|
};
|
|
57
63
|
}
|
|
@@ -60,27 +66,80 @@ function repositoryKey(repo) {
|
|
|
60
66
|
const id = repo ? (0, developer_repository_mapping_1.toRepositoryNodeId)(repo.trim().replace(/\.git$/, "")) : undefined;
|
|
61
67
|
return id ? id.slice("repository:".length).toLowerCase() : undefined;
|
|
62
68
|
}
|
|
69
|
+
/** One `links.trace` ref, `owner/name@sha`: its repository as written and the commit. Undefined for any other ref. */
|
|
70
|
+
function parseTraceRef(ref) {
|
|
71
|
+
const m = /^([^\s@]+)@([0-9a-f]{4,40})$/i.exec(ref.trim());
|
|
72
|
+
const key = m ? repositoryKey(m[1]) : undefined;
|
|
73
|
+
return m && key ? { repository: m[1].replace(/\.git$/, ""), key, sha: m[2].toLowerCase() } : undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The repositories a record names, case-folded, each with the commits its
|
|
77
|
+
* `links.trace` holds there: its `repo` first (with no commit when the trace
|
|
78
|
+
* names none in it), then every other repository the trace names.
|
|
79
|
+
*/
|
|
80
|
+
function repositoriesOfRecord(snapshot) {
|
|
81
|
+
const out = new Map();
|
|
82
|
+
const own = repositoryKey(snapshot.repo);
|
|
83
|
+
if (own)
|
|
84
|
+
out.set(own, { spelled: snapshot.repo.trim().replace(/\.git$/, ""), commits: [] });
|
|
85
|
+
for (const ref of snapshot.trace ?? []) {
|
|
86
|
+
const t = parseTraceRef(ref);
|
|
87
|
+
if (!t)
|
|
88
|
+
continue;
|
|
89
|
+
const known = out.get(t.key) ?? { spelled: t.repository, commits: [] };
|
|
90
|
+
if (!known.commits.includes(t.sha))
|
|
91
|
+
known.commits.push(t.sha);
|
|
92
|
+
out.set(t.key, known);
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
63
96
|
const newestFirst = (a, b) => (b.date ?? "").localeCompare(a.date ?? "") || b.modified_at.localeCompare(a.modified_at);
|
|
64
97
|
function sessionsByRepository(records) {
|
|
65
98
|
const sessions = new Map();
|
|
66
99
|
const spelled = new Map();
|
|
67
100
|
let withoutRepo = 0;
|
|
68
101
|
for (const [id, snapshot] of records) {
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
102
|
+
const repositories = repositoriesOfRecord(snapshot);
|
|
103
|
+
if (!repositories.size) {
|
|
71
104
|
withoutRepo += 1;
|
|
72
105
|
continue;
|
|
73
106
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
spelled.
|
|
107
|
+
for (const [key, { spelled: name, commits }] of repositories) {
|
|
108
|
+
const list = sessions.get(key) ?? [];
|
|
109
|
+
list.push(sessionOf(id, snapshot, commits));
|
|
110
|
+
sessions.set(key, list);
|
|
111
|
+
if (!spelled.has(key))
|
|
112
|
+
spelled.set(key, name);
|
|
113
|
+
}
|
|
79
114
|
}
|
|
80
115
|
for (const list of sessions.values())
|
|
81
116
|
list.sort(newestFirst);
|
|
82
117
|
return { sessions, spelled, records: records.size, withoutRepo };
|
|
83
118
|
}
|
|
119
|
+
/** A capability address without its scheme, owner and repository case-folded: `miadi-capability:` and `miadi-capability://` read the same. */
|
|
120
|
+
function capabilityKey(address) {
|
|
121
|
+
const m = /^miadi-capability:(?:\/\/)?([^/\s]+)\/([^/\s]+)\/(package|cli|skill)\/(.+)$/.exec(address.trim());
|
|
122
|
+
return m ? `${m[1].toLowerCase()}/${m[2].toLowerCase()}/${m[3]}/${m[4]}` : undefined;
|
|
123
|
+
}
|
|
124
|
+
/** The sessions whose record's `capabilities[]` names this capability, newest first. */
|
|
125
|
+
function capabilitySessions(address, records) {
|
|
126
|
+
const key = capabilityKey(address);
|
|
127
|
+
if (!key)
|
|
128
|
+
return [];
|
|
129
|
+
const out = [];
|
|
130
|
+
for (const [id, snapshot] of records) {
|
|
131
|
+
const entry = (snapshot.capabilities ?? []).find((c) => capabilityKey(c.capability) === key);
|
|
132
|
+
if (!entry)
|
|
133
|
+
continue;
|
|
134
|
+
out.push({
|
|
135
|
+
...sessionOf(id, snapshot),
|
|
136
|
+
...(entry.relation ? { relation: entry.relation } : {}),
|
|
137
|
+
...(entry.version ? { version: entry.version } : {}),
|
|
138
|
+
...(entry.evidence?.length ? { capability_evidence: entry.evidence } : {}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return out.sort(newestFirst);
|
|
142
|
+
}
|
|
84
143
|
const keyOfNode = (nodeId) => nodeId.slice("repository:".length).toLowerCase();
|
|
85
144
|
/**
|
|
86
145
|
* One repository: its rows when a hub holds them, its sessions, and its
|
package/dist/lineage.d.ts
CHANGED
|
@@ -15,46 +15,46 @@ export declare const LineageRowSchema: z.ZodEffects<z.ZodObject<{
|
|
|
15
15
|
/** what was learned, at most 55 words */
|
|
16
16
|
description: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
17
17
|
}, "strict", z.ZodTypeAny, {
|
|
18
|
-
revision: "pending" | "revised" | "affirmed";
|
|
19
18
|
type: "learned-from";
|
|
20
19
|
from: string;
|
|
21
20
|
to: string;
|
|
22
21
|
statedBy: string;
|
|
23
22
|
statedAt: string;
|
|
24
23
|
grounding: string[];
|
|
24
|
+
revision: "pending" | "revised" | "affirmed";
|
|
25
25
|
description?: string | undefined;
|
|
26
26
|
revisedBy?: string | undefined;
|
|
27
27
|
revisedAt?: string | undefined;
|
|
28
28
|
}, {
|
|
29
|
-
revision: "pending" | "revised" | "affirmed";
|
|
30
29
|
type: "learned-from";
|
|
31
30
|
from: string;
|
|
32
31
|
to: string;
|
|
33
32
|
statedBy: string;
|
|
34
33
|
statedAt: string;
|
|
35
34
|
grounding: string[];
|
|
35
|
+
revision: "pending" | "revised" | "affirmed";
|
|
36
36
|
description?: string | undefined;
|
|
37
37
|
revisedBy?: string | undefined;
|
|
38
38
|
revisedAt?: string | undefined;
|
|
39
39
|
}>, {
|
|
40
|
-
revision: "pending" | "revised" | "affirmed";
|
|
41
40
|
type: "learned-from";
|
|
42
41
|
from: string;
|
|
43
42
|
to: string;
|
|
44
43
|
statedBy: string;
|
|
45
44
|
statedAt: string;
|
|
46
45
|
grounding: string[];
|
|
46
|
+
revision: "pending" | "revised" | "affirmed";
|
|
47
47
|
description?: string | undefined;
|
|
48
48
|
revisedBy?: string | undefined;
|
|
49
49
|
revisedAt?: string | undefined;
|
|
50
50
|
}, {
|
|
51
|
-
revision: "pending" | "revised" | "affirmed";
|
|
52
51
|
type: "learned-from";
|
|
53
52
|
from: string;
|
|
54
53
|
to: string;
|
|
55
54
|
statedBy: string;
|
|
56
55
|
statedAt: string;
|
|
57
56
|
grounding: string[];
|
|
57
|
+
revision: "pending" | "revised" | "affirmed";
|
|
58
58
|
description?: string | undefined;
|
|
59
59
|
revisedBy?: string | undefined;
|
|
60
60
|
revisedAt?: string | undefined;
|
package/dist/read.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type RepositoryWhere } from "./hosts";
|
|
|
4
4
|
import { type CapabilityFacet } from "@medicine-wheel/capabilities";
|
|
5
5
|
import { type CapabilityKind, type ProvidesEdge } from "./capabilities";
|
|
6
6
|
import { type MappingIssue, type MergedMapping } from "@medicine-wheel/developer-repository-mapping";
|
|
7
|
-
import { type SessionsByRepository } from "./join";
|
|
7
|
+
import { type CapabilitySession, type SessionsByRepository } from "./join";
|
|
8
8
|
import { type LineageEdge, type LineageGraph, type RepositoryLineage } from "./lineage";
|
|
9
9
|
import type { HubState, InventoryState, RepositoryListing, RepositoryView } from "./types";
|
|
10
10
|
type Env = Record<string, string | undefined>;
|
|
@@ -33,7 +33,7 @@ export interface WhereRead {
|
|
|
33
33
|
/** Where repositories live: a host's own readings first, then the readings this package ships. */
|
|
34
34
|
export declare function readWhere(path?: string | undefined): WhereRead;
|
|
35
35
|
/** The packages the shipped scan read, with their versions and first-party ranges. */
|
|
36
|
-
export declare function readPackages(): {
|
|
36
|
+
export declare function readPackages(file?: string | undefined): {
|
|
37
37
|
packages: PackageReading[];
|
|
38
38
|
issues: MappingIssue[];
|
|
39
39
|
};
|
|
@@ -76,6 +76,16 @@ export interface CapabilitiesAnswer {
|
|
|
76
76
|
}
|
|
77
77
|
/** "What does this repository provide?", or with no repository, every capability. Reads no hub and no inventory. */
|
|
78
78
|
export declare function repositoryCapabilities(repository?: string, options?: Pick<ReadOptions, "capabilities">): CapabilitiesAnswer;
|
|
79
|
+
/** A capability beside another one, with the address that opens it. */
|
|
80
|
+
export interface RelatedCapability {
|
|
81
|
+
relation: "consumes" | "consumed-by" | "ships" | "shipped-by";
|
|
82
|
+
kind: CapabilityKind;
|
|
83
|
+
name: string;
|
|
84
|
+
address: string;
|
|
85
|
+
version?: string;
|
|
86
|
+
/** for `consumes` and `consumed-by`: the range declared */
|
|
87
|
+
range?: string;
|
|
88
|
+
}
|
|
79
89
|
export interface CapabilityRecord {
|
|
80
90
|
/** the row, with its kind and the address a person cites it by */
|
|
81
91
|
capability: CapabilityFacet & {
|
|
@@ -86,7 +96,11 @@ export interface CapabilityRecord {
|
|
|
86
96
|
repository: string;
|
|
87
97
|
/** for a package: its version, the manifest and commit it was read at, and what it consumes and what consumes it */
|
|
88
98
|
impact?: ImpactAnswer;
|
|
99
|
+
/** the capabilities beside it: what a package consumes, what consumes it, the commands it ships, the package a command comes from */
|
|
100
|
+
related: RelatedCapability[];
|
|
89
101
|
scans: typeof SHIPPED_CAPABILITIES_SCANS;
|
|
102
|
+
/** with `sessions`: the sessions whose inventory record names it (used, revised, brought into being), newest first */
|
|
103
|
+
sessions?: CapabilitySession[];
|
|
90
104
|
}
|
|
91
105
|
/**
|
|
92
106
|
* The capability an address names (`miadi-capability:<owner>/<repo>/<kind>/<name>`):
|
|
@@ -98,7 +112,10 @@ export declare function findCapability(parts: {
|
|
|
98
112
|
repo: string;
|
|
99
113
|
kind: string;
|
|
100
114
|
name: string;
|
|
101
|
-
}, options?: Pick<ReadOptions, "capabilities">
|
|
115
|
+
}, options?: Pick<ReadOptions, "capabilities" | "inventory"> & {
|
|
116
|
+
/** read the session inventory for the sessions whose record names it: session data, for the write tier */
|
|
117
|
+
sessions?: boolean;
|
|
118
|
+
}): CapabilityRecord | undefined;
|
|
102
119
|
export interface LineageRead {
|
|
103
120
|
/** the files read, in precedence order */
|
|
104
121
|
from: string[];
|
package/dist/read.js
CHANGED
|
@@ -57,13 +57,27 @@ function readWhere(path = process.env.MIADI_REPOSITORY_HOSTS?.trim() || undefine
|
|
|
57
57
|
return { from: texts.map((t) => t.source), readings: parsed.readings, issues: [...unread, ...parsed.issues] };
|
|
58
58
|
}
|
|
59
59
|
/** The packages the shipped scan read, with their versions and first-party ranges. */
|
|
60
|
-
function readPackages() {
|
|
60
|
+
function readPackages(file = process.env.MIADI_REPOSITORY_PACKAGES) {
|
|
61
61
|
const packages = [];
|
|
62
62
|
const issues = [];
|
|
63
|
+
// A host's own reading first (`mw-repomap capabilities map --packages <file>`): the first to name a package speaks for it.
|
|
64
|
+
if (file) {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = (0, developer_repository_mapping_1.parseJsonl)((0, node_fs_1.readFileSync)(file, "utf8"), impact_1.PackageReadingSchema, file);
|
|
67
|
+
packages.push(...parsed.rows);
|
|
68
|
+
issues.push(...parsed.issues);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
issues.push({ severity: "error", file, message: `could not read: ${error.message}` });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const named = new Set(packages.map((p) => p.name));
|
|
63
75
|
shipped_capabilities_1.SHIPPED_PACKAGES.forEach((row, index) => {
|
|
64
76
|
const parsed = impact_1.PackageReadingSchema.safeParse(row);
|
|
65
|
-
if (parsed.success)
|
|
66
|
-
|
|
77
|
+
if (parsed.success) {
|
|
78
|
+
if (!named.has(parsed.data.name))
|
|
79
|
+
packages.push(parsed.data);
|
|
80
|
+
}
|
|
67
81
|
else
|
|
68
82
|
issues.push({ severity: "error", file: shipped_capabilities_1.SHIPPED_CAPABILITIES_SOURCE, line: index + 1, message: parsed.error.issues.map((i) => i.message).join("; ") });
|
|
69
83
|
});
|
|
@@ -145,12 +159,31 @@ function findCapability(parts, options = {}) {
|
|
|
145
159
|
const provider = c.providedBy.find((p) => p.toLowerCase() === repository);
|
|
146
160
|
if (!provider)
|
|
147
161
|
continue;
|
|
148
|
-
const
|
|
162
|
+
const { packages } = readPackages();
|
|
163
|
+
const impact = kind === "package" ? (0, impact_1.impactOf)(c.name, packages) : undefined;
|
|
164
|
+
const related = [];
|
|
165
|
+
const version = (v) => (v ? { version: v } : {});
|
|
166
|
+
if (impact) {
|
|
167
|
+
for (const l of impact.consumes)
|
|
168
|
+
related.push({ relation: "consumes", kind: "package", name: l.name, address: (0, capabilities_2.capabilityAddress)(l.repository, "package", l.name), ...version(l.version), range: l.range });
|
|
169
|
+
for (const l of impact.consumers.filter((x) => x.depth === 1))
|
|
170
|
+
related.push({ relation: "consumed-by", kind: "package", name: l.name, address: (0, capabilities_2.capabilityAddress)(l.repository, "package", l.name), ...version(l.version), range: l.range });
|
|
171
|
+
for (const bin of packages.find((p) => p.name === c.name)?.bins ?? [])
|
|
172
|
+
related.push({ relation: "ships", kind: "cli", name: bin, address: (0, capabilities_2.capabilityAddress)(provider, "cli", bin) });
|
|
173
|
+
}
|
|
174
|
+
if (kind === "cli") {
|
|
175
|
+
const shipper = packages.find((p) => p.repository.toLowerCase() === repository && p.bins?.includes(c.name));
|
|
176
|
+
if (shipper)
|
|
177
|
+
related.push({ relation: "shipped-by", kind: "package", name: shipper.name, address: (0, capabilities_2.capabilityAddress)(shipper.repository, "package", shipper.name), ...version(shipper.version) });
|
|
178
|
+
}
|
|
179
|
+
const address = (0, capabilities_2.capabilityAddress)(provider, kind, c.name);
|
|
149
180
|
return {
|
|
150
|
-
capability: { ...c, kind, address
|
|
181
|
+
capability: { ...c, kind, address },
|
|
151
182
|
repository: provider,
|
|
152
183
|
...(impact ? { impact } : {}),
|
|
184
|
+
related,
|
|
153
185
|
scans: read.scans,
|
|
186
|
+
...(options.sessions ? { sessions: (0, join_1.capabilitySessions)(address, (0, hooks_interpreter_1.readInventoryRecords)(options.inventory ?? inventoryDir())) } : {}),
|
|
154
187
|
};
|
|
155
188
|
}
|
|
156
189
|
return undefined;
|
package/dist/scan.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface ScanOptions {
|
|
4
|
-
/** the ref to read; default the remote's default branch (`origin/HEAD`), else HEAD */
|
|
5
|
-
ref?: string;
|
|
6
|
-
/** `owner/name` or `repository:owner/name`; default from the `origin` remote */
|
|
7
|
-
repository?: string;
|
|
8
|
-
observedBy: string;
|
|
9
|
-
now?: Date;
|
|
10
|
-
}
|
|
11
|
-
export interface ScanResult {
|
|
12
|
-
repository: string;
|
|
13
|
-
ref: string;
|
|
14
|
-
commit: string;
|
|
15
|
-
capabilities: CapabilityFacet[];
|
|
16
|
-
/** each package's version and the ranges it declares, all of them */
|
|
17
|
-
packages: PackageReading[];
|
|
18
|
-
}
|
|
19
|
-
export declare function scanRepository(clone: string, options: ScanOptions): Promise<ScanResult>;
|
|
1
|
+
export { readRepositoryCapabilities, scanRepository } from "@medicine-wheel/developer-repository-mapping/node";
|
|
2
|
+
export type { RepositoryCapabilities, ScanOptions, ScanResult } from "@medicine-wheel/developer-repository-mapping/node";
|
package/dist/scan.js
CHANGED
|
@@ -1,82 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// The scan
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// the commit it was read at. Read-only: git ls-tree, git show, git rev-parse.
|
|
2
|
+
// The scan on Node lives in @medicine-wheel/developer-repository-mapping/node
|
|
3
|
+
// (P20). `readRepositoryCapabilities` takes a repository's own
|
|
4
|
+
// .miadi/capabilities.jsonl first, and falls back to its files.
|
|
6
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.scanRepository =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const capabilities_1 = require("./capabilities");
|
|
12
|
-
const run = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
13
|
-
async function git(clone, args) {
|
|
14
|
-
try {
|
|
15
|
-
const { stdout } = await run("git", ["-C", clone, ...args], { maxBuffer: 256 * 1024 * 1024 });
|
|
16
|
-
return stdout;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async function scanRepository(clone, options) {
|
|
23
|
-
if ((await git(clone, ["rev-parse", "--git-dir"])) === undefined)
|
|
24
|
-
throw new Error(`not a git clone: ${clone}`);
|
|
25
|
-
const ref = options.ref ?? ((await git(clone, ["rev-parse", "--verify", "-q", "origin/HEAD"])) ? "origin/HEAD" : "HEAD");
|
|
26
|
-
const commit = (await git(clone, ["rev-parse", "--verify", `${ref}^{commit}`]))?.trim();
|
|
27
|
-
if (!commit)
|
|
28
|
-
throw new Error(`${clone}: no commit at ${ref}`);
|
|
29
|
-
let repository = options.repository
|
|
30
|
-
? options.repository.startsWith("repository:") ? options.repository : `repository:${options.repository}`
|
|
31
|
-
: undefined;
|
|
32
|
-
if (!repository) {
|
|
33
|
-
const remote = (0, developer_repository_mapping_1.parseGithubRemote)((await git(clone, ["remote", "get-url", "origin"]))?.trim() ?? "");
|
|
34
|
-
if (!remote)
|
|
35
|
-
throw new Error(`${clone}: origin is not on GitHub; pass --repository owner/name`);
|
|
36
|
-
repository = (0, developer_repository_mapping_1.repositoryNodeId)(remote.owner, remote.name);
|
|
37
|
-
}
|
|
38
|
-
const files = ((await git(clone, ["ls-tree", "-r", "--name-only", commit])) ?? "").split("\n").filter(Boolean);
|
|
39
|
-
const show = (path) => git(clone, ["show", `${commit}:${path}`]);
|
|
40
|
-
const globs = (0, capabilities_1.workspaceGlobs)(await show("package.json"), files.includes("pnpm-workspace.yaml") ? await show("pnpm-workspace.yaml") : undefined);
|
|
41
|
-
const artefacts = [];
|
|
42
|
-
const packages = [];
|
|
43
|
-
for (const manifest of (0, capabilities_1.packageManifests)(globs, files)) {
|
|
44
|
-
const pkg = (0, capabilities_1.parsePackageJson)((await show(manifest)) ?? "");
|
|
45
|
-
if (!pkg.name)
|
|
46
|
-
continue;
|
|
47
|
-
packages.push({
|
|
48
|
-
capability: (0, capabilities_1.capabilityId)("package", pkg.name),
|
|
49
|
-
name: pkg.name,
|
|
50
|
-
...(pkg.version ? { version: pkg.version } : {}),
|
|
51
|
-
repository,
|
|
52
|
-
path: manifest,
|
|
53
|
-
commit: commit.slice(0, 12),
|
|
54
|
-
dependsOn: pkg.dependsOn,
|
|
55
|
-
});
|
|
56
|
-
artefacts.push({ kind: "package", name: pkg.name, ...(pkg.description ? { description: pkg.description } : {}), path: manifest });
|
|
57
|
-
for (const bin of pkg.bins) {
|
|
58
|
-
artefacts.push({ kind: "cli", name: bin, description: `The ${bin} command, shipped by ${pkg.name}.`, path: manifest });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
for (const file of (0, capabilities_1.skillFiles)(files)) {
|
|
62
|
-
const front = (0, capabilities_1.parseSkillFrontMatter)((await show(file)) ?? "");
|
|
63
|
-
const name = front.name ?? file.split("/").slice(-2, -1)[0];
|
|
64
|
-
if (!name)
|
|
65
|
-
continue;
|
|
66
|
-
artefacts.push({ kind: "skill", name, ...(front.description ? { description: front.description } : {}), path: file });
|
|
67
|
-
}
|
|
68
|
-
// Capabilities defined in code, each by the reader written for its repository's file.
|
|
69
|
-
for (const reader of capabilities_1.CODE_READERS) {
|
|
70
|
-
if (reader.repository.toLowerCase() !== repository.toLowerCase() || !files.includes(reader.path))
|
|
71
|
-
continue;
|
|
72
|
-
artefacts.push(...reader.read((await show(reader.path)) ?? ""));
|
|
73
|
-
}
|
|
74
|
-
const observedAt = (options.now ?? new Date()).toISOString();
|
|
75
|
-
return {
|
|
76
|
-
repository,
|
|
77
|
-
ref,
|
|
78
|
-
commit,
|
|
79
|
-
capabilities: (0, capabilities_1.capabilityRows)(artefacts, { repository, commit, observedBy: options.observedBy, observedAt }),
|
|
80
|
-
packages,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
6
|
+
exports.scanRepository = exports.readRepositoryCapabilities = void 0;
|
|
7
|
+
var node_1 = require("@medicine-wheel/developer-repository-mapping/node");
|
|
8
|
+
Object.defineProperty(exports, "readRepositoryCapabilities", { enumerable: true, get: function () { return node_1.readRepositoryCapabilities; } });
|
|
9
|
+
Object.defineProperty(exports, "scanRepository", { enumerable: true, get: function () { return node_1.scanRepository; } });
|