@theholocron/astromech 5.0.0-alpha.283 → 5.0.0-alpha.284
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 +13 -0
- package/dist/repo-validation/index.d.mts +58 -0
- package/dist/repo-validation/index.mjs +97 -0
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -248,3 +248,16 @@ config surface don't pull `@commitlint/*` in:
|
|
|
248
248
|
The root entry also exports the config-file generators `holocron repo setup`
|
|
249
249
|
writes (`createEditorconfig`, `createAlexrc`, `createPrePush`, …) and
|
|
250
250
|
`createHeader`.
|
|
251
|
+
|
|
252
|
+
## Repo validation — `@theholocron/astromech/repo-validation`
|
|
253
|
+
|
|
254
|
+
The rules of the `platform.repoValidation` checks, once, as pure functions over plain data (changed files, commit
|
|
255
|
+
subjects, the PR description, a manifest) that return findings. They do no git, no filesystem and no network, so the two
|
|
256
|
+
interfaces that run them only supply the data: the CLI (`holocron probe docs presence`, and the `docsEnforcement` job of
|
|
257
|
+
`holocron run platform.repoValidation`) from git, and [Sentinel](https://docs.theholocron.dev/holocron/sentinel/) from the
|
|
258
|
+
webhook and the GitHub API (#929).
|
|
259
|
+
|
|
260
|
+
- Docs presence: `isFeat(subjects)`, `packageOf(file, readPackage)`, `pageNames(dir)`, `hasDocsSignal(dir, changedFiles, addedCommentLines)`,
|
|
261
|
+
`isAddedDocComment(line)`, `parseSkipDocs(text)` (the `[skip docs] <reason>` marker) and
|
|
262
|
+
`evaluateDocsPresence({ packages, changedFiles, addedCommentLines, skip })`, which sorts a feature's packages into
|
|
263
|
+
those to warn about and those a marker excused.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** A `[skip docs]` marker found in a PR description or commit message. */
|
|
2
|
+
interface SkipDocs {
|
|
3
|
+
/** The packages it names (`[skip docs: array-utils]`), or `null` for every package. */
|
|
4
|
+
scope: string[] | null;
|
|
5
|
+
/** What follows the marker on its line; empty when the marker gives no reason, which does not count. */
|
|
6
|
+
reason: string;
|
|
7
|
+
}
|
|
8
|
+
/** What the docs-presence check found for the packages a feature changed. */
|
|
9
|
+
interface DocsPresenceResult {
|
|
10
|
+
/** Packages with no docs signal and no `[skip docs]` reason. */
|
|
11
|
+
warn: string[];
|
|
12
|
+
/** Packages a `[skip docs]` marker with a reason covered. */
|
|
13
|
+
skipped: Array<{
|
|
14
|
+
dir: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** A marker covered a package but gave no reason, so the package is in `warn`. */
|
|
18
|
+
missingReason: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sorts the packages a feature changed into those that need a warning (no docs signal, and no `[skip docs]` marker
|
|
22
|
+
* with a reason that covers them) and those a marker excused. A marker with no reason excuses nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function evaluateDocsPresence(input: {
|
|
25
|
+
packages: readonly string[];
|
|
26
|
+
changedFiles: readonly string[];
|
|
27
|
+
addedCommentLines: (dir: string) => readonly string[];
|
|
28
|
+
skip: SkipDocs | null;
|
|
29
|
+
}): DocsPresenceResult;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the PR touches a package's documentation: a doc comment added in its source, its `README.md`, or a docs
|
|
32
|
+
* page named after it (see `pageNames`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasDocsSignal(dir: string, changedFiles: readonly string[], addedCommentLines: readonly string[]): boolean;
|
|
35
|
+
/** Whether a line of a unified diff adds part of a doc comment: its `/**` opener, a ` * text` line or the closer. */
|
|
36
|
+
export declare function isAddedDocComment(line: string): boolean;
|
|
37
|
+
/** Whether any subject is a Conventional Commit `feat`: `feat:`, `feat(scope):` or `feat!:`, in any case. */
|
|
38
|
+
export declare function isFeat(subjects: readonly string[]): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The public package a changed file is source of: the nearest folder above it with a `package.json`, when the file is
|
|
41
|
+
* under that package's `src/` or is its root `index`, and the package is not private. Tests, other package files and
|
|
42
|
+
* files in no package give `undefined`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function packageOf(file: string, readPackage: (dir: string) => {
|
|
45
|
+
private?: boolean;
|
|
46
|
+
} | undefined): string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The names a package's docs page can have: its folder name, and that name without the `-client` or
|
|
49
|
+
* `holocron-plugin-` part its page drops (`clients/axiom-client` is the page `clients/axiom.mdx`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function pageNames(dir: string): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Finds `[skip docs] reason`, or `[skip docs: pkg-a, pkg-b] reason`, on one line of a PR description or commit
|
|
54
|
+
* body. Like semantic-release's `[skip ci]`, except that the reason after it is what makes it count. `null` when the
|
|
55
|
+
* text has no marker.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseSkipDocs(text: string): SkipDocs | null;
|
|
58
|
+
export type { DocsPresenceResult, SkipDocs };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/repo-validation/docs-presence/page-names/page-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* The names a package's docs page can have: its folder name, and that name without the `-client` or
|
|
4
|
+
* `holocron-plugin-` part its page drops (`clients/axiom-client` is the page `clients/axiom.mdx`).
|
|
5
|
+
*/
|
|
6
|
+
function pageNames(dir) {
|
|
7
|
+
const name = dir.slice(dir.lastIndexOf("/") + 1);
|
|
8
|
+
return [.../* @__PURE__ */ new Set([
|
|
9
|
+
name,
|
|
10
|
+
name.replace(/-client$/, ""),
|
|
11
|
+
name.replace(/^holocron-plugin-/, "")
|
|
12
|
+
])];
|
|
13
|
+
}
|
|
14
|
+
// src/repo-validation/docs-presence/has-docs-signal/has-docs-signal.ts
|
|
15
|
+
/**
|
|
16
|
+
* Whether the PR touches a package's documentation: a doc comment added in its source, its `README.md`, or a docs
|
|
17
|
+
* page named after it (see `pageNames`).
|
|
18
|
+
*/
|
|
19
|
+
function hasDocsSignal(dir, changedFiles, addedCommentLines) {
|
|
20
|
+
if (addedCommentLines.length > 0) return true;
|
|
21
|
+
const names = pageNames(dir);
|
|
22
|
+
return changedFiles.some((f) => {
|
|
23
|
+
if (f === `${dir}/README.md`) return true;
|
|
24
|
+
if (!f.startsWith("docs/") || !/\.mdx?$/.test(f)) return false;
|
|
25
|
+
return names.includes(f.slice(f.lastIndexOf("/") + 1).replace(/\.mdx?$/, ""));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// src/repo-validation/docs-presence/evaluate-docs-presence/evaluate-docs-presence.ts
|
|
29
|
+
/**
|
|
30
|
+
* Sorts the packages a feature changed into those that need a warning (no docs signal, and no `[skip docs]` marker
|
|
31
|
+
* with a reason that covers them) and those a marker excused. A marker with no reason excuses nothing.
|
|
32
|
+
*/
|
|
33
|
+
function evaluateDocsPresence(input) {
|
|
34
|
+
const { packages, changedFiles, addedCommentLines, skip } = input;
|
|
35
|
+
const result = {
|
|
36
|
+
warn: [],
|
|
37
|
+
skipped: [],
|
|
38
|
+
missingReason: false
|
|
39
|
+
};
|
|
40
|
+
for (const dir of packages) {
|
|
41
|
+
if (hasDocsSignal(dir, changedFiles, addedCommentLines(dir))) continue;
|
|
42
|
+
const covered = skip !== null && (skip.scope === null || skip.scope.some((s) => s === dir || pageNames(dir).includes(s)));
|
|
43
|
+
if (covered && skip.reason) {
|
|
44
|
+
result.skipped.push({
|
|
45
|
+
dir,
|
|
46
|
+
reason: skip.reason
|
|
47
|
+
});
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (covered) result.missingReason = true;
|
|
51
|
+
result.warn.push(dir);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
// src/repo-validation/docs-presence/is-added-doc-comment/is-added-doc-comment.ts
|
|
56
|
+
/** Whether a line of a unified diff adds part of a doc comment: its `/**` opener, a ` * text` line or the closer. */
|
|
57
|
+
function isAddedDocComment(line) {
|
|
58
|
+
return /^\+\s*(\/\*\*|\*(\s|\/|$))/.test(line);
|
|
59
|
+
}
|
|
60
|
+
// src/repo-validation/docs-presence/is-feat/is-feat.ts
|
|
61
|
+
/** Whether any subject is a Conventional Commit `feat`: `feat:`, `feat(scope):` or `feat!:`, in any case. */
|
|
62
|
+
function isFeat(subjects) {
|
|
63
|
+
return subjects.some((s) => /^feat(\([^)]*\))?!?:/i.test(s.trim()));
|
|
64
|
+
}
|
|
65
|
+
// src/repo-validation/docs-presence/package-of/package-of.ts
|
|
66
|
+
/**
|
|
67
|
+
* The public package a changed file is source of: the nearest folder above it with a `package.json`, when the file is
|
|
68
|
+
* under that package's `src/` or is its root `index`, and the package is not private. Tests, other package files and
|
|
69
|
+
* files in no package give `undefined`.
|
|
70
|
+
*/
|
|
71
|
+
function packageOf(file, readPackage) {
|
|
72
|
+
if (file.includes("node_modules/") || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file)) return void 0;
|
|
73
|
+
const parts = file.split("/");
|
|
74
|
+
for (let i = parts.length - 1; i > 0; i--) {
|
|
75
|
+
const dir = parts.slice(0, i).join("/");
|
|
76
|
+
const pkg = readPackage(dir);
|
|
77
|
+
if (!pkg) continue;
|
|
78
|
+
if (pkg.private) return void 0;
|
|
79
|
+
const inside = parts.slice(i).join("/");
|
|
80
|
+
return inside.startsWith("src/") || /^index\.[cm]?[jt]s$/.test(inside) ? dir : void 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// src/repo-validation/docs-presence/parse-skip-docs/parse-skip-docs.ts
|
|
84
|
+
/**
|
|
85
|
+
* Finds `[skip docs] reason`, or `[skip docs: pkg-a, pkg-b] reason`, on one line of a PR description or commit
|
|
86
|
+
* body. Like semantic-release's `[skip ci]`, except that the reason after it is what makes it count. `null` when the
|
|
87
|
+
* text has no marker.
|
|
88
|
+
*/
|
|
89
|
+
function parseSkipDocs(text) {
|
|
90
|
+
const match = /\[skip docs(?::\s*([^\]]*?))?\][ \t]*([^\n]*)/i.exec(text);
|
|
91
|
+
if (!match) return null;
|
|
92
|
+
return {
|
|
93
|
+
scope: match[1] ? match[1].split(",").map((s) => s.trim()).filter(Boolean) : null,
|
|
94
|
+
reason: match[2].trim()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export { evaluateDocsPresence, hasDocsSignal, isAddedDocComment, isFeat, packageOf, pageNames, parseSkipDocs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/astromech",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.284",
|
|
4
4
|
"description": "The Holocron task runner — one task manifest drives `holocron run`, `holocron run ci`, the CI workflows, package.json scripts, linters, and required checks.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
"types": "./dist/release/index.d.mts",
|
|
42
42
|
"import": "./dist/release/index.mjs",
|
|
43
43
|
"default": "./dist/release/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./repo-validation": {
|
|
46
|
+
"types": "./dist/repo-validation/index.d.mts",
|
|
47
|
+
"import": "./dist/repo-validation/index.mjs",
|
|
48
|
+
"default": "./dist/repo-validation/index.mjs"
|
|
44
49
|
}
|
|
45
50
|
},
|
|
46
51
|
"files": [
|
|
@@ -50,8 +55,8 @@
|
|
|
50
55
|
"@commitlint/lint": "^21.2.3",
|
|
51
56
|
"@commitlint/load": "^21.2.3",
|
|
52
57
|
"@commitlint/types": "^21.2.3",
|
|
53
|
-
"@theholocron/datapad": "5.0.0-alpha.283",
|
|
54
58
|
"@theholocron/fs-utils": "^1.16.1-alpha.3",
|
|
59
|
+
"@theholocron/datapad": "5.0.0-alpha.284",
|
|
55
60
|
"@theholocron/json-utils": "^1.16.1-alpha.3",
|
|
56
61
|
"@theholocron/pkg-utils": "^1.16.1-alpha.3"
|
|
57
62
|
},
|
|
@@ -73,10 +78,10 @@
|
|
|
73
78
|
"@theholocron/commitlint-config": "^8.9.0-alpha.5",
|
|
74
79
|
"@theholocron/eslint-config": "^8.9.0-alpha.5",
|
|
75
80
|
"@theholocron/rollup-plugin-transform-template": "^8.9.0-alpha.5",
|
|
76
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.5",
|
|
77
81
|
"@theholocron/semantic-release-config": "^8.9.0-alpha.5",
|
|
78
82
|
"@theholocron/tsconfig": "^8.9.0-alpha.5",
|
|
79
|
-
"@theholocron/vitest-config": "^8.9.0-alpha.5"
|
|
83
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.5",
|
|
84
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.5"
|
|
80
85
|
},
|
|
81
86
|
"peerDependencies": {
|
|
82
87
|
"@semantic-release/commit-analyzer": "^13",
|