@icebreakers/monorepo 5.6.0 → 5.7.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 +2 -0
- package/dist/baseline-DPfotf4y.mjs +146 -0
- package/dist/bundle-B9vRch4R.mjs +49 -0
- package/dist/catalog-CDEyc1uA.mjs +299 -0
- package/dist/cli.mjs +1487 -156
- package/dist/commands-TS8ABFdP.mjs +13820 -0
- package/dist/config-C38c_Q8L.mjs +66 -0
- package/dist/{create-flow-CXRhfGbb.mjs → create-flow-CCr2hfSY.mjs} +90 -24
- package/dist/deps-CUdI2DaB.mjs +47 -0
- package/dist/execute-PX1hT0qv.mjs +68 -0
- package/dist/execute-Vi4qHe-D.mjs +663 -0
- package/dist/format-DZ7L34rf.mjs +28 -0
- package/dist/index-CoCTFWZJ.d.mts +2150 -0
- package/dist/index.d.mts +1738 -112
- package/dist/index.mjs +60 -7
- package/dist/inputs-_xIVONmB.mjs +50 -0
- package/dist/npm-B25nrSyz.mjs +82 -0
- package/dist/plan-B5aE_WNF.mjs +75 -0
- package/dist/run-Lu7y1bNf.mjs +165 -0
- package/dist/save-CdCf630Z.mjs +79 -0
- package/dist/scan-4nboHNXP.mjs +293 -0
- package/dist/template-drift-BBhnrHY1.mjs +2740 -0
- package/dist/tooling-entry.d.mts +1 -1
- package/dist/tooling-entry.mjs +2 -2
- package/dist/transaction-DAhY8EpG.mjs +168 -0
- package/dist/tsconfig-CGntrzBM.mjs +1483 -0
- package/dist/{vitest-Blzbh8xZ.mjs → vitest-DkGh4Ygo.mjs} +1 -1
- package/dist/workspace-tasks-CnB8kkS0.mjs +4435 -0
- package/package.json +22 -4
- package/resources/api-report/runner.cjs +76 -0
- package/resources/devcontainer/setup.mjs +36 -0
- package/resources/knip/reporter.mjs +46 -0
- package/resources/maintenance/migration-lanes.mjs +141 -0
- package/resources/maintenance/migration-lock.mjs +119 -0
- package/resources/maintenance/migrations.mjs +215 -0
- package/resources/maintenance/presets.mjs +130 -0
- package/resources/maintenance/validate.mjs +233 -0
- package/resources/maintenance/workflow.yml +151 -0
- package/resources/skills/repoctl/SKILL.md +2 -0
- package/resources/skills/repoctl/references/commands.md +224 -13
- package/resources/skills/repoctl/references/config.md +70 -6
- package/resources/skills/repoctl/references/dependencies.md +37 -0
- package/resources/skills/repoctl/references/knip.md +34 -0
- package/resources/skills/repoctl/references/templates.md +23 -0
- package/dist/commands-D4xZQ5t-.mjs +0 -5685
- package/dist/config-p842Knhq.mjs +0 -114
- package/dist/index-Bl_PB2Ch.d.mts +0 -1039
- package/dist/tsconfig-BrjI_5yI.mjs +0 -75
- package/dist/types-MAUIQpfp.mjs +0 -499
- package/dist/workspace-MCKewElu.mjs +0 -123
package/README.md
CHANGED
|
@@ -34,3 +34,5 @@ This package retains the `repo` and `repoctl` bins for existing installations. N
|
|
|
34
34
|
- Documentation: https://repoctl.icebreaker.top
|
|
35
35
|
- Repository: https://github.com/icelib/repoctl/tree/main/packages/monorepo
|
|
36
36
|
- Issues: https://github.com/icelib/repoctl/issues
|
|
37
|
+
|
|
38
|
+
Doctor exposes `getDoctorRuleIds()`, `runDoctor(cwd, { rules, suppressions })`, `planDoctorFix(cwd, options)`, and `applyDoctorFixPlan(cwd, plan)`. Rule selection uses stable IDs; suppressions require a reason and can expire on an inclusive UTC date. Fix plans only add absent recommended root script keys, preserve existing values, reject changed inputs, and verify the result.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { at as record, rt as hash } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
2
|
+
import path from "pathe";
|
|
3
|
+
import { readFile, stat } from "node:fs/promises";
|
|
4
|
+
import { isDeepStrictEqual } from "node:util";
|
|
5
|
+
//#region src/commands/check/knip/native.ts
|
|
6
|
+
const marker = "__REPOCTL_KNIP_REPORT_V1__";
|
|
7
|
+
function findingFingerprint(finding) {
|
|
8
|
+
const members = Array.isArray(finding.native["symbols"]) ? finding.native["symbols"].map((member) => [
|
|
9
|
+
member.symbol,
|
|
10
|
+
member.kind ?? "",
|
|
11
|
+
member.specifier ?? ""
|
|
12
|
+
]).sort() : [];
|
|
13
|
+
return hash(JSON.stringify([
|
|
14
|
+
finding.type,
|
|
15
|
+
finding.severity,
|
|
16
|
+
finding.workspace,
|
|
17
|
+
finding.file,
|
|
18
|
+
finding.symbol,
|
|
19
|
+
finding.native["parentSymbol"] ?? "",
|
|
20
|
+
finding.native["specifier"] ?? "",
|
|
21
|
+
members
|
|
22
|
+
]));
|
|
23
|
+
}
|
|
24
|
+
function normalizeFinding(root, workspaces, value) {
|
|
25
|
+
const issue = record(value);
|
|
26
|
+
if (!issue || typeof issue["type"] !== "string" || !issue["type"] || !["warn", "error"].includes(String(issue["severity"])) || typeof issue["filePath"] !== "string" || typeof issue["symbol"] !== "string" || typeof issue["workspace"] !== "string") throw new Error("Knip returned an unsupported diagnostic shape.");
|
|
27
|
+
for (const key of [
|
|
28
|
+
"line",
|
|
29
|
+
"col",
|
|
30
|
+
"pos"
|
|
31
|
+
]) if (issue[key] !== void 0 && (!Number.isSafeInteger(issue[key]) || Number(issue[key]) < 0)) throw new Error("Knip returned an invalid source location.");
|
|
32
|
+
if (issue["symbols"] !== void 0 && (!Array.isArray(issue["symbols"]) || issue["symbols"].some((item) => !record(item) || typeof item.symbol !== "string"))) throw new Error("Knip returned invalid diagnostic members.");
|
|
33
|
+
const file = path.relative(root, path.resolve(root, issue["filePath"])) || ".";
|
|
34
|
+
const nativeWorkspace = path.isAbsolute(issue["workspace"]) ? path.relative(root, issue["workspace"]) || "." : issue["workspace"];
|
|
35
|
+
const workspace = workspaces.includes(nativeWorkspace) ? nativeWorkspace : [...workspaces].sort((a, b) => b.length - a.length).find((dir) => dir === "." || file === dir || file.startsWith(`${dir}/`)) ?? ".";
|
|
36
|
+
const hint = record(issue["hint"]);
|
|
37
|
+
const native = {
|
|
38
|
+
...issue,
|
|
39
|
+
filePath: file,
|
|
40
|
+
workspace: nativeWorkspace,
|
|
41
|
+
...hint && typeof hint["filePath"] === "string" ? { hint: {
|
|
42
|
+
...hint,
|
|
43
|
+
filePath: path.relative(root, path.resolve(root, hint["filePath"])) || "."
|
|
44
|
+
} } : {}
|
|
45
|
+
};
|
|
46
|
+
const finding = {
|
|
47
|
+
type: issue["type"],
|
|
48
|
+
severity: issue["severity"],
|
|
49
|
+
workspace,
|
|
50
|
+
file,
|
|
51
|
+
symbol: issue["symbol"],
|
|
52
|
+
...typeof issue["line"] === "number" ? { line: issue["line"] } : {},
|
|
53
|
+
...typeof issue["col"] === "number" ? { column: issue["col"] } : {},
|
|
54
|
+
native
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
fingerprint: findingFingerprint(finding),
|
|
58
|
+
...finding
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function parseKnipOutput(root, stdout) {
|
|
62
|
+
const lines = stdout.split(/\r?\n/);
|
|
63
|
+
const reports = lines.filter((line) => line.startsWith(marker));
|
|
64
|
+
if (reports.length !== 1) throw new Error("Knip did not emit exactly one complete repoctl reporter payload.");
|
|
65
|
+
const native = record(JSON.parse(reports[0].slice(26)));
|
|
66
|
+
const report = record(native?.["report"]);
|
|
67
|
+
const nativePlugins = record(native?.["plugins"]);
|
|
68
|
+
if (!native || native["schemaVersion"] !== 1 || native["kind"] !== "repoctl-knip-native" || typeof native["cwd"] !== "string" || path.resolve(native["cwd"]) !== root || typeof native["hasConfigLoadErrors"] !== "boolean" || !Array.isArray(native["findings"]) || !Array.isArray(native["workspaces"]) || native["workspaces"].some((item) => typeof item !== "string") || !report || Object.values(report).some((item) => typeof item !== "boolean") || !nativePlugins || Object.values(nativePlugins).some((item) => !Array.isArray(item) || item.some((name) => typeof name !== "string")) || native["configFilePath"] !== null && typeof native["configFilePath"] !== "string") throw new Error("Knip returned an incompatible reporter payload.");
|
|
69
|
+
if (native["hasConfigLoadErrors"]) throw new Error("Knip could not load all tool configurations; this analysis is incomplete.");
|
|
70
|
+
const workspaces = [...new Set(native["workspaces"].map((item) => path.relative(root, path.resolve(root, item)) || "."))].sort();
|
|
71
|
+
if (!workspaces.length) throw new Error("Knip reported no analyzed workspaces.");
|
|
72
|
+
const findings = native["findings"].map((item) => normalizeFinding(root, workspaces, item)).sort((a, b) => a.fingerprint.localeCompare(b.fingerprint));
|
|
73
|
+
if (new Set(findings.map((item) => item.fingerprint)).size !== findings.length) throw new Error("Knip returned duplicate diagnostic identities.");
|
|
74
|
+
return {
|
|
75
|
+
findings,
|
|
76
|
+
workspaces,
|
|
77
|
+
report,
|
|
78
|
+
plugins: Object.fromEntries(Object.entries(nativePlugins).map(([key, values]) => [path.isAbsolute(key) ? path.relative(root, key) || "." : key, [...values].sort()]).sort(([a], [b]) => String(a).localeCompare(String(b)))),
|
|
79
|
+
configFile: native["configFilePath"] === null ? null : path.relative(root, native["configFilePath"]),
|
|
80
|
+
output: lines.filter((line) => !line.startsWith(marker)).join("\n").trim()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function summarizeKnip(findings) {
|
|
84
|
+
const summary = {
|
|
85
|
+
errors: 0,
|
|
86
|
+
warnings: 0,
|
|
87
|
+
byType: {}
|
|
88
|
+
};
|
|
89
|
+
for (const finding of findings) {
|
|
90
|
+
const counts = summary.byType[finding.type] ??= {
|
|
91
|
+
errors: 0,
|
|
92
|
+
warnings: 0
|
|
93
|
+
};
|
|
94
|
+
const key = finding.severity === "error" ? "errors" : "warnings";
|
|
95
|
+
counts[key]++;
|
|
96
|
+
summary[key]++;
|
|
97
|
+
}
|
|
98
|
+
return summary;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/commands/check/knip/baseline.ts
|
|
102
|
+
function validateKnipBaseline(value) {
|
|
103
|
+
const baseline = record(value);
|
|
104
|
+
const scope = record(baseline?.["scope"]);
|
|
105
|
+
if (!baseline || baseline["schemaVersion"] !== 1 || baseline["kind"] !== "knip-baseline" || !scope || typeof scope["toolVersion"] !== "string" || scope["rootName"] !== null && typeof scope["rootName"] !== "string" || typeof scope["production"] !== "boolean" || typeof scope["strict"] !== "boolean" || !Array.isArray(scope["workspaces"]) || !scope["workspaces"].length || scope["workspaces"].some((item) => typeof item !== "string") || !Array.isArray(scope["configuration"]) || scope["configuration"].some((item) => !record(item) || typeof item.path !== "string" || typeof item.hash !== "string") || scope["configFile"] !== null && typeof scope["configFile"] !== "string" || !record(scope["report"]) || !record(scope["plugins"]) || !Array.isArray(baseline["findings"])) throw new Error("Invalid Knip baseline schema. Regenerate it explicitly after review.");
|
|
106
|
+
for (const item of baseline["findings"]) if (!record(item) || typeof item.fingerprint !== "string" || typeof item.type !== "string" || !["error", "warn"].includes(item.severity) || typeof item.workspace !== "string" || typeof item.file !== "string" || typeof item.symbol !== "string" || !record(item.native) || item.fingerprint !== findingFingerprint(item)) throw new Error("Invalid Knip baseline finding or fingerprint.");
|
|
107
|
+
if (new Set(baseline["findings"].map((item) => item.fingerprint)).size !== baseline["findings"].length) throw new Error("Knip baseline contains duplicate findings.");
|
|
108
|
+
return baseline;
|
|
109
|
+
}
|
|
110
|
+
async function readKnipBaseline(file) {
|
|
111
|
+
if ((await stat(file)).size > 33554432) throw new Error("Knip baseline exceeds 32 MiB.");
|
|
112
|
+
return validateKnipBaseline(JSON.parse(await readFile(file, "utf8")));
|
|
113
|
+
}
|
|
114
|
+
async function compareKnipBaseline(file, scope, findings) {
|
|
115
|
+
if (!file) return {
|
|
116
|
+
status: "none",
|
|
117
|
+
path: null,
|
|
118
|
+
existing: [],
|
|
119
|
+
added: [...findings],
|
|
120
|
+
fixed: []
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
const baseline = await readKnipBaseline(file);
|
|
124
|
+
if (!isDeepStrictEqual(baseline["scope"], scope)) throw new Error("Knip baseline analysis scope changed (tool version, primary config, workspace set or enabled plugins). Review and save a new baseline explicitly.");
|
|
125
|
+
const previous = new Set(baseline["findings"].map((item) => item.fingerprint));
|
|
126
|
+
const current = new Set(findings.map((item) => item.fingerprint));
|
|
127
|
+
return {
|
|
128
|
+
status: "valid",
|
|
129
|
+
path: file,
|
|
130
|
+
existing: findings.filter((item) => previous.has(item.fingerprint)),
|
|
131
|
+
added: findings.filter((item) => !previous.has(item.fingerprint)),
|
|
132
|
+
fixed: baseline["findings"].filter((item) => !current.has(item.fingerprint))
|
|
133
|
+
};
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return {
|
|
136
|
+
status: "invalid",
|
|
137
|
+
path: file,
|
|
138
|
+
reason: error.message,
|
|
139
|
+
existing: [],
|
|
140
|
+
added: [],
|
|
141
|
+
fixed: []
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
export { summarizeKnip as i, validateKnipBaseline as n, parseKnipOutput as r, compareKnipBaseline as t };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from "pathe";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path$1 from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { build } from "esbuild";
|
|
6
|
+
//#region src/core/config/bundle.ts
|
|
7
|
+
const preserveModulePaths = {
|
|
8
|
+
name: "repoctl-config-module-paths",
|
|
9
|
+
setup(plugin) {
|
|
10
|
+
plugin.onLoad({ filter: /\.[cm]?[jt]s$/ }, async ({ path: filename }) => {
|
|
11
|
+
const source = (await readFile(filename, "utf8")).replace(/^#![^\n]*(?:\n|$)/, "");
|
|
12
|
+
const directory = path$1.dirname(filename);
|
|
13
|
+
return {
|
|
14
|
+
contents: `const __repoctl_filename = ${JSON.stringify(filename)}; const __repoctl_dirname = ${JSON.stringify(directory)}; const __repoctl_url = ${JSON.stringify(pathToFileURL(filename).href)};\n` + source,
|
|
15
|
+
loader: /\.[cm]?ts$/.test(filename) ? "ts" : "js"
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** Compile local configuration modules in memory; installed packages stay external. */
|
|
21
|
+
async function bundleConfig(filename) {
|
|
22
|
+
const cwd = path.dirname(filename);
|
|
23
|
+
const result = await build({
|
|
24
|
+
entryPoints: [filename],
|
|
25
|
+
absWorkingDir: cwd,
|
|
26
|
+
bundle: true,
|
|
27
|
+
write: false,
|
|
28
|
+
metafile: true,
|
|
29
|
+
platform: "node",
|
|
30
|
+
format: "esm",
|
|
31
|
+
packages: "external",
|
|
32
|
+
treeShaking: false,
|
|
33
|
+
logLevel: "silent",
|
|
34
|
+
define: {
|
|
35
|
+
"__filename": "__repoctl_filename",
|
|
36
|
+
"__dirname": "__repoctl_dirname",
|
|
37
|
+
"import.meta.filename": "__repoctl_filename",
|
|
38
|
+
"import.meta.dirname": "__repoctl_dirname",
|
|
39
|
+
"import.meta.url": "__repoctl_url"
|
|
40
|
+
},
|
|
41
|
+
plugins: [preserveModulePaths]
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
code: result.outputFiles[0].text,
|
|
45
|
+
files: Object.keys(result.metafile.inputs).map((file) => path.resolve(cwd, file))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { bundleConfig };
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
|
|
2
|
+
import { Ht as clearWorkspaceCache, at as record, rt as hash, st as updateManifest } from "./workspace-tasks-CnB8kkS0.mjs";
|
|
3
|
+
import { a as dependencySections, i as rangesOverlap, n as equivalentRanges, r as parseSpecifier, t as scanDependencies } from "./scan-4nboHNXP.mjs";
|
|
4
|
+
import { i as dependencyNextSteps, n as inspectDependencyPlanInputs, o as dependencyReport, r as validateDependencyPlan, t as writeDependencyTransaction } from "./transaction-DAhY8EpG.mjs";
|
|
5
|
+
import { satisfies, subset, valid, validRange } from "semver";
|
|
6
|
+
import YAML, { isAlias, isMap } from "yaml";
|
|
7
|
+
import { isDeepStrictEqual } from "node:util";
|
|
8
|
+
//#region src/commands/deps/catalog/config.ts
|
|
9
|
+
function catalogName(value = "default") {
|
|
10
|
+
if (typeof value !== "string" || !value.trim() || value !== value.trim()) throw new Error("Select a nonempty catalog name (default or a named catalog).");
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function readCatalogs(workspace) {
|
|
14
|
+
const named = record(workspace["catalogs"]);
|
|
15
|
+
if (workspace["catalogs"] != null && !named) throw new Error("pnpm-workspace.yaml catalogs must be a mapping.");
|
|
16
|
+
if (workspace["catalog"] != null && named?.["default"] != null) throw new Error("The default catalog is defined twice; use catalog or catalogs.default, not both.");
|
|
17
|
+
const catalogs = /* @__PURE__ */ new Map();
|
|
18
|
+
const items = [...Object.entries(named ?? {})];
|
|
19
|
+
if (workspace["catalog"] != null) items.push(["default", workspace["catalog"]]);
|
|
20
|
+
for (const [name, value] of items.sort(([a], [b]) => a.localeCompare(b))) {
|
|
21
|
+
catalogName(name);
|
|
22
|
+
const entries = record(value);
|
|
23
|
+
if (!entries || Object.values(entries).some((entry) => typeof entry !== "string")) throw new Error(`Catalog ${name} must map dependency names to string specifiers.`);
|
|
24
|
+
catalogs.set(name, entries);
|
|
25
|
+
}
|
|
26
|
+
return catalogs;
|
|
27
|
+
}
|
|
28
|
+
function catalogEntry(catalogs, name, dependency) {
|
|
29
|
+
const entries = catalogs.get(name);
|
|
30
|
+
return entries && Object.hasOwn(entries, dependency) ? entries[dependency] : void 0;
|
|
31
|
+
}
|
|
32
|
+
function addCatalogEntry(original, name, dependency, target) {
|
|
33
|
+
const document = YAML.parseDocument(original, { keepSourceTokens: true });
|
|
34
|
+
if (document.errors.length) throw document.errors[0];
|
|
35
|
+
const location = name === "default" && !document.hasIn(["catalogs", "default"]) ? ["catalog"] : ["catalogs", name];
|
|
36
|
+
for (let index = 0; index <= location.length; index++) {
|
|
37
|
+
const node = index ? document.getIn(location.slice(0, index), true) : document.contents;
|
|
38
|
+
if (isAlias(node) || isMap(node) && node.anchor) throw new Error("Catalog migration cannot edit an anchored or aliased catalog mapping; make that mapping explicit first.");
|
|
39
|
+
}
|
|
40
|
+
document.setIn([...location, dependency], target);
|
|
41
|
+
let output = document.toString({ lineWidth: 0 });
|
|
42
|
+
if (!original.endsWith("\n")) output = output.replace(/\n$/, "");
|
|
43
|
+
return original.includes("\r\n") ? output.replaceAll("\n", "\r\n") : output;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/commands/deps/catalog/selection.ts
|
|
47
|
+
function migrationCandidate(scan, group, options) {
|
|
48
|
+
const catalog = catalogName(options.catalog);
|
|
49
|
+
const current = catalogEntry(readCatalogs(scan.workspace), catalog, group.dependency);
|
|
50
|
+
const result = {
|
|
51
|
+
dependency: group.dependency,
|
|
52
|
+
section: group.section,
|
|
53
|
+
group: group.group,
|
|
54
|
+
catalog,
|
|
55
|
+
status: "blocked",
|
|
56
|
+
reason: "unsupported_protocol",
|
|
57
|
+
target: null,
|
|
58
|
+
occurrences: group.occurrences
|
|
59
|
+
};
|
|
60
|
+
const stop = (reason) => ({
|
|
61
|
+
...result,
|
|
62
|
+
reason
|
|
63
|
+
});
|
|
64
|
+
if (group.status === "exception") return stop("policy_exception");
|
|
65
|
+
if (group.occurrences.some((item) => item.protocol === "catalog" && (item.specifier.slice(8) || "default") !== catalog)) return stop("different_catalog");
|
|
66
|
+
if (options.to !== void 0 && current !== void 0 && options.to !== current) return stop("existing_entry_conflict");
|
|
67
|
+
if (group.occurrences.every((item) => item.protocol === "catalog") && current !== void 0) return {
|
|
68
|
+
...result,
|
|
69
|
+
status: "managed",
|
|
70
|
+
reason: "already_cataloged",
|
|
71
|
+
target: current
|
|
72
|
+
};
|
|
73
|
+
if (group.section === "peerDependencies") return stop("peer_range");
|
|
74
|
+
if (group.occurrences.some((item) => ![
|
|
75
|
+
"semver",
|
|
76
|
+
"npm",
|
|
77
|
+
"catalog"
|
|
78
|
+
].includes(item.protocol) || !item.range || !item.source) || new Set(group.occurrences.map((item) => item.source)).size !== 1) return stop("unsupported_protocol");
|
|
79
|
+
const ranges = group.occurrences.map((item) => item.range);
|
|
80
|
+
if (rangesOverlap(ranges) !== true) return stop("incompatible_ranges");
|
|
81
|
+
const target = options.to ?? current ?? (equivalentRanges(ranges) ? group.occurrences[0].specifier : void 0);
|
|
82
|
+
if (!target) return {
|
|
83
|
+
...result,
|
|
84
|
+
status: "needs_target",
|
|
85
|
+
reason: "target_required"
|
|
86
|
+
};
|
|
87
|
+
const parsed = parseSpecifier(group.dependency, target);
|
|
88
|
+
if (!["semver", "npm"].includes(parsed.protocol) || !parsed.range || group.occurrences.some((item) => item.source !== parsed.source || item.protocol !== "catalog" && item.protocol !== parsed.protocol)) return stop("unsupported_protocol");
|
|
89
|
+
const version = valid(parsed.range);
|
|
90
|
+
if (ranges.some((range) => !(version ? satisfies(version, range) : subset(parsed.range, range)))) return stop(current !== void 0 ? "existing_entry_conflict" : "target_not_subset");
|
|
91
|
+
return {
|
|
92
|
+
...result,
|
|
93
|
+
status: "ready",
|
|
94
|
+
reason: current !== void 0 ? "existing_entry" : options.to !== void 0 ? "explicit_narrowing" : "equivalent_ranges",
|
|
95
|
+
target
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/commands/deps/catalog/plan.ts
|
|
100
|
+
function prepareCatalogMigration(scan, options) {
|
|
101
|
+
if (!options || typeof options.dependency !== "string" || !options.dependency.trim() || !dependencySections.includes(options.section) || options.group !== void 0 && (typeof options.group !== "string" || !options.group) || options.to !== void 0 && (typeof options.to !== "string" || !options.to.trim())) throw new Error("Select a dependency, dependency section and optional explicit catalog target.");
|
|
102
|
+
const catalog = catalogName(options.catalog);
|
|
103
|
+
const group = dependencyReport(scan).groups.find((item) => item.dependency === options.dependency && item.section === options.section && item.group === (options.group ?? "default"));
|
|
104
|
+
if (!group) throw new Error("No dependency declarations match this catalog migration selection.");
|
|
105
|
+
const candidate = migrationCandidate(scan, group, options);
|
|
106
|
+
if (!["ready", "managed"].includes(candidate.status) || candidate.target === null) throw new Error(`Catalog migration requires review: ${candidate.reason}. Choose an intentional version group/named catalog, provide a common --to subrange, or keep the declarations unchanged.`);
|
|
107
|
+
const selection = {
|
|
108
|
+
dependency: options.dependency,
|
|
109
|
+
section: options.section,
|
|
110
|
+
group: options.group ?? "default",
|
|
111
|
+
catalog,
|
|
112
|
+
to: candidate.target
|
|
113
|
+
};
|
|
114
|
+
const updates = group.occurrences.filter((item) => item.protocol !== "catalog").map((item) => {
|
|
115
|
+
const original = scan.contents.get(item.path);
|
|
116
|
+
const reference = catalog === "default" ? "catalog:" : `catalog:${catalog}`;
|
|
117
|
+
return {
|
|
118
|
+
path: item.path,
|
|
119
|
+
original,
|
|
120
|
+
content: updateManifest(original, item.section, item.name, reference)
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
if (updates.length && !Object.hasOwn(readCatalogs(scan.workspace).get(catalog) ?? {}, selection.dependency)) {
|
|
124
|
+
const original = scan.contents.get("pnpm-workspace.yaml");
|
|
125
|
+
updates.push({
|
|
126
|
+
path: "pnpm-workspace.yaml",
|
|
127
|
+
original,
|
|
128
|
+
content: addCatalogEntry(original, catalog, selection.dependency, selection.to)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
plan: {
|
|
133
|
+
schemaVersion: 1,
|
|
134
|
+
kind: "catalog-migration",
|
|
135
|
+
workspaceDir: scan.workspaceDir,
|
|
136
|
+
selection,
|
|
137
|
+
inputs: scan.inputs,
|
|
138
|
+
files: updates.map((item) => ({
|
|
139
|
+
path: item.path,
|
|
140
|
+
beforeHash: hash(item.original),
|
|
141
|
+
afterHash: hash(item.content),
|
|
142
|
+
before: item.original,
|
|
143
|
+
after: item.content
|
|
144
|
+
})),
|
|
145
|
+
consumers: group.occurrences,
|
|
146
|
+
nextSteps: [...dependencyNextSteps]
|
|
147
|
+
},
|
|
148
|
+
updates
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/commands/deps/catalog/references.ts
|
|
153
|
+
function catalogReferences(scan, catalogs) {
|
|
154
|
+
const declarations = scan.occurrences.filter((item) => item.protocol === "catalog");
|
|
155
|
+
for (const [selector, specifier] of Object.entries(record(scan.workspace["overrides"]) ?? {})) {
|
|
156
|
+
if (typeof specifier !== "string" || !specifier.startsWith("catalog:")) continue;
|
|
157
|
+
const parsed = /^((?:@[\w.~-]+\/)?[\w.~-]+)(?:@(.+))?$/.exec(selector);
|
|
158
|
+
const name = parsed && (!parsed[2] || !parsed[2].includes(">") || validRange(parsed[2])) ? parsed[1] : null;
|
|
159
|
+
declarations.push({
|
|
160
|
+
name: name ?? selector,
|
|
161
|
+
path: "pnpm-workspace.yaml",
|
|
162
|
+
workspace: ".",
|
|
163
|
+
packageName: null,
|
|
164
|
+
section: "overrides",
|
|
165
|
+
specifier,
|
|
166
|
+
...name ? parseSpecifier(name, specifier, scan.workspace) : {
|
|
167
|
+
protocol: "catalog",
|
|
168
|
+
source: null,
|
|
169
|
+
range: null
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return declarations.map((item) => {
|
|
174
|
+
const catalog = item.specifier.slice(8) || "default";
|
|
175
|
+
const entries = catalogs.get(catalog);
|
|
176
|
+
const unresolved = item.section === "overrides" && !/^(?:@[\w.~-]+\/)?[\w.~-]+$/.test(item.name);
|
|
177
|
+
const status = !entries ? "missing_catalog" : unresolved ? "unresolved_selector" : Object.hasOwn(entries, item.name) ? "resolved" : "missing_entry";
|
|
178
|
+
return {
|
|
179
|
+
...item,
|
|
180
|
+
catalog,
|
|
181
|
+
status
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/commands/deps/catalog/report.ts
|
|
187
|
+
function catalogReport(scan, options = {}) {
|
|
188
|
+
const catalog = catalogName(options.catalog);
|
|
189
|
+
const catalogs = readCatalogs(scan.workspace);
|
|
190
|
+
const findings = [];
|
|
191
|
+
const references = catalogReferences(scan, catalogs);
|
|
192
|
+
for (const item of references) if (item.status !== "resolved") findings.push({
|
|
193
|
+
code: item.status,
|
|
194
|
+
catalog: item.catalog,
|
|
195
|
+
dependency: item.name,
|
|
196
|
+
path: item.path,
|
|
197
|
+
section: item.section,
|
|
198
|
+
specifier: item.specifier
|
|
199
|
+
});
|
|
200
|
+
const entries = [];
|
|
201
|
+
for (const [name, values] of catalogs) for (const [dependency, specifier] of Object.entries(values).sort(([a], [b]) => a.localeCompare(b))) {
|
|
202
|
+
const consumers = references.filter((item) => item.catalog === name && item.name === dependency && item.status === "resolved");
|
|
203
|
+
const uncertain = references.some((item) => item.catalog === name && item.status === "unresolved_selector");
|
|
204
|
+
entries.push({
|
|
205
|
+
catalog: name,
|
|
206
|
+
dependency,
|
|
207
|
+
specifier,
|
|
208
|
+
status: consumers.length ? "used" : uncertain ? "usage_unknown" : "unused",
|
|
209
|
+
consumers
|
|
210
|
+
});
|
|
211
|
+
if (!consumers.length && !uncertain) findings.push({
|
|
212
|
+
code: "unused_entry",
|
|
213
|
+
catalog: name,
|
|
214
|
+
dependency,
|
|
215
|
+
path: "pnpm-workspace.yaml",
|
|
216
|
+
specifier
|
|
217
|
+
});
|
|
218
|
+
const parsed = parseSpecifier(dependency, specifier);
|
|
219
|
+
if (!["semver", "npm"].includes(parsed.protocol) || !parsed.range) findings.push({
|
|
220
|
+
code: "uncomparable_entry",
|
|
221
|
+
catalog: name,
|
|
222
|
+
dependency,
|
|
223
|
+
path: "pnpm-workspace.yaml",
|
|
224
|
+
specifier
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
const candidates = dependencyReport(scan).groups.map((group) => migrationCandidate(scan, group, { catalog }));
|
|
228
|
+
for (const candidate of candidates) {
|
|
229
|
+
if (["peer_range", "policy_exception"].includes(candidate.reason)) continue;
|
|
230
|
+
for (const item of candidate.occurrences) if (["semver", "npm"].includes(item.protocol) && Object.hasOwn(catalogs.get(catalog) ?? {}, item.name)) findings.push({
|
|
231
|
+
code: "direct_declaration",
|
|
232
|
+
catalog,
|
|
233
|
+
dependency: item.name,
|
|
234
|
+
path: item.path,
|
|
235
|
+
section: item.section,
|
|
236
|
+
specifier: item.specifier
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
schemaVersion: 1,
|
|
241
|
+
workspaceDir: scan.workspaceDir,
|
|
242
|
+
catalog,
|
|
243
|
+
entries,
|
|
244
|
+
references,
|
|
245
|
+
findings,
|
|
246
|
+
candidates,
|
|
247
|
+
summary: {
|
|
248
|
+
missing: references.filter((item) => item.status === "missing_catalog" || item.status === "missing_entry").length,
|
|
249
|
+
unused: entries.filter((item) => item.status === "unused").length,
|
|
250
|
+
uncomparable: findings.filter((item) => item.code === "uncomparable_entry").length,
|
|
251
|
+
direct: findings.filter((item) => item.code === "direct_declaration").length,
|
|
252
|
+
ready: candidates.filter((item) => item.status === "ready").length
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/commands/deps/catalog/apply.ts
|
|
258
|
+
async function applyCatalogMigrationPlan(cwd, plan) {
|
|
259
|
+
validateDependencyPlan(plan);
|
|
260
|
+
if (plan.kind !== "catalog-migration" || !Array.isArray(plan.consumers)) throw new Error("Invalid catalog migration plan.");
|
|
261
|
+
const scan = await scanDependencies(cwd);
|
|
262
|
+
if (inspectDependencyPlanInputs(scan, plan)) return {
|
|
263
|
+
status: "unchanged",
|
|
264
|
+
changed: [],
|
|
265
|
+
nextSteps: [...dependencyNextSteps]
|
|
266
|
+
};
|
|
267
|
+
const prepared = prepareCatalogMigration(scan, plan.selection);
|
|
268
|
+
if (!isDeepStrictEqual(prepared.plan.files, plan.files) || !isDeepStrictEqual(prepared.plan.consumers, plan.consumers)) throw new Error("The catalog migration no longer matches the reviewed declarations and YAML changes.");
|
|
269
|
+
if (!prepared.updates.length) return {
|
|
270
|
+
status: "unchanged",
|
|
271
|
+
changed: [],
|
|
272
|
+
nextSteps: [...dependencyNextSteps]
|
|
273
|
+
};
|
|
274
|
+
try {
|
|
275
|
+
await writeDependencyTransaction(scan.workspaceDir, prepared.updates);
|
|
276
|
+
} finally {
|
|
277
|
+
clearWorkspaceCache();
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
status: "applied",
|
|
281
|
+
changed: plan.files.map((file) => file.path),
|
|
282
|
+
nextSteps: [...dependencyNextSteps]
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/commands/deps/catalog/index.ts
|
|
287
|
+
var catalog_exports = /* @__PURE__ */ __exportAll({
|
|
288
|
+
applyCatalogMigrationPlan: () => applyCatalogMigrationPlan,
|
|
289
|
+
checkCatalogs: () => checkCatalogs,
|
|
290
|
+
planCatalogMigration: () => planCatalogMigration
|
|
291
|
+
});
|
|
292
|
+
async function checkCatalogs(cwd, options = {}) {
|
|
293
|
+
return catalogReport(await scanDependencies(cwd), options);
|
|
294
|
+
}
|
|
295
|
+
async function planCatalogMigration(cwd, options) {
|
|
296
|
+
return prepareCatalogMigration(await scanDependencies(cwd), options).plan;
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
export { applyCatalogMigrationPlan as i, checkCatalogs as n, planCatalogMigration as r, catalog_exports as t };
|