@theholocron/cli 4.17.1 → 4.17.2
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 +4 -84
- package/dist/cli.mjs.map +1 -1
- package/package.json +4 -4
package/dist/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path, { basename, dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { checkbox, input, select } from "@inquirer/prompts";
|
|
6
|
-
import { KNOWN_WORKFLOWS, createAstromech, extractPreviewConfig, reusableTemplates } from "@theholocron/astromech";
|
|
6
|
+
import { KNOWN_WORKFLOWS, createAstromech, extractPreviewConfig, readWorkspacePackages, reusableTemplates } from "@theholocron/astromech";
|
|
7
7
|
import { loadTasksConfig } from "@theholocron/astromech/config";
|
|
8
8
|
import yargs from "yargs";
|
|
9
9
|
import { hideBin } from "yargs/helpers";
|
|
@@ -3570,86 +3570,6 @@ function createIgnoreConfig() {
|
|
|
3570
3570
|
return `${workflowHeader$6()}${alexignore_default}`;
|
|
3571
3571
|
}
|
|
3572
3572
|
//#endregion
|
|
3573
|
-
//#region src/templates/configs/codecov/codecov.yml
|
|
3574
|
-
var codecov_default = "codecov:\n require_ci_to_pass: true\n\ncoverage:\n precision: 2\n round: down\n status:\n project:\n default:\n target: auto\n threshold: 2%\n # Infra-only PRs (dep bumps, config, lockfile) touch no coverable code,\n # so codecov produces no report to compare. Pass instead of blocking\n # forever on a required check that will never post.\n if_not_found: success\n patch:\n default:\n target: 80%\n if_not_found: success\n\ncomment:\n layout: \"reach,diff,flags,components\"\n behavior: default\n require_changes: true\n\ncomponent_management:\n default_rules:\n statuses:\n - type: patch\n target: 80%\n if_not_found: success\n individual_components:\n";
|
|
3575
|
-
//#endregion
|
|
3576
|
-
//#region src/templates/configs/codecov/utils.ts
|
|
3577
|
-
const INDIVIDUAL_COMPONENTS_MARKER = " individual_components:";
|
|
3578
|
-
function codecovComponentBlock(packages) {
|
|
3579
|
-
if (packages.length === 0) return "\n []\n";
|
|
3580
|
-
return "\n" + packages.flatMap(({ slug }) => [
|
|
3581
|
-
` - component_id: ${slug}`,
|
|
3582
|
-
` name: "${slug}"`,
|
|
3583
|
-
` paths:`,
|
|
3584
|
-
` - packages/${slug}/**`,
|
|
3585
|
-
``
|
|
3586
|
-
]).join("\n");
|
|
3587
|
-
}
|
|
3588
|
-
/**
|
|
3589
|
-
* Ensure every codecov status default carries `if_not_found: success`, so an
|
|
3590
|
-
* infra-only PR (dep bump, config, lockfile — no coverable change) passes
|
|
3591
|
-
* instead of hanging forever on a required check codecov never posts.
|
|
3592
|
-
*
|
|
3593
|
-
* Injects the key on the line after each `target:` that sits inside a status
|
|
3594
|
-
* block (`coverage.status.*.default` or a `statuses:` list item — indent ≥ 8,
|
|
3595
|
-
* or ≥ 8 for a `- type:` list entry), when the immediate sibling lines do not
|
|
3596
|
-
* already declare it.
|
|
3597
|
-
*/
|
|
3598
|
-
function ensureIfNotFound(yaml) {
|
|
3599
|
-
const lines = yaml.split("\n");
|
|
3600
|
-
const out = [];
|
|
3601
|
-
for (let i = 0; i < lines.length; i++) {
|
|
3602
|
-
const line = lines[i];
|
|
3603
|
-
out.push(line);
|
|
3604
|
-
const m = /^(\s{8,})target:\s+\S+\s*$/.exec(line);
|
|
3605
|
-
if (!m) continue;
|
|
3606
|
-
const indent = m[1];
|
|
3607
|
-
let alreadySet = false;
|
|
3608
|
-
for (let j = i + 1; j < lines.length; j++) {
|
|
3609
|
-
const sib = lines[j];
|
|
3610
|
-
if (sib.trim() === "") continue;
|
|
3611
|
-
const sibIndent = sib.match(/^\s*/)[0].length;
|
|
3612
|
-
if (sibIndent < indent.length) break;
|
|
3613
|
-
if (sibIndent === indent.length && /^\s*if_not_found\s*:/.test(sib)) {
|
|
3614
|
-
alreadySet = true;
|
|
3615
|
-
break;
|
|
3616
|
-
}
|
|
3617
|
-
if (sibIndent === indent.length && /^\s*(- |\w)/.test(sib) && !/^\s*(threshold|flags|paths|branches)\s*:/.test(sib)) break;
|
|
3618
|
-
}
|
|
3619
|
-
if (!alreadySet) out.push(`${indent}if_not_found: success`);
|
|
3620
|
-
}
|
|
3621
|
-
return out.join("\n");
|
|
3622
|
-
}
|
|
3623
|
-
function mergeCodecovComponents(existing, packages) {
|
|
3624
|
-
const idx = existing.indexOf(INDIVIDUAL_COMPONENTS_MARKER);
|
|
3625
|
-
if (idx === -1) return ensureIfNotFound(existing);
|
|
3626
|
-
return ensureIfNotFound(existing.slice(0, idx + 24)) + codecovComponentBlock(packages);
|
|
3627
|
-
}
|
|
3628
|
-
async function readWorkspacePackages(repoRoot) {
|
|
3629
|
-
const packagesDir = join(repoRoot, "packages");
|
|
3630
|
-
const entries = await readdir(packagesDir, { withFileTypes: true }).catch(() => null);
|
|
3631
|
-
if (!entries) return [];
|
|
3632
|
-
const packages = [];
|
|
3633
|
-
for (const entry of entries) {
|
|
3634
|
-
if (!entry.isDirectory()) continue;
|
|
3635
|
-
try {
|
|
3636
|
-
const raw = await readFile(join(packagesDir, entry.name, "package.json"), "utf8");
|
|
3637
|
-
const pkg = JSON.parse(raw);
|
|
3638
|
-
if (typeof pkg.name === "string") packages.push({
|
|
3639
|
-
slug: entry.name,
|
|
3640
|
-
name: pkg.name
|
|
3641
|
-
});
|
|
3642
|
-
} catch {}
|
|
3643
|
-
}
|
|
3644
|
-
return packages.sort((a, b) => a.slug.localeCompare(b.slug));
|
|
3645
|
-
}
|
|
3646
|
-
//#endregion
|
|
3647
|
-
//#region src/templates/configs/codecov/create-config.ts
|
|
3648
|
-
const { scaffoldHeader } = createHeader({ source: "packages/cli/src/templates/configs/codecov/create-config.ts" });
|
|
3649
|
-
function createConfig$5(packages) {
|
|
3650
|
-
return `${scaffoldHeader()}${codecov_default.trimEnd()}${codecovComponentBlock(packages)}`;
|
|
3651
|
-
}
|
|
3652
|
-
//#endregion
|
|
3653
3573
|
//#region src/templates/configs/devmoji/create-config.ts
|
|
3654
3574
|
const { workflowHeader: workflowHeader$5 } = createHeader({ source: "packages/cli/src/templates/configs/devmoji/create-config.ts" });
|
|
3655
3575
|
function createConfig$4() {
|
|
@@ -4720,7 +4640,6 @@ async function runSetup(input) {
|
|
|
4720
4640
|
}
|
|
4721
4641
|
{
|
|
4722
4642
|
const hasTestWorkflow = (config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name).includes("test");
|
|
4723
|
-
const packages = await readWorkspacePackages(input.context.repoRoot);
|
|
4724
4643
|
const existing = await readFile(join(input.context.repoRoot, "codecov.yml"), "utf8").catch(() => null);
|
|
4725
4644
|
if (!hasTestWorkflow && existing == null) steps.push({
|
|
4726
4645
|
capability: "source",
|
|
@@ -4729,9 +4648,10 @@ async function runSetup(input) {
|
|
|
4729
4648
|
message: "no test workflow configured"
|
|
4730
4649
|
});
|
|
4731
4650
|
else steps.push(await runStep("source", "write codecov.yml", dryRun, async () => {
|
|
4732
|
-
const content =
|
|
4651
|
+
const content = createAstromech({ cwd: input.context.repoRoot }).codecovConfig(existing);
|
|
4733
4652
|
await source.writeRepoFile("codecov.yml", content);
|
|
4734
|
-
|
|
4653
|
+
const packageCount = readWorkspacePackages(input.context.repoRoot).length;
|
|
4654
|
+
return packageCount > 0 ? `${packageCount} components` : "no components";
|
|
4735
4655
|
}));
|
|
4736
4656
|
print(formatStep(steps[steps.length - 1]));
|
|
4737
4657
|
}
|