@theholocron/astromech 5.0.0-alpha.25 → 5.0.0-alpha.251
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 +76 -32
- package/dist/config/index.d.mts +45 -8
- package/dist/config/index.mjs +13 -24
- package/dist/editorconfig-checker-HPpphHhI.mjs +39 -0
- package/dist/index.d.mts +507 -411
- package/dist/index.mjs +2465 -1193
- package/dist/lint/index.d.mts +81 -0
- package/dist/lint/index.mjs +136 -0
- package/dist/load-C1uY2yBv.mjs +35 -0
- package/dist/release/index.d.mts +128 -0
- package/dist/release/index.mjs +230 -0
- package/dist/schema-CalPyBNd.mjs +18 -0
- package/dist/{schema-D01VYg43.d.mts → schema.type-B28guVbH.d.mts} +16 -19
- package/package.json +50 -13
- package/dist/schema-Cf5dfaDO.mjs +0 -11
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { QualifiedConfig } from "@commitlint/types";
|
|
2
|
+
/**
|
|
3
|
+
* The org's canonical `alex` (inclusive-language) config, as raw parsed
|
|
4
|
+
* data rather than the pre-rendered file strings `createRcConfig()`/
|
|
5
|
+
* `createIgnoreConfig()` produce for `holocron repo setup` to write into a
|
|
6
|
+
* repo's own `.alexrc.json`/`.alexignore`.
|
|
7
|
+
*
|
|
8
|
+
* `.alexrc.json` is explicitly "generated by `holocron repo setup` — do not
|
|
9
|
+
* edit manually" (this repo's own `AGENTS.md`) — the real source of truth
|
|
10
|
+
* is this JSON file, one canonical copy, not each repo's synced one. A
|
|
11
|
+
* central Sentinel check (holocron#769/#793) reads it directly rather
|
|
12
|
+
* than fetching each repo's own copy via the Contents API — the same "one
|
|
13
|
+
* config, not N copies" reasoning `@theholocron/commitlint-config` already
|
|
14
|
+
* established for commit-message linting.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ALEX_CONFIG: {
|
|
17
|
+
allow: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Glob-ish path patterns `alex` skips. Kept as a literal here rather than
|
|
21
|
+
* importing `../templates/configs/alexjs/alexignore` directly — that file
|
|
22
|
+
* (like `commit-msg`/`pre-push`) is deliberately extensionless, matching
|
|
23
|
+
* the real filename `holocron repo setup` writes, which ECMAScript's own
|
|
24
|
+
* module resolution (`moduleResolution: "nodenext"`) can't import across
|
|
25
|
+
* a package boundary without an extension. Keep in sync with that file by
|
|
26
|
+
* hand; it changes rarely.
|
|
27
|
+
*/
|
|
28
|
+
export declare const ALEX_IGNORE_PATTERNS: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The paths editorconfig-checker skips, read from the same
|
|
31
|
+
* `editorconfig-checker.json` template `holocron repo setup` writes as a repo's
|
|
32
|
+
* `.editorconfig-checker.json` — so Sentinel's central editorconfig check
|
|
33
|
+
* (holocron#927) excludes exactly what CI's editorconfig-checker does, from
|
|
34
|
+
* one source.
|
|
35
|
+
*
|
|
36
|
+
* The exclusion that matters most is `\.md$` / `\.mdx$`: the generated
|
|
37
|
+
* `.editorconfig` gives every file tab indentation, but
|
|
38
|
+
* `@theholocron/prettier-config` formats markdown with spaces, so a README's
|
|
39
|
+
* indented code example would fail one tool or the other. Markdown is left
|
|
40
|
+
* to prettier and markdownlint.
|
|
41
|
+
*
|
|
42
|
+
* Each entry is a regular-expression source, matched against a
|
|
43
|
+
* repo-relative path, as editorconfig-checker itself treats them.
|
|
44
|
+
*/
|
|
45
|
+
export declare const EDITORCONFIG_CHECKER_EXCLUDE: readonly string[];
|
|
46
|
+
/** `true` when `path` matches any {@link EDITORCONFIG_CHECKER_EXCLUDE} pattern. */
|
|
47
|
+
export declare function isEditorConfigExcluded(path: string): boolean;
|
|
48
|
+
interface CommitMessageViolation {
|
|
49
|
+
/** Rule name, e.g. `"subject-empty"`. */
|
|
50
|
+
rule: string;
|
|
51
|
+
/** commitlint's own message for the failure, e.g. `"subject may not be empty"`. */
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
54
|
+
export declare function lintCommitMessage(message: string, loaded: QualifiedConfig): Promise<CommitMessageViolation[]>;
|
|
55
|
+
interface LintCommitMsgFileResult {
|
|
56
|
+
valid: boolean;
|
|
57
|
+
violations: CommitMessageViolation[];
|
|
58
|
+
}
|
|
59
|
+
export declare function lintCommitMsgFile(filePath: string, cwd?: string): Promise<LintCommitMsgFileResult>;
|
|
60
|
+
/**
|
|
61
|
+
* The org's canonical prettier ignore-pattern list for a central Sentinel
|
|
62
|
+
* check (holocron#769/#819) — the `PRETTIER_CONFIG` object itself doesn't
|
|
63
|
+
* need a home here, since `@theholocron/prettier-config`'s default export
|
|
64
|
+
* already *is* one canonical, importable config (the same "one config,
|
|
65
|
+
* not N copies" reasoning `@theholocron/commitlint-config` established for
|
|
66
|
+
* commit-message linting, and `ALEX_CONFIG` established for inclusive
|
|
67
|
+
* language) — only the ignore list is a Sentinel-specific decision that
|
|
68
|
+
* belongs alongside `ALEX_IGNORE_PATTERNS`, not inside the config package.
|
|
69
|
+
*
|
|
70
|
+
* Reuses `ALEX_IGNORE_PATTERNS`' own entries (`.github/*`, `CHANGELOG.md`,
|
|
71
|
+
* `LICENSE` all independently confirmed to fail a real `prettier.check()`
|
|
72
|
+
* today — machine-generated or unparseable content, same reasoning that
|
|
73
|
+
* excluded them from alex), plus `pnpm-lock.yaml` — prettier-specific
|
|
74
|
+
* (alex never reads a lockfile, but prettier would try to reformat it):
|
|
75
|
+
* machine-written by pnpm's own writer, and not gitignored (lockfiles are
|
|
76
|
+
* tracked), so prettier picks it up by default. Reformatting it
|
|
77
|
+
* fights every subsequent `pnpm install` (this repo's own `.prettierignore`
|
|
78
|
+
* already excludes it for that exact reason).
|
|
79
|
+
*/
|
|
80
|
+
export declare const PRETTIER_IGNORE_PATTERNS: string[];
|
|
81
|
+
export type { CommitMessageViolation, LintCommitMsgFileResult };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { n as alexrc_default, t as editorconfig_checker_default } from "../editorconfig-checker-HPpphHhI.mjs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import load from "@commitlint/load";
|
|
4
|
+
import lint from "@commitlint/lint";
|
|
5
|
+
// src/lint/alex-config/alex-config.ts
|
|
6
|
+
/**
|
|
7
|
+
* The org's canonical `alex` (inclusive-language) config, as raw parsed
|
|
8
|
+
* data rather than the pre-rendered file strings `createRcConfig()`/
|
|
9
|
+
* `createIgnoreConfig()` produce for `holocron repo setup` to write into a
|
|
10
|
+
* repo's own `.alexrc.json`/`.alexignore`.
|
|
11
|
+
*
|
|
12
|
+
* `.alexrc.json` is explicitly "generated by `holocron repo setup` — do not
|
|
13
|
+
* edit manually" (this repo's own `AGENTS.md`) — the real source of truth
|
|
14
|
+
* is this JSON file, one canonical copy, not each repo's synced one. A
|
|
15
|
+
* central Sentinel check (holocron#769/#793) reads it directly rather
|
|
16
|
+
* than fetching each repo's own copy via the Contents API — the same "one
|
|
17
|
+
* config, not N copies" reasoning `@theholocron/commitlint-config` already
|
|
18
|
+
* established for commit-message linting.
|
|
19
|
+
*/
|
|
20
|
+
const ALEX_CONFIG = alexrc_default;
|
|
21
|
+
// src/lint/alex-ignore-patterns/alex-ignore-patterns.ts
|
|
22
|
+
/**
|
|
23
|
+
* Glob-ish path patterns `alex` skips. Kept as a literal here rather than
|
|
24
|
+
* importing `../templates/configs/alexjs/alexignore` directly — that file
|
|
25
|
+
* (like `commit-msg`/`pre-push`) is deliberately extensionless, matching
|
|
26
|
+
* the real filename `holocron repo setup` writes, which ECMAScript's own
|
|
27
|
+
* module resolution (`moduleResolution: "nodenext"`) can't import across
|
|
28
|
+
* a package boundary without an extension. Keep in sync with that file by
|
|
29
|
+
* hand; it changes rarely.
|
|
30
|
+
*/
|
|
31
|
+
const ALEX_IGNORE_PATTERNS = [
|
|
32
|
+
".github/*",
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
];
|
|
36
|
+
// src/lint/editorconfig-checker-exclude/editorconfig-checker-exclude.ts
|
|
37
|
+
/**
|
|
38
|
+
* The paths editorconfig-checker skips, read from the same
|
|
39
|
+
* `editorconfig-checker.json` template `holocron repo setup` writes as a repo's
|
|
40
|
+
* `.editorconfig-checker.json` — so Sentinel's central editorconfig check
|
|
41
|
+
* (holocron#927) excludes exactly what CI's editorconfig-checker does, from
|
|
42
|
+
* one source.
|
|
43
|
+
*
|
|
44
|
+
* The exclusion that matters most is `\.md$` / `\.mdx$`: the generated
|
|
45
|
+
* `.editorconfig` gives every file tab indentation, but
|
|
46
|
+
* `@theholocron/prettier-config` formats markdown with spaces, so a README's
|
|
47
|
+
* indented code example would fail one tool or the other. Markdown is left
|
|
48
|
+
* to prettier and markdownlint.
|
|
49
|
+
*
|
|
50
|
+
* Each entry is a regular-expression source, matched against a
|
|
51
|
+
* repo-relative path, as editorconfig-checker itself treats them.
|
|
52
|
+
*/
|
|
53
|
+
const EDITORCONFIG_CHECKER_EXCLUDE = editorconfig_checker_default.Exclude;
|
|
54
|
+
// src/lint/is-editorconfig-excluded/is-editorconfig-excluded.ts
|
|
55
|
+
/** `true` when `path` matches any {@link EDITORCONFIG_CHECKER_EXCLUDE} pattern. */
|
|
56
|
+
function isEditorConfigExcluded(path) {
|
|
57
|
+
return EDITORCONFIG_CHECKER_EXCLUDE.some((pattern) => new RegExp(pattern).test(path));
|
|
58
|
+
}
|
|
59
|
+
// src/lint/lint-message/lint-message.ts
|
|
60
|
+
/**
|
|
61
|
+
* Lints one commit message string against an already-loaded commitlint
|
|
62
|
+
* config. The genuinely environment-independent half of commit-message
|
|
63
|
+
* linting (holocron#789) — *obtaining* a `QualifiedConfig` differs by
|
|
64
|
+
* caller (Sentinel isolates itself from any ambient config since it runs
|
|
65
|
+
* standalone, away from a real repo checkout; `lintCommitMsgFile` below
|
|
66
|
+
* lets cosmiconfig discover the invoking repo's own
|
|
67
|
+
* `commitlint.config.*`, matching `commitlint --edit`'s own contract) —
|
|
68
|
+
* but linting one message against a loaded config is identical either way.
|
|
69
|
+
*
|
|
70
|
+
* Real `@commitlint/lint` — the same programmatic API `@commitlint/cli`
|
|
71
|
+
* itself uses internally — never a reimplementation of commitlint's rules.
|
|
72
|
+
*/
|
|
73
|
+
/** `parserPreset.parserOpts`, if the loaded config sets one — same lookup `@commitlint/cli`'s own `selectParserOpts()` does. */
|
|
74
|
+
function selectParserOpts(parserPreset) {
|
|
75
|
+
return parserPreset?.parserOpts;
|
|
76
|
+
}
|
|
77
|
+
async function lintCommitMessage(message, loaded) {
|
|
78
|
+
const opts = {
|
|
79
|
+
/* istanbul ignore next -- see comment above */
|
|
80
|
+
parserOpts: selectParserOpts(loaded.parserPreset) ?? {},
|
|
81
|
+
plugins: loaded.plugins,
|
|
82
|
+
/* istanbul ignore next -- see comment above */
|
|
83
|
+
ignores: loaded.ignores ?? [],
|
|
84
|
+
defaultIgnores: loaded.defaultIgnores !== false
|
|
85
|
+
};
|
|
86
|
+
const outcome = await lint(message, loaded.rules, opts);
|
|
87
|
+
if (outcome.valid) return [];
|
|
88
|
+
return outcome.errors.map((error) => ({
|
|
89
|
+
rule: error.name,
|
|
90
|
+
message: error.message
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
// src/lint/lint-commit-msg-file/lint-commit-msg-file.ts
|
|
94
|
+
/**
|
|
95
|
+
* `holocron run lint commit-msg <file>` — a real programmatic replacement for
|
|
96
|
+
* shelling out to `commitlint --edit "$1"` from `.husky/commit-msg`
|
|
97
|
+
* (holocron#789). Matches that CLI's own contract exactly: `file` is a
|
|
98
|
+
* path to the commit message being written (the arg git's `commit-msg`
|
|
99
|
+
* hook passes as `$1`), no `--config` override needed — `@commitlint/load`
|
|
100
|
+
* runs from `cwd` with no seed, so cosmiconfig's own normal upward search
|
|
101
|
+
* discovers the invoking repo's real `commitlint.config.*` file, exactly
|
|
102
|
+
* as `commitlint --edit` (no `--config` flag) already does today. Unlike
|
|
103
|
+
* Sentinel's `loadIsolatedConfig()`, no isolation is needed here — this
|
|
104
|
+
* runs inside a real repo checkout with a real `node_modules`, not
|
|
105
|
+
* standalone on a server.
|
|
106
|
+
*/
|
|
107
|
+
async function lintCommitMsgFile(filePath, cwd = process.cwd()) {
|
|
108
|
+
const violations = await lintCommitMessage(await readFile(filePath, "utf8"), await load({}, { cwd }));
|
|
109
|
+
return {
|
|
110
|
+
valid: violations.length === 0,
|
|
111
|
+
violations
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// src/lint/prettier-ignore-patterns/prettier-ignore-patterns.ts
|
|
115
|
+
/**
|
|
116
|
+
* The org's canonical prettier ignore-pattern list for a central Sentinel
|
|
117
|
+
* check (holocron#769/#819) — the `PRETTIER_CONFIG` object itself doesn't
|
|
118
|
+
* need a home here, since `@theholocron/prettier-config`'s default export
|
|
119
|
+
* already *is* one canonical, importable config (the same "one config,
|
|
120
|
+
* not N copies" reasoning `@theholocron/commitlint-config` established for
|
|
121
|
+
* commit-message linting, and `ALEX_CONFIG` established for inclusive
|
|
122
|
+
* language) — only the ignore list is a Sentinel-specific decision that
|
|
123
|
+
* belongs alongside `ALEX_IGNORE_PATTERNS`, not inside the config package.
|
|
124
|
+
*
|
|
125
|
+
* Reuses `ALEX_IGNORE_PATTERNS`' own entries (`.github/*`, `CHANGELOG.md`,
|
|
126
|
+
* `LICENSE` all independently confirmed to fail a real `prettier.check()`
|
|
127
|
+
* today — machine-generated or unparseable content, same reasoning that
|
|
128
|
+
* excluded them from alex), plus `pnpm-lock.yaml` — prettier-specific
|
|
129
|
+
* (alex never reads a lockfile, but prettier would try to reformat it):
|
|
130
|
+
* machine-written by pnpm's own writer, and not gitignored (lockfiles are
|
|
131
|
+
* tracked), so prettier picks it up by default. Reformatting it
|
|
132
|
+
* fights every subsequent `pnpm install` (this repo's own `.prettierignore`
|
|
133
|
+
* already excludes it for that exact reason).
|
|
134
|
+
*/
|
|
135
|
+
const PRETTIER_IGNORE_PATTERNS = [...ALEX_IGNORE_PATTERNS, "pnpm-lock.yaml"];
|
|
136
|
+
export { ALEX_CONFIG, ALEX_IGNORE_PATTERNS, EDITORCONFIG_CHECKER_EXCLUDE, PRETTIER_IGNORE_PATTERNS, isEditorConfigExcluded, lintCommitMessage, lintCommitMsgFile };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { loadLayered } from "@theholocron/datapad";
|
|
2
|
+
// src/config/coerce-tasks/coerce-tasks.ts
|
|
3
|
+
/** A bare item array is shorthand for `{ tasks: [...] }`. */
|
|
4
|
+
function coerceTasks(value) {
|
|
5
|
+
if (value == null) return void 0;
|
|
6
|
+
return Array.isArray(value) ? { tasks: value } : value;
|
|
7
|
+
}
|
|
8
|
+
// src/config/load/load.ts
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the task manifest for a repo: the `tasks` key of
|
|
11
|
+
* `holocron.config.*`, then a dedicated `astromech.config.*` merged on
|
|
12
|
+
* top (dedicated wins; item arrays concatenate). Returns `{}` when
|
|
13
|
+
* neither source is present.
|
|
14
|
+
*
|
|
15
|
+
* `walkUp: true` — `holocron run`/`ci` are usable from any subdirectory of
|
|
16
|
+
* a repo, not only its exact root (datapad walks up to the nearest `.git`
|
|
17
|
+
* boundary; see `@theholocron/datapad`'s own doc comment).
|
|
18
|
+
*
|
|
19
|
+
* A caller that has already loaded `holocron.config.*` passes it as
|
|
20
|
+
* `options.holocron` so it is not found and loaded again.
|
|
21
|
+
*/
|
|
22
|
+
async function loadTasksConfig(cwd, options = {}) {
|
|
23
|
+
return (await loadLayered({
|
|
24
|
+
cwd,
|
|
25
|
+
name: "astromech",
|
|
26
|
+
walkUp: true,
|
|
27
|
+
fallback: {
|
|
28
|
+
file: "holocron",
|
|
29
|
+
key: "tasks",
|
|
30
|
+
preloaded: options.holocron
|
|
31
|
+
},
|
|
32
|
+
coerce: (raw) => coerceTasks(raw)
|
|
33
|
+
}))?.config ?? {};
|
|
34
|
+
}
|
|
35
|
+
export { coerceTasks as n, loadTasksConfig as t };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { r as TasksConfig } from "../schema.type-B28guVbH.mjs";
|
|
2
|
+
import { defineConfig } from "@theholocron/semantic-release-config";
|
|
3
|
+
/** Runs `git` with `args` in `cwd`, feeding it `input` on stdin, and returns stdout. */
|
|
4
|
+
export type GitRun = (args: string[], input: string, cwd: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
* The repo-relative files each of `hashes` changed, from one
|
|
7
|
+
* `git diff-tree --stdin` call. A commit that changes nothing (or a merge
|
|
8
|
+
* commit) maps to `[]`. Paths come back verbatim, not quoted, whatever they
|
|
9
|
+
* contain.
|
|
10
|
+
*/
|
|
11
|
+
export declare function commitFiles(cwd: string, hashes: readonly string[], run?: GitRun): Map<string, string[]>;
|
|
12
|
+
/** The slice of a semantic-release commit this module reads. */
|
|
13
|
+
interface ReleaseCommit {
|
|
14
|
+
/** Full commit hash. */
|
|
15
|
+
hash: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/** The slice of a semantic-release plugin context this module reads; everything else passes through untouched. */
|
|
19
|
+
interface ReleaseContext {
|
|
20
|
+
cwd?: string;
|
|
21
|
+
commits?: ReleaseCommit[];
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
/** A semantic-release plugin step that looks at commits. */
|
|
25
|
+
type CommitStep = "analyzeCommits" | "generateNotes" | "success";
|
|
26
|
+
type StepFn = (pluginConfig: unknown, context: ReleaseContext) => unknown;
|
|
27
|
+
/** A plugin module that implements `Step`. */
|
|
28
|
+
type StepPlugin<Step extends CommitStep> = Partial<Record<Step, StepFn>>;
|
|
29
|
+
interface FolderScopedDeps {
|
|
30
|
+
/**
|
|
31
|
+
* Loads a plugin module by specifier, resolved from `cwd` (the repo being released). Defaults to a
|
|
32
|
+
* dynamic `import()` of the module as `cwd` resolves it, which is how semantic-release loads its own plugins.
|
|
33
|
+
*/
|
|
34
|
+
load?: (specifier: string, cwd: string) => Promise<unknown>;
|
|
35
|
+
/** Lists the files each commit changed. Defaults to `git diff-tree`. */
|
|
36
|
+
listFiles?: typeof commitFiles;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An inline semantic-release plugin that runs `step` of the stock plugin
|
|
40
|
+
* (`@semantic-release/commit-analyzer` for `analyzeCommits`,
|
|
41
|
+
* `@semantic-release/release-notes-generator` for `generateNotes`) over only
|
|
42
|
+
* the commits that changed a file at or under `paths`.
|
|
43
|
+
*
|
|
44
|
+
* After a monorepo import, `lastTag..HEAD` spans every folder's commits, so an
|
|
45
|
+
* unscoped analyzer would release a folder for a commit that never touched it.
|
|
46
|
+
* The wrapped plugin is loaded on first use, so it only needs to be installed
|
|
47
|
+
* where a release actually runs. Commits are listed with one `git diff-tree`
|
|
48
|
+
* call, in `context.cwd`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function folderScoped<Step extends CommitStep>(step: Step, paths: readonly string[], deps?: FolderScopedDeps): StepPlugin<Step>;
|
|
51
|
+
/**
|
|
52
|
+
* The mirror of {@link folderScoped}, for the release of everything that is in **no**
|
|
53
|
+
* version group: it sees only commits that changed a file outside every group folder. A commit
|
|
54
|
+
* confined to a group (and the group's imported history) belongs to that group's release; letting the
|
|
55
|
+
* repo-wide one analyze it would release the repo for a change that is not in it, and write the
|
|
56
|
+
* group's commits into the repo's changelog.
|
|
57
|
+
*/
|
|
58
|
+
export declare function ungroupedScoped<Step extends CommitStep>(step: Step, groups: readonly string[], deps?: FolderScopedDeps): StepPlugin<Step>;
|
|
59
|
+
/** The file `specifier` resolves to for the repo at `cwd`, else for `semantic-release`; `requireFrom` is a seam for tests. */
|
|
60
|
+
export declare function resolvePlugin(specifier: string, cwd: string, requireFrom?: (file: string) => {
|
|
61
|
+
resolve(id: string): string;
|
|
62
|
+
}): string;
|
|
63
|
+
/**
|
|
64
|
+
* Splits the GitHub plugin's entry so its "released in…" comments and labels go only to the PRs and
|
|
65
|
+
* issues of the commits `scoped` keeps. The entry stays as it was, so it still publishes the GitHub
|
|
66
|
+
* release, but with the commenting turned off; `scoped` (a {@link folderScoped} or
|
|
67
|
+
* {@link ungroupedScoped} `success` step) then does the commenting with the entry's own config.
|
|
68
|
+
*/
|
|
69
|
+
export declare function commentOnlyFor(entry: string | [string, Record<string, unknown> | undefined], scoped: StepPlugin<"success">): ((string | [string, Record<string, unknown> | undefined]) | [object, unknown])[];
|
|
70
|
+
/** What `defineConfig()` from `@theholocron/semantic-release-config` accepts. */
|
|
71
|
+
type DefineConfigOptions = NonNullable<Parameters<typeof defineConfig>[0]>;
|
|
72
|
+
interface GroupReleaseOptions extends DefineConfigOptions {
|
|
73
|
+
/**
|
|
74
|
+
* The version group: a folder of the repo (`clients`, `observability`, `cli`) that
|
|
75
|
+
* releases on its own. It prefixes the tags (`clients-v1.43.2`) and the release commit.
|
|
76
|
+
*/
|
|
77
|
+
group: string;
|
|
78
|
+
/** Repo-relative folders whose commits release this group. Defaults to `[group]`. */
|
|
79
|
+
paths?: readonly string[];
|
|
80
|
+
/** The group's changelog. Defaults to `<group>/CHANGELOG.md`. */
|
|
81
|
+
changelogFile?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A semantic-release config that releases one version group of a monorepo,
|
|
85
|
+
* built on the org's `defineConfig()` so its rules, notes layout and plugin
|
|
86
|
+
* order stay the same:
|
|
87
|
+
*
|
|
88
|
+
* - tags are `<group>-v<version>`, so each group finds its own last release;
|
|
89
|
+
* - the commit analyzer and notes generator see only commits that touched the
|
|
90
|
+
* group's `paths` ({@link folderScoped});
|
|
91
|
+
* - the changelog, the release commit's assets and its message are the group's.
|
|
92
|
+
*
|
|
93
|
+
* Run one `semantic-release` per group. Cross-group dependencies resolve from
|
|
94
|
+
* the registry, so `paths` is the group's folder unless more is listed.
|
|
95
|
+
*/
|
|
96
|
+
export declare function groupReleaseConfig(options: GroupReleaseOptions): object;
|
|
97
|
+
/**
|
|
98
|
+
* Whether any of `files` (repo-relative, `/`-separated) sits at or under one of
|
|
99
|
+
* `paths` (repo-relative folders). `clients` matches `clients/http/x.ts` but
|
|
100
|
+
* not `clients-old/x.ts`.
|
|
101
|
+
*/
|
|
102
|
+
export declare function inScope(files: readonly string[], paths: readonly string[]): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether any of `files` sits **outside** every one of `folders`: the mirror of
|
|
105
|
+
* {@link inScope}. A commit that only touches the version groups' folders is out;
|
|
106
|
+
* one that touches anything else, even beside a group's files, is in.
|
|
107
|
+
*/
|
|
108
|
+
export declare function outsideFolders(files: readonly string[], folders: readonly string[]): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The version groups a repo releases on their own: the folder names listed under `groups`
|
|
111
|
+
* in its `delivery.publish` task. This is what the generated publish workflow reads, so a
|
|
112
|
+
* release config that asks here stays in step with it instead of keeping a second list.
|
|
113
|
+
* `[]` for a repo that releases as one.
|
|
114
|
+
*/
|
|
115
|
+
export declare function releaseGroups(config: Pick<TasksConfig, "tasks">): string[];
|
|
116
|
+
interface UngroupedReleaseOptions extends DefineConfigOptions {
|
|
117
|
+
/** The version groups released on their own: folders of the repo whose commits this release ignores. */
|
|
118
|
+
groups: readonly string[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The semantic-release config for everything that is in no version group, built on the org's
|
|
122
|
+
* `defineConfig()`: tags, changelog and release commit are the repo's own, as before. The commit
|
|
123
|
+
* analyzer and notes generator skip commits confined to the `groups` folders, because those
|
|
124
|
+
* belong to the groups' releases ({@link ungroupedScoped}). With no groups it is `defineConfig()`
|
|
125
|
+
* unchanged.
|
|
126
|
+
*/
|
|
127
|
+
export declare function ungroupedReleaseConfig({ groups, ...options }: UngroupedReleaseOptions): object;
|
|
128
|
+
export type { CommitStep, DefineConfigOptions, FolderScopedDeps, GroupReleaseOptions, ReleaseCommit, ReleaseContext, StepPlugin, UngroupedReleaseOptions };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { t as normalizeTaskEntry } from "../schema-CalPyBNd.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { defineConfig } from "@theholocron/semantic-release-config";
|
|
7
|
+
// src/release/commit-files/commit-files.ts
|
|
8
|
+
const defaultGitRun = (args, input, cwd) => execFileSync("git", args, {
|
|
9
|
+
cwd,
|
|
10
|
+
input,
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
maxBuffer: 268435456
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* The repo-relative files each of `hashes` changed, from one
|
|
16
|
+
* `git diff-tree --stdin` call. A commit that changes nothing (or a merge
|
|
17
|
+
* commit) maps to `[]`. Paths come back verbatim, not quoted, whatever they
|
|
18
|
+
* contain.
|
|
19
|
+
*/
|
|
20
|
+
function commitFiles(cwd, hashes, run = defaultGitRun) {
|
|
21
|
+
const files = new Map(hashes.map((hash) => [hash, []]));
|
|
22
|
+
if (hashes.length === 0) return files;
|
|
23
|
+
const out = run([
|
|
24
|
+
"-c",
|
|
25
|
+
"core.quotePath=false",
|
|
26
|
+
"diff-tree",
|
|
27
|
+
"--stdin",
|
|
28
|
+
"--name-only",
|
|
29
|
+
"-r",
|
|
30
|
+
"--root"
|
|
31
|
+
], `${hashes.join("\n")}\n`, cwd);
|
|
32
|
+
let current;
|
|
33
|
+
for (const line of out.split("\n")) {
|
|
34
|
+
if (line === "") continue;
|
|
35
|
+
const known = files.get(line);
|
|
36
|
+
if (known) current = known;
|
|
37
|
+
else current?.push(line);
|
|
38
|
+
}
|
|
39
|
+
return files;
|
|
40
|
+
}
|
|
41
|
+
// src/release/in-scope/in-scope.ts
|
|
42
|
+
/**
|
|
43
|
+
* Whether any of `files` (repo-relative, `/`-separated) sits at or under one of
|
|
44
|
+
* `paths` (repo-relative folders). `clients` matches `clients/http/x.ts` but
|
|
45
|
+
* not `clients-old/x.ts`.
|
|
46
|
+
*/
|
|
47
|
+
function inScope(files, paths) {
|
|
48
|
+
const folders = paths.map((path) => path.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
49
|
+
return files.some((file) => folders.some((folder) => file === folder || file.startsWith(`${folder}/`)));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether any of `files` sits **outside** every one of `folders`: the mirror of
|
|
53
|
+
* {@link inScope}. A commit that only touches the version groups' folders is out;
|
|
54
|
+
* one that touches anything else, even beside a group's files, is in.
|
|
55
|
+
*/
|
|
56
|
+
function outsideFolders(files, folders) {
|
|
57
|
+
const normalized = folders.map((folder) => folder.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
58
|
+
return files.some((file) => !normalized.some((folder) => file === folder || file.startsWith(`${folder}/`)));
|
|
59
|
+
}
|
|
60
|
+
// src/release/folder-scoped/folder-scoped.ts
|
|
61
|
+
/** The semantic-release plugin that implements each commit-reading step. `success` is the GitHub plugin's "released in…" comments. */
|
|
62
|
+
const MODULES = {
|
|
63
|
+
analyzeCommits: "@semantic-release/commit-analyzer",
|
|
64
|
+
generateNotes: "@semantic-release/release-notes-generator",
|
|
65
|
+
success: "@semantic-release/github"
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* An inline semantic-release plugin that runs `step` of the stock plugin
|
|
69
|
+
* (`@semantic-release/commit-analyzer` for `analyzeCommits`,
|
|
70
|
+
* `@semantic-release/release-notes-generator` for `generateNotes`) over only
|
|
71
|
+
* the commits that changed a file at or under `paths`.
|
|
72
|
+
*
|
|
73
|
+
* After a monorepo import, `lastTag..HEAD` spans every folder's commits, so an
|
|
74
|
+
* unscoped analyzer would release a folder for a commit that never touched it.
|
|
75
|
+
* The wrapped plugin is loaded on first use, so it only needs to be installed
|
|
76
|
+
* where a release actually runs. Commits are listed with one `git diff-tree`
|
|
77
|
+
* call, in `context.cwd`.
|
|
78
|
+
*/
|
|
79
|
+
function folderScoped(step, paths, deps = {}) {
|
|
80
|
+
return scopedBy(step, (files) => inScope(files, paths), deps);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The mirror of {@link folderScoped}, for the release of everything that is in **no**
|
|
84
|
+
* version group: it sees only commits that changed a file outside every group folder. A commit
|
|
85
|
+
* confined to a group (and the group's imported history) belongs to that group's release; letting the
|
|
86
|
+
* repo-wide one analyze it would release the repo for a change that is not in it, and write the
|
|
87
|
+
* group's commits into the repo's changelog.
|
|
88
|
+
*/
|
|
89
|
+
function ungroupedScoped(step, groups, deps = {}) {
|
|
90
|
+
return scopedBy(step, (files) => outsideFolders(files, groups), deps);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* `import()` of `specifier` the way semantic-release finds its own plugins: as the repo at `cwd` resolves it,
|
|
94
|
+
* else as `semantic-release` does (the stock plugins are its dependencies, not the repo's). A bare `import()`
|
|
95
|
+
* would resolve from this file, inside astromech, where neither is visible.
|
|
96
|
+
*/
|
|
97
|
+
function importFrom(specifier, cwd) {
|
|
98
|
+
return import(pathToFileURL(resolvePlugin(specifier, cwd)).href);
|
|
99
|
+
}
|
|
100
|
+
/** The file `specifier` resolves to for the repo at `cwd`, else for `semantic-release`; `requireFrom` is a seam for tests. */
|
|
101
|
+
function resolvePlugin(specifier, cwd, requireFrom = createRequire) {
|
|
102
|
+
const fromRepo = requireFrom(join(cwd, "package.json"));
|
|
103
|
+
try {
|
|
104
|
+
return fromRepo.resolve(specifier);
|
|
105
|
+
} catch {
|
|
106
|
+
return requireFrom(fromRepo.resolve("semantic-release")).resolve(specifier);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function scopedBy(step, keep, { load = importFrom, listFiles = commitFiles }) {
|
|
110
|
+
const scoped = async (pluginConfig, context) => {
|
|
111
|
+
const { commits = [], cwd = process.cwd() } = context;
|
|
112
|
+
const inner = await load(MODULES[step], cwd);
|
|
113
|
+
const files = listFiles(cwd, commits.map((commit) => commit.hash));
|
|
114
|
+
const kept = commits.filter((commit) => keep(files.get(commit.hash) ?? []));
|
|
115
|
+
return inner[step]?.(pluginConfig, {
|
|
116
|
+
...context,
|
|
117
|
+
commits: kept
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
return { [step]: scoped };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Splits the GitHub plugin's entry so its "released in…" comments and labels go only to the PRs and
|
|
124
|
+
* issues of the commits `scoped` keeps. The entry stays as it was, so it still publishes the GitHub
|
|
125
|
+
* release, but with the commenting turned off; `scoped` (a {@link folderScoped} or
|
|
126
|
+
* {@link ungroupedScoped} `success` step) then does the commenting with the entry's own config.
|
|
127
|
+
*/
|
|
128
|
+
function commentOnlyFor(entry, scoped) {
|
|
129
|
+
const [name, config] = Array.isArray(entry) ? entry : [entry, void 0];
|
|
130
|
+
return [[name, {
|
|
131
|
+
...config,
|
|
132
|
+
successComment: false,
|
|
133
|
+
releasedLabels: false
|
|
134
|
+
}], [scoped, config]];
|
|
135
|
+
}
|
|
136
|
+
// src/release/group-release-config/group-release-config.ts
|
|
137
|
+
const GROUP = /^[a-z][a-z0-9-]*$/;
|
|
138
|
+
/**
|
|
139
|
+
* A semantic-release config that releases one version group of a monorepo,
|
|
140
|
+
* built on the org's `defineConfig()` so its rules, notes layout and plugin
|
|
141
|
+
* order stay the same:
|
|
142
|
+
*
|
|
143
|
+
* - tags are `<group>-v<version>`, so each group finds its own last release;
|
|
144
|
+
* - the commit analyzer and notes generator see only commits that touched the
|
|
145
|
+
* group's `paths` ({@link folderScoped});
|
|
146
|
+
* - the changelog, the release commit's assets and its message are the group's.
|
|
147
|
+
*
|
|
148
|
+
* Run one `semantic-release` per group. Cross-group dependencies resolve from
|
|
149
|
+
* the registry, so `paths` is the group's folder unless more is listed.
|
|
150
|
+
*/
|
|
151
|
+
function groupReleaseConfig(options) {
|
|
152
|
+
const { group, paths = [group], changelogFile = `${group}/CHANGELOG.md`, assets, ...rest } = options;
|
|
153
|
+
if (!GROUP.test(group)) throw new TypeError(`release group must be a lowercase folder name like "clients", got ${JSON.stringify(group)}`);
|
|
154
|
+
if (paths.length === 0) throw new TypeError(`release group ${JSON.stringify(group)} needs at least one path`);
|
|
155
|
+
const base = defineConfig({
|
|
156
|
+
...rest,
|
|
157
|
+
assets: assets ?? [
|
|
158
|
+
changelogFile,
|
|
159
|
+
`${group}/**/package.json`,
|
|
160
|
+
"!**/node_modules/**"
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
const scope = (entry) => {
|
|
164
|
+
const [name, config] = Array.isArray(entry) ? entry : [entry, void 0];
|
|
165
|
+
switch (name) {
|
|
166
|
+
case "@semantic-release/commit-analyzer": return [[folderScoped("analyzeCommits", paths), config]];
|
|
167
|
+
case "@semantic-release/release-notes-generator": return [[folderScoped("generateNotes", paths), config]];
|
|
168
|
+
case "@semantic-release/changelog": return [[name, {
|
|
169
|
+
...config,
|
|
170
|
+
changelogFile
|
|
171
|
+
}]];
|
|
172
|
+
case "@semantic-release/git": return [[name, {
|
|
173
|
+
...config,
|
|
174
|
+
message: groupMessage(config?.["message"], group)
|
|
175
|
+
}]];
|
|
176
|
+
case "@semantic-release/github": return commentOnlyFor(entry, folderScoped("success", paths));
|
|
177
|
+
default: return [entry];
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
...base,
|
|
182
|
+
tagFormat: `${group}-v\${version}`,
|
|
183
|
+
plugins: base.plugins.flatMap(scope)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** `chore(release): <version> …` becomes `chore(release): <group> <version> …`. */
|
|
187
|
+
function groupMessage(message, group) {
|
|
188
|
+
return message.replace(/^chore\(release\): /, `chore(release): ${group} `);
|
|
189
|
+
}
|
|
190
|
+
// src/release/release-groups/release-groups.ts
|
|
191
|
+
/**
|
|
192
|
+
* The version groups a repo releases on their own: the folder names listed under `groups`
|
|
193
|
+
* in its `delivery.publish` task. This is what the generated publish workflow reads, so a
|
|
194
|
+
* release config that asks here stays in step with it instead of keeping a second list.
|
|
195
|
+
* `[]` for a repo that releases as one.
|
|
196
|
+
*/
|
|
197
|
+
function releaseGroups(config) {
|
|
198
|
+
const groups = (config.tasks ?? []).map(normalizeTaskEntry).find((entry) => entry.name === "delivery.publish")?.with?.["groups"];
|
|
199
|
+
if (!Array.isArray(groups)) return [];
|
|
200
|
+
return groups.flatMap((group) => {
|
|
201
|
+
const name = typeof group === "string" ? group : group?.name;
|
|
202
|
+
return typeof name === "string" ? [name] : [];
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// src/release/ungrouped-release-config/ungrouped-release-config.ts
|
|
206
|
+
/**
|
|
207
|
+
* The semantic-release config for everything that is in no version group, built on the org's
|
|
208
|
+
* `defineConfig()`: tags, changelog and release commit are the repo's own, as before. The commit
|
|
209
|
+
* analyzer and notes generator skip commits confined to the `groups` folders, because those
|
|
210
|
+
* belong to the groups' releases ({@link ungroupedScoped}). With no groups it is `defineConfig()`
|
|
211
|
+
* unchanged.
|
|
212
|
+
*/
|
|
213
|
+
function ungroupedReleaseConfig({ groups, ...options }) {
|
|
214
|
+
const base = defineConfig(options);
|
|
215
|
+
if (groups.length === 0) return base;
|
|
216
|
+
const scope = (entry) => {
|
|
217
|
+
const [name, config] = Array.isArray(entry) ? entry : [entry, void 0];
|
|
218
|
+
switch (name) {
|
|
219
|
+
case "@semantic-release/commit-analyzer": return [[ungroupedScoped("analyzeCommits", groups), config]];
|
|
220
|
+
case "@semantic-release/release-notes-generator": return [[ungroupedScoped("generateNotes", groups), config]];
|
|
221
|
+
case "@semantic-release/github": return commentOnlyFor(entry, ungroupedScoped("success", groups));
|
|
222
|
+
default: return [entry];
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
return {
|
|
226
|
+
...base,
|
|
227
|
+
plugins: base.plugins.flatMap(scope)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export { commentOnlyFor, commitFiles, folderScoped, groupReleaseConfig, inScope, outsideFolders, releaseGroups, resolvePlugin, ungroupedReleaseConfig, ungroupedScoped };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/config/schema/schema.ts
|
|
2
|
+
/**
|
|
3
|
+
* The `tasks` config shape — the single manifest of what a repo runs.
|
|
4
|
+
* Read from a dedicated `astromech.config.*` file or the `tasks` key of
|
|
5
|
+
* `holocron.config.*` (see {@link loadTasksConfig}).
|
|
6
|
+
*
|
|
7
|
+
* Runtime validation is the loader's job, not this type's — the type only
|
|
8
|
+
* describes what an author writes.
|
|
9
|
+
*/
|
|
10
|
+
/** Normalise a `TaskConfigItem` to a full {@link TaskEntry} with defaults applied. */
|
|
11
|
+
function normalizeTaskEntry(item) {
|
|
12
|
+
return {
|
|
13
|
+
ci: true,
|
|
14
|
+
local: true,
|
|
15
|
+
...typeof item === "string" ? { name: item } : item
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export { normalizeTaskEntry as t };
|