@theholocron/cli 5.0.0-alpha.379 → 5.0.0-alpha.380
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/cli.mjs +107 -25
- package/dist/cli.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cli.mjs
CHANGED
|
@@ -16582,30 +16582,40 @@ function firstDifference(committed, generated) {
|
|
|
16582
16582
|
const cut = (text) => text === void 0 ? "(end of file)" : JSON.stringify(text.slice(0, 80));
|
|
16583
16583
|
return `first difference at line ${at + 1}: committed ${cut(a[at])}, generated ${cut(b[at])}`;
|
|
16584
16584
|
}
|
|
16585
|
-
/** The package whose config generated a workflow, from its `# Source package:` marker (`.` is the root). */
|
|
16586
|
-
function sourcePackage(text) {
|
|
16587
|
-
return /^# Source package: (.+)$/m.exec(text)?.[1] ?? null;
|
|
16588
|
-
}
|
|
16589
16585
|
/**
|
|
16590
16586
|
* Problems with the generated files, as human-readable lines: a file that differs from the committed copy or is
|
|
16591
|
-
* missing, a file whose second generation differs from the first, and a workflow that nothing generates and that is not
|
|
16592
|
-
*
|
|
16587
|
+
* missing, a file whose second generation differs from the first, and a workflow that nothing generates and that is not marked as someone else's (hand-maintained or on the
|
|
16588
|
+
* unmanaged list). The files a workspace package's config generates are checked the same way as the root's, and a
|
|
16589
|
+
* problem with one names the package and the command that writes it.
|
|
16593
16590
|
*/
|
|
16594
|
-
function checkGenerated({ files, again, read, workflows }) {
|
|
16591
|
+
function checkGenerated({ files, again, packages = [], read, workflows }) {
|
|
16595
16592
|
const problems = [];
|
|
16596
|
-
const
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
|
|
16602
|
-
}
|
|
16603
|
-
|
|
16593
|
+
const written = /* @__PURE__ */ new Set();
|
|
16594
|
+
const scopes = [{
|
|
16595
|
+
from: "",
|
|
16596
|
+
fix: "`holocron repo setup` or `holocron repo sync`",
|
|
16597
|
+
files,
|
|
16598
|
+
again
|
|
16599
|
+
}, ...packages.map((pkg) => ({
|
|
16600
|
+
from: ` for package ${pkg.path}`,
|
|
16601
|
+
fix: `\`holocron repo sync --cwd ${pkg.path}\``,
|
|
16602
|
+
files: pkg.files,
|
|
16603
|
+
again: pkg.again
|
|
16604
|
+
}))];
|
|
16605
|
+
for (const scope of scopes) {
|
|
16606
|
+
const second = new Map(scope.again.map((f) => [f.path, f.content]));
|
|
16607
|
+
for (const file of scope.files) {
|
|
16608
|
+
if (written.has(file.path)) continue;
|
|
16609
|
+
written.add(file.path);
|
|
16610
|
+
const committed = read(file.path);
|
|
16611
|
+
if (committed === null) problems.push(`${file.path}: missing${scope.from}; run ${scope.fix} and commit it`);
|
|
16612
|
+
else if (committed !== file.content) problems.push(`${file.path}: differs from what holocron generates${scope.from} (${firstDifference(committed, file.content)}); run ${scope.fix} and commit the result`);
|
|
16613
|
+
if (second.get(file.path) !== file.content) problems.push(`${file.path}: generating it twice gives different content`);
|
|
16614
|
+
}
|
|
16615
|
+
}
|
|
16604
16616
|
for (const [name, text] of workflows) {
|
|
16605
16617
|
const path = `${WORKFLOWS_DIR}${name}`;
|
|
16606
|
-
if (
|
|
16607
|
-
const source = sourcePackage(text);
|
|
16608
|
-
if (text.startsWith("# AUTO-GENERATED") && source !== null && source !== ".") continue;
|
|
16618
|
+
if (written.has(path) || name in UNMANAGED_WORKFLOWS || text.startsWith("# HAND-MAINTAINED")) continue;
|
|
16609
16619
|
problems.push(`${path}: no task generates it and it is not marked "# HAND-MAINTAINED"; remove it, or mark it hand-maintained`);
|
|
16610
16620
|
}
|
|
16611
16621
|
return problems;
|
|
@@ -17064,6 +17074,48 @@ async function generateRepoFiles(input) {
|
|
|
17064
17074
|
...await generateTurboFiles(input)
|
|
17065
17075
|
];
|
|
17066
17076
|
}
|
|
17077
|
+
// src/commands/probe/generated/generate-package-workflows.ts
|
|
17078
|
+
/** The extensions a `holocron.config` can have. */
|
|
17079
|
+
const CONFIG_EXTENSIONS = [
|
|
17080
|
+
"ts",
|
|
17081
|
+
"js",
|
|
17082
|
+
"mjs",
|
|
17083
|
+
"cjs",
|
|
17084
|
+
"json"
|
|
17085
|
+
];
|
|
17086
|
+
function files(entries) {
|
|
17087
|
+
return entries.filter((e) => e.kind === "file");
|
|
17088
|
+
}
|
|
17089
|
+
/**
|
|
17090
|
+
* The thin-caller workflows of every workspace package that has a `holocron.config.*` of its own (`apps/sentinel`),
|
|
17091
|
+
* each generated twice by the function `holocron repo sync --cwd <package>` writes them with. The root's own config
|
|
17092
|
+
* is not here. A package whose config cannot be loaded is reported in `errors`, not skipped.
|
|
17093
|
+
*/
|
|
17094
|
+
async function generatePackageWorkflows(repoRoot) {
|
|
17095
|
+
const result = {
|
|
17096
|
+
packages: [],
|
|
17097
|
+
errors: []
|
|
17098
|
+
};
|
|
17099
|
+
for (const pkg of readWorkspacePackages(repoRoot)) {
|
|
17100
|
+
const path = pkg.path ?? `${pkg.dir}/${pkg.slug}`;
|
|
17101
|
+
const dir = join(repoRoot, path);
|
|
17102
|
+
if (!CONFIG_EXTENSIONS.some((ext) => existsSync(join(dir, `holocron.config.${ext}`)))) continue;
|
|
17103
|
+
try {
|
|
17104
|
+
const input = {
|
|
17105
|
+
loaded: await loadConfig(dir),
|
|
17106
|
+
repoRoot: dir
|
|
17107
|
+
};
|
|
17108
|
+
result.packages.push({
|
|
17109
|
+
path,
|
|
17110
|
+
files: files(generateWorkflowFiles(input)),
|
|
17111
|
+
again: files(generateWorkflowFiles(input))
|
|
17112
|
+
});
|
|
17113
|
+
} catch (error) {
|
|
17114
|
+
result.errors.push(`${path}: could not generate its workflows: ${error.message}`);
|
|
17115
|
+
}
|
|
17116
|
+
}
|
|
17117
|
+
return result;
|
|
17118
|
+
}
|
|
17067
17119
|
// src/commands/probe/generated/check-scripts.ts
|
|
17068
17120
|
/**
|
|
17069
17121
|
* Problems with the scripts: a root script that differs from what `scriptsFor` writes (a hand edit is drift, as it is
|
|
@@ -17091,6 +17143,25 @@ function checkScripts({ packages, desired, turboKeys }) {
|
|
|
17091
17143
|
}
|
|
17092
17144
|
return problems;
|
|
17093
17145
|
}
|
|
17146
|
+
// src/commands/probe/generated/shared-workflows.ts
|
|
17147
|
+
/**
|
|
17148
|
+
* One line for each package whose config generates a workflow that the root config (or an earlier package) already
|
|
17149
|
+
* does: only the first is checked, because `holocron repo sync --cwd <package>` refuses to overwrite a file another
|
|
17150
|
+
* package wrote (holocron#1026). It is worth knowing, not a failure; the usual cause is a preset that gives a package
|
|
17151
|
+
* the root's tasks.
|
|
17152
|
+
*/
|
|
17153
|
+
function sharedWorkflows(files, packages) {
|
|
17154
|
+
const owners = new Map(files.map((f) => [f.path, "the root config"]));
|
|
17155
|
+
const lines = [];
|
|
17156
|
+
for (const pkg of packages) {
|
|
17157
|
+
const shared = pkg.files.filter((f) => owners.has(f.path));
|
|
17158
|
+
for (const file of pkg.files) if (!owners.has(file.path)) owners.set(file.path, `package ${pkg.path}`);
|
|
17159
|
+
if (shared.length === 0) continue;
|
|
17160
|
+
const first = shared[0];
|
|
17161
|
+
lines.push(`package ${pkg.path} also generates ${shared.length} workflow(s) that another config writes, only that copy is checked (${first.path}, from ${owners.get(first.path)}, is one)`);
|
|
17162
|
+
}
|
|
17163
|
+
return lines;
|
|
17164
|
+
}
|
|
17094
17165
|
// src/commands/probe/generated/generated-probes.ts
|
|
17095
17166
|
/** The group of probes that check the files `repo setup` and `repo sync` generate. */
|
|
17096
17167
|
const GENERATED_PROVIDER = "generated";
|
|
@@ -17144,7 +17215,8 @@ async function generate(input) {
|
|
|
17144
17215
|
/**
|
|
17145
17216
|
* `generated check` generates every file `repo setup` writes from the config alone (no provider, no token), twice, and
|
|
17146
17217
|
* fails for each one that differs from the committed copy, differs the second time, or is a workflow nothing
|
|
17147
|
-
* generates.
|
|
17218
|
+
* generates. It does the same for the workflows each workspace package's own config generates (`apps/sentinel`), which
|
|
17219
|
+
* are named by the package in the message. CI runs it, so a change to a generator or to the config that was not followed by a run of `repo setup`
|
|
17148
17220
|
* or `repo sync` cannot merge.
|
|
17149
17221
|
*/
|
|
17150
17222
|
function generatedProbes(loaded, repoRoot) {
|
|
@@ -17158,21 +17230,31 @@ function generatedProbes(loaded, repoRoot) {
|
|
|
17158
17230
|
};
|
|
17159
17231
|
const first = await generate(input);
|
|
17160
17232
|
const second = await generate(input);
|
|
17233
|
+
const owned = await generatePackageWorkflows(repoRoot);
|
|
17161
17234
|
const workflowsDir = join(repoRoot, ".github", "workflows");
|
|
17162
17235
|
const workflows = /* @__PURE__ */ new Map();
|
|
17163
17236
|
for (const name of readdirSync(workflowsDir).filter((n) => n.endsWith(".yml")).sort()) workflows.set(name, readFileSync(join(workflowsDir, name), "utf8"));
|
|
17164
|
-
const problems = [
|
|
17165
|
-
|
|
17166
|
-
|
|
17167
|
-
|
|
17168
|
-
|
|
17169
|
-
|
|
17237
|
+
const problems = [
|
|
17238
|
+
...first.errors,
|
|
17239
|
+
...owned.errors,
|
|
17240
|
+
...checkGenerated({
|
|
17241
|
+
files: first.files,
|
|
17242
|
+
again: second.files,
|
|
17243
|
+
packages: owned.packages,
|
|
17244
|
+
read: (path) => readText(join(repoRoot, path)),
|
|
17245
|
+
workflows
|
|
17246
|
+
})
|
|
17247
|
+
];
|
|
17170
17248
|
const scripts = checkScripts(scriptsInput(loaded, repoRoot));
|
|
17171
17249
|
problems.push(...scripts.fail);
|
|
17172
17250
|
for (const line of problems) ctx.say({
|
|
17173
17251
|
status: "fail",
|
|
17174
17252
|
label: line
|
|
17175
17253
|
});
|
|
17254
|
+
for (const line of sharedWorkflows(first.files, owned.packages)) ctx.say({
|
|
17255
|
+
status: "info",
|
|
17256
|
+
label: line
|
|
17257
|
+
});
|
|
17176
17258
|
for (const line of scripts.info) ctx.say({
|
|
17177
17259
|
status: "info",
|
|
17178
17260
|
label: line
|