rman 1.3.0 → 2.0.0-beta.3

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.
Files changed (187) hide show
  1. package/README.md +65 -31
  2. package/builtins/platforms/node/augmentation/rmanrc.augmentation.d.ts +83 -0
  3. package/builtins/platforms/node/augmentation/system-info.augmentation.d.ts +26 -0
  4. package/builtins/platforms/node/augmentation/system-info.augmentation.js +79 -0
  5. package/builtins/platforms/node/commands/ci.command.d.ts +133 -0
  6. package/builtins/platforms/node/commands/ci.command.js +60 -0
  7. package/builtins/platforms/node/commands/clean.command.d.ts +185 -0
  8. package/builtins/platforms/node/commands/clean.command.js +74 -0
  9. package/builtins/platforms/node/index.d.ts +8 -0
  10. package/builtins/platforms/node/index.js +8 -0
  11. package/builtins/platforms/node/node-config.interface.d.ts +76 -0
  12. package/builtins/platforms/node/node-config.interface.js +7 -0
  13. package/builtins/platforms/node/node-manifest.provider.d.ts +68 -0
  14. package/builtins/platforms/node/node-manifest.provider.js +125 -0
  15. package/builtins/platforms/node/node.platform.d.ts +53 -0
  16. package/builtins/platforms/node/node.platform.js +134 -0
  17. package/builtins/platforms/node/services/ci.service.d.ts +47 -0
  18. package/builtins/platforms/node/services/ci.service.js +213 -0
  19. package/builtins/platforms/node/services/clean.service.d.ts +53 -0
  20. package/builtins/platforms/node/services/clean.service.js +237 -0
  21. package/builtins/platforms/node/services/publish.service.d.ts +114 -0
  22. package/builtins/platforms/node/services/publish.service.js +371 -0
  23. package/builtins/platforms/node/services/version-plan.service.d.ts +44 -0
  24. package/builtins/platforms/node/services/version-plan.service.js +58 -0
  25. package/builtins/platforms/node/utils/workspace-range.d.ts +26 -0
  26. package/builtins/platforms/node/utils/workspace-range.js +28 -0
  27. package/builtins/presets/index.d.ts +15 -0
  28. package/builtins/presets/index.js +57 -0
  29. package/builtins/presets/node.d.ts +16 -0
  30. package/builtins/presets/node.js +57 -0
  31. package/{services → builtins/publish-targets/docker}/docker-publish.service.d.ts +52 -31
  32. package/{services → builtins/publish-targets/docker}/docker-publish.service.js +49 -26
  33. package/builtins/publish-targets/docker/docker.target.d.ts +54 -0
  34. package/builtins/publish-targets/docker/docker.target.js +40 -0
  35. package/builtins/publish-targets/docker/index.d.ts +2 -0
  36. package/builtins/publish-targets/docker/index.js +2 -0
  37. package/builtins/publish-targets/npm/index.d.ts +2 -0
  38. package/builtins/publish-targets/npm/index.js +2 -0
  39. package/builtins/publish-targets/npm/npm-publish-target.d.ts +73 -0
  40. package/builtins/publish-targets/npm/npm-publish-target.js +95 -0
  41. package/builtins/publish-targets/npm/npm-view.d.ts +48 -0
  42. package/builtins/publish-targets/npm/npm-view.js +71 -0
  43. package/cli.d.ts +8 -0
  44. package/cli.js +228 -93
  45. package/commands/build.command.d.ts +177 -3
  46. package/commands/build.command.js +20 -10
  47. package/commands/changelog.command.d.ts +296 -3
  48. package/commands/changelog.command.js +127 -43
  49. package/commands/config.command.d.ts +44 -3
  50. package/commands/config.command.js +53 -24
  51. package/commands/diff.command.d.ts +37 -3
  52. package/commands/diff.command.js +25 -16
  53. package/commands/exec.command.d.ts +193 -3
  54. package/commands/exec.command.js +60 -58
  55. package/commands/github-release.command.d.ts +154 -3
  56. package/commands/github-release.command.js +67 -37
  57. package/commands/import.command.d.ts +36 -3
  58. package/commands/import.command.js +28 -20
  59. package/commands/info.command.d.ts +35 -7
  60. package/commands/info.command.js +36 -30
  61. package/commands/lint.command.d.ts +176 -0
  62. package/commands/lint.command.js +34 -0
  63. package/commands/list.command.d.ts +163 -3
  64. package/commands/list.command.js +109 -71
  65. package/commands/publish.command.d.ts +231 -0
  66. package/commands/publish.command.js +304 -0
  67. package/commands/run.command.d.ts +186 -6
  68. package/commands/run.command.js +26 -72
  69. package/commands/test.command.d.ts +173 -3
  70. package/commands/test.command.js +16 -10
  71. package/commands/version.command.d.ts +330 -3
  72. package/commands/version.command.js +292 -78
  73. package/commands.d.ts +32 -0
  74. package/commands.js +28 -0
  75. package/constants.js +1 -1
  76. package/core/application.d.ts +116 -0
  77. package/core/application.js +160 -0
  78. package/core/classes/package.d.ts +219 -0
  79. package/core/classes/package.js +214 -0
  80. package/core/classes/registry.d.ts +30 -0
  81. package/core/classes/registry.js +47 -0
  82. package/core/{repository.d.ts → classes/repository.d.ts} +69 -20
  83. package/core/{repository.js → classes/repository.js} +195 -75
  84. package/core/classes/service.d.ts +49 -0
  85. package/core/classes/service.js +40 -0
  86. package/core/{version-scheme.d.ts → classes/version-scheme.d.ts} +23 -1
  87. package/core/{version-scheme.js → classes/version-scheme.js} +29 -1
  88. package/core/classes/workspace.d.ts +275 -0
  89. package/core/classes/workspace.js +537 -0
  90. package/core/command-builder.d.ts +14 -0
  91. package/core/command-builder.js +94 -0
  92. package/core/config/config-file-scope.d.ts +107 -0
  93. package/core/config/config-file-scope.js +226 -0
  94. package/core/config/config-interpolator.d.ts +164 -0
  95. package/core/config/config-interpolator.js +577 -0
  96. package/core/config/config-paths.d.ts +65 -0
  97. package/core/config/config-paths.js +78 -0
  98. package/core/config/config-reader.d.ts +192 -0
  99. package/core/config/config-reader.js +727 -0
  100. package/core/{merge-config.d.ts → config/merge-config.d.ts} +33 -34
  101. package/core/config/merge-config.js +260 -0
  102. package/core/{resolve-target.d.ts → config/resolve-config-target.d.ts} +1 -1
  103. package/core/{resolve-target.js → config/resolve-config-target.js} +1 -1
  104. package/core/{custom-command.d.ts → interfaces/custom-command.d.ts} +46 -10
  105. package/core/{custom-command.js → interfaces/custom-command.js} +44 -17
  106. package/core/{manifest.d.ts → interfaces/manifest.d.ts} +49 -27
  107. package/core/interfaces/manifest.js +132 -0
  108. package/core/interfaces/plugin.d.ts +174 -0
  109. package/core/interfaces/plugin.js +124 -0
  110. package/core/interfaces/publish-target.d.ts +136 -0
  111. package/core/interfaces/publish-target.js +43 -0
  112. package/core/{run-step.d.ts → interfaces/run-step.d.ts} +4 -4
  113. package/core/interfaces/run-step.js +1 -0
  114. package/core/plugin-loader.d.ts +25 -0
  115. package/core/plugin-loader.js +53 -0
  116. package/index.d.ts +122 -24
  117. package/index.js +66 -16
  118. package/interfaces/config-scope.interface.d.ts +223 -0
  119. package/interfaces/config-scope.interface.js +1 -0
  120. package/interfaces/rman-config.interface.d.ts +821 -203
  121. package/interfaces/rman-config.interface.js +78 -1
  122. package/package.json +3 -1
  123. package/services/change-hash.service.d.ts +42 -8
  124. package/services/change-hash.service.js +92 -13
  125. package/services/changelog.service.d.ts +91 -52
  126. package/services/changelog.service.js +460 -74
  127. package/services/config-service.d.ts +8 -0
  128. package/services/config-service.js +3 -0
  129. package/services/exec.service.d.ts +23 -12
  130. package/services/exec.service.js +14 -9
  131. package/services/github-release.service.d.ts +45 -34
  132. package/services/github-release.service.js +15 -12
  133. package/services/import.service.d.ts +25 -14
  134. package/services/import.service.js +9 -5
  135. package/services/list.service.d.ts +67 -13
  136. package/services/list.service.js +62 -15
  137. package/services/run.service.d.ts +35 -22
  138. package/services/run.service.js +316 -233
  139. package/services/system-info.d.ts +1 -1
  140. package/services/version-plan.service.d.ts +35 -8
  141. package/services/version-plan.service.js +96 -36
  142. package/services/version.service.d.ts +34 -14
  143. package/services/version.service.js +35 -16
  144. package/services.d.ts +1 -1
  145. package/services.js +1 -1
  146. package/utils/bin-path.d.ts +6 -7
  147. package/utils/bin-path.js +7 -18
  148. package/utils/branch-guard.d.ts +30 -1
  149. package/utils/branch-guard.js +31 -0
  150. package/utils/color-yaml.d.ts +8 -0
  151. package/utils/color-yaml.js +86 -0
  152. package/utils/exec.d.ts +10 -0
  153. package/utils/exec.js +1 -1
  154. package/utils/git.d.ts +26 -0
  155. package/utils/git.js +65 -0
  156. package/utils/logger.d.ts +2 -2
  157. package/utils/logger.js +1 -1
  158. package/utils/package-filter.d.ts +135 -8
  159. package/utils/package-filter.js +204 -16
  160. package/utils/printable-config.d.ts +9 -1
  161. package/utils/printable-config.js +46 -1
  162. package/utils/progress-panel.d.ts +9 -0
  163. package/utils/progress-panel.js +23 -1
  164. package/utils/release-version.d.ts +1 -1
  165. package/utils/run-bin.d.ts +10 -0
  166. package/utils/run-bin.js +1 -1
  167. package/utils/run-options.d.ts +97 -0
  168. package/utils/run-options.js +81 -0
  169. package/utils/version-group.d.ts +31 -0
  170. package/utils/version-group.js +43 -0
  171. package/utils/version-stamp.d.ts +1 -1
  172. package/utils/version-stamp.js +1 -1
  173. package/commands/changed.command.d.ts +0 -3
  174. package/commands/changed.command.js +0 -29
  175. package/core/config.d.ts +0 -409
  176. package/core/config.js +0 -939
  177. package/core/extends-config.d.ts +0 -27
  178. package/core/extends-config.js +0 -89
  179. package/core/manifest.js +0 -150
  180. package/core/merge-config.js +0 -219
  181. package/core/package.d.ts +0 -83
  182. package/core/package.js +0 -106
  183. package/core/plugin.d.ts +0 -112
  184. package/core/plugin.js +0 -189
  185. package/core/workspace.d.ts +0 -68
  186. package/core/workspace.js +0 -83
  187. /package/{core/run-step.js → builtins/platforms/node/augmentation/rmanrc.augmentation.js} +0 -0
@@ -0,0 +1,31 @@
1
+ import type { Package } from '../core/classes/package.js';
2
+ /**
3
+ * The identity packages are batched by when `version` plans a release - `.rmanrc group`, cascaded
4
+ * like every unmarked key. `true` (the default) puts a package in the implicit repo-wide group, a
5
+ * non-empty string joins exactly the packages naming the same one, and `false` makes it a group of
6
+ * itself.
7
+ *
8
+ * **It lives here rather than on the planner because two unrelated things need the same answer.**
9
+ * `VersionPlanService.resolveGroupKey` batches the plan with it; `ChangeHashService.tagPattern`
10
+ * asks how many lines the repository releases along, which decides whether a repo-wide tag can
11
+ * name a release at all. Two copies of five lines would be easy to write and impossible to keep in
12
+ * step, and the failure they would produce is silent - a boundary computed under one answer and a
13
+ * tag written under the other.
14
+ *
15
+ * `resolveGroupKey` stays `protected` and delegates here, so a planner can still override the
16
+ * batching; what it cannot do is leave the tag pattern behind, which is the point.
17
+ */
18
+ export declare function groupKeyOf(pkg: Package): string;
19
+ /**
20
+ * How many distinct version lines this package's repository releases along - 1 when every package
21
+ * moves together, more once anything is grouped apart.
22
+ *
23
+ * **Structural, exactly like `usesCalendarVersion`'s group count**, and for the same reason: two
24
+ * lines can hold the same number today and diverge tomorrow, so reading the versions would move
25
+ * the answer under the repository's feet.
26
+ *
27
+ * `1` for a package belonging to no repository yet - a bare `new Package(dir, app)`, which the test
28
+ * fixtures build. One line is the answer that changes nothing, which is what an unknown should
29
+ * resolve to here.
30
+ */
31
+ export declare function versionLineCount(pkg: Package): number;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The identity packages are batched by when `version` plans a release - `.rmanrc group`, cascaded
3
+ * like every unmarked key. `true` (the default) puts a package in the implicit repo-wide group, a
4
+ * non-empty string joins exactly the packages naming the same one, and `false` makes it a group of
5
+ * itself.
6
+ *
7
+ * **It lives here rather than on the planner because two unrelated things need the same answer.**
8
+ * `VersionPlanService.resolveGroupKey` batches the plan with it; `ChangeHashService.tagPattern`
9
+ * asks how many lines the repository releases along, which decides whether a repo-wide tag can
10
+ * name a release at all. Two copies of five lines would be easy to write and impossible to keep in
11
+ * step, and the failure they would produce is silent - a boundary computed under one answer and a
12
+ * tag written under the other.
13
+ *
14
+ * `resolveGroupKey` stays `protected` and delegates here, so a planner can still override the
15
+ * batching; what it cannot do is leave the tag pattern behind, which is the point.
16
+ */
17
+ export function groupKeyOf(pkg) {
18
+ const g = pkg.config?.group;
19
+ if (g === false)
20
+ return `solo:${pkg.name}`;
21
+ if (typeof g === 'string' && g)
22
+ return `named:${g}`;
23
+ return 'default';
24
+ }
25
+ /**
26
+ * How many distinct version lines this package's repository releases along - 1 when every package
27
+ * moves together, more once anything is grouped apart.
28
+ *
29
+ * **Structural, exactly like `usesCalendarVersion`'s group count**, and for the same reason: two
30
+ * lines can hold the same number today and diverge tomorrow, so reading the versions would move
31
+ * the answer under the repository's feet.
32
+ *
33
+ * `1` for a package belonging to no repository yet - a bare `new Package(dir, app)`, which the test
34
+ * fixtures build. One line is the answer that changes nothing, which is what an unknown should
35
+ * resolve to here.
36
+ */
37
+ export function versionLineCount(pkg) {
38
+ const repository = pkg.repository;
39
+ const packages = repository?.packages;
40
+ if (!packages?.length)
41
+ return 1;
42
+ return new Set(packages.map(groupKeyOf)).size;
43
+ }
@@ -29,7 +29,7 @@ export declare function stampVersionLabel(content: string, version: string): str
29
29
  * ```
30
30
  *
31
31
  * **A helper, not a policy**: which shape a language declares a version in is
32
- * `ManifestProvider.stampVersion`'s answer, and this is the one most of them share, exported so
32
+ * `Plugin.stampVersion`'s answer, and this is the one most of them share, exported so
33
33
  * every provider need not re-derive the same regex. Measured, it reaches a Go `const version =
34
34
  * "…"`, a Gradle/TOML `version = "…"` and a JS/TS `const version = '…'`.
35
35
  *
@@ -51,7 +51,7 @@ export function stampVersionLabel(content, version) {
51
51
  * ```
52
52
  *
53
53
  * **A helper, not a policy**: which shape a language declares a version in is
54
- * `ManifestProvider.stampVersion`'s answer, and this is the one most of them share, exported so
54
+ * `Plugin.stampVersion`'s answer, and this is the one most of them share, exported so
55
55
  * every provider need not re-derive the same regex. Measured, it reaches a Go `const version =
56
56
  * "…"`, a Gradle/TOML `version = "…"` and a JS/TS `const version = '…'`.
57
57
  *
@@ -1,3 +0,0 @@
1
- import type { Argv } from 'yargs';
2
- import type { Repository } from '../core/repository.js';
3
- export declare function initCli(repository: Repository, program: Argv): void;
@@ -1,29 +0,0 @@
1
- import colors from 'ansi-colors';
2
- import { VersionPlanService } from '../services/version-plan.service.js';
3
- import { applyPackageFilterOptions, readPackageFilterOptions } from '../utils/package-filter.js';
4
- export function initCli(repository, program) {
5
- program.command({
6
- command: 'changed',
7
- describe: 'Shows which packages the next "version" run would bump, without changing anything',
8
- builder: cmd => applyPackageFilterOptions(cmd).example('$0 changed', '').example('$0 changed --json', '').option('json', {
9
- alias: 'j',
10
- describe: 'Print output as JSON',
11
- type: 'boolean',
12
- }),
13
- handler: async (args) => {
14
- const plan = await VersionPlanService.getPlanner().getPlan(repository, readPackageFilterOptions(args));
15
- const changed = plan.filter(e => e.status === 'bump');
16
- if (args.json) {
17
- console.log(JSON.stringify(changed.map(e => ({ name: e.package.name, group: e.group, from: e.from, to: e.to, reason: e.reason })), undefined, 2));
18
- return;
19
- }
20
- if (!changed.length) {
21
- console.log(colors.gray('Nothing has changed.'));
22
- return;
23
- }
24
- for (const e of changed) {
25
- console.log(colors.green('changed'), colors.cyan(e.package.name), colors.gray(`(${e.group})`), e.from, '->', colors.yellow(e.to));
26
- }
27
- },
28
- });
29
- }
package/core/config.d.ts DELETED
@@ -1,409 +0,0 @@
1
- import path from 'path';
2
- import semver from 'semver';
3
- import type { RmanConfig } from '../interfaces/rman-config.interface.js';
4
- /**
5
- * Identity helper for authoring a `.rmanrc.cjs`/`.mjs`/`.js` config with full type-checking and
6
- * autocomplete - the same `defineConfig` pattern Vite/Vitest use. Returns `config` completely
7
- * unchanged; this exists purely so TypeScript can infer/check against `RmanConfig`, not for any
8
- * runtime behavior:
9
- *
10
- * // .rmanrc.mjs
11
- * import { defineConfig } from 'rman';
12
- * export default defineConfig({ packageManager: 'pnpm' });
13
- *
14
- * // .rmanrc.cjs
15
- * const { defineConfig } = require('rman');
16
- * module.exports = defineConfig({ packageManager: 'pnpm' });
17
- */
18
- export declare function defineConfig(config: RmanConfig): RmanConfig;
19
- /**
20
- * Reads the rman configuration defined at a single directory level, merging
21
- * (in increasing precedence): `package.json#rman`, `.rmanrc.yml`, `.rmanrc`,
22
- * then `.rmanrc.cjs`/`.rmanrc.mjs`/`.rmanrc.js` (whichever exist, in that order).
23
- */
24
- export declare function readDirConfig(dirname: string): Promise<RmanConfig>;
25
- /**
26
- * Resolves the effective config for the package at `targetDir`, cascading from `rootDir` down to
27
- * it (inclusive) - each directory level overrides the ones above it, the way tsconfig's `extends`
28
- * chain does.
29
- *
30
- * Every level contributes in two ways:
31
- *
32
- * - **An unmarked key configures that directory and every package under it.** What a parent says
33
- * reaches the children, which is what every directory-scoped config in the ecosystem does and
34
- * what a reader expects without being told.
35
- * - **A `"[selector]"` block narrows the audience** - `"[/]"` to the root package alone, `"[*]"` or
36
- * a glob to the packages below (never the root, which is nobody's child). See `parseSelector`.
37
- *
38
- * **The root used to be the one directory whose unmarked config did *not* cascade**, on the
39
- * reasoning that a setting means different things to a package and to the repository - and the
40
- * reasoning is sound, but the rule it produced was not readable: an intermediate `packages/`
41
- * cascaded while the root did not, so what a file meant depended on whether a `package.json` sat
42
- * beside it. `vars` then had to be carved out as an exception, which is what a rule fighting itself
43
- * looks like. One sentence now covers both: what is written above reaches below, and `"[/]"` is how
44
- * a statement stays at the root.
45
- *
46
- * **The cost is real and lands on one subtree.** `run.<script>`'s hooks on the root are a repo-wide
47
- * bookend, run once at the repository root; on a package they are that package's own hook, run in
48
- * its directory. Cascaded, one declaration is both - once at the root and once per package. A
49
- * repo-wide bookend therefore belongs under `"[/]"`, where its audience is visible; that is the
50
- * migration this change asks for, and the only one that is not mechanical.
51
- *
52
- * `packageName` is what selectors match against; without it, selector blocks contribute nothing at
53
- * all. The root package passes its own, since `"[/]"` speaks to it.
54
- */
55
- export declare function resolveConfig(rootDir: string, targetDir: string, cache?: Map<string, RmanConfig>, packageName?: string): Promise<RmanConfig>;
56
- /** A config key naming packages rather than settings: `"[*]"`, `"[/]"`, `"[pkg-a]"`. The
57
- * brackets are what keep this space from colliding with real config keys - no setting starts with
58
- * one - and in YAML they also mean the key always needs quoting (`"[*]":`), since a bare `[*]`
59
- * parses as a flow sequence. */
60
- export declare function isSelectorKey(key: string): boolean;
61
- /**
62
- * **Which packages a selector speaks for.** Two audiences, and the second is a glob:
63
- *
64
- * | | |
65
- * | --- | --- |
66
- * | `"[/]"` | the **root package** alone |
67
- * | `"[*]"`, `"[pkg-a]"`, `"[*-dialect]"` | the packages **below** this directory that the glob matches |
68
- *
69
- * `/` for the root because that is what a repository root is called everywhere else, and it cannot
70
- * collide with a package name.
71
- *
72
- * **The root is never selected by name, and that one rule removes two traps.** A glob matches
73
- * package names, and the root is nobody's child - so `"[my-*]"` cannot quietly pick up a repository
74
- * whose root package happens to be called `my-repo`, and `"[*]"` cannot hand a package-shaped
75
- * setting to a root that has no build directory to apply it to. The root is addressed structurally
76
- * or not at all.
77
- *
78
- * **`"[ws:*]"` / `"[workspace:*]"` is accepted and means exactly `"[*]"`.** The qualifier existed to
79
- * say "not the root" back when a bare glob included it; the shape of the set says that now, so it
80
- * has nothing left to add. Accepted rather than rejected because the two spellings resolve to the
81
- * same packages - an error would be friction with no reader to protect.
82
- */
83
- export declare function parseSelector(key: string): {
84
- scope: 'root' | 'package';
85
- test: (name: string) => boolean;
86
- };
87
- /** The glob inside a selector key, as a `RegExp` anchored at both ends - so `"[*-dialect]"` matches
88
- * `mysql-dialect` but not `my-dialect-helper`. Glob rather than regex, to match every other
89
- * pattern in rman (`allowBranch`, `changelog.tagPattern`, `clean.include`). */
90
- export declare function selectorToRegExp(key: string): RegExp;
91
- /** One package, as an expression sees it - the same shape for the package the config belongs to
92
- * and for the repository itself, so `${{ repository.basename }}` reads the way `${{ pkg.basename }}` does. */
93
- /**
94
- * `file` in a `${{ ... }}` expression: what is actually on disk, resolved against **the package
95
- * the config was resolved for** - so one declaration in a `"[*]"` block asks each package about
96
- * its own directory.
97
- *
98
- * The pair exists because a config has two different questions about a path, and answering both
99
- * with one function would mean picking a wrong default for the other:
100
- *
101
- * ```yaml
102
- * "[*]":
103
- * run:
104
- * build:
105
- * # first of these that exists, and an error naming the config path if none do
106
- * exec: 'tsc -b ${{ file.exists("tsconfig-build.json") || file.resolve("tsconfig.json") }}'
107
- * ```
108
- *
109
- * **Every member asks a question, and none may ever change anything - no `copy`, no `write`, no
110
- * `mkdir`.** Not a matter of taste: this is evaluated when the config *resolves*, which every
111
- * command does, so a member that acted would act on `rman list`, `rman info` and `rman config`.
112
- *
113
- * That has been tried, in the only way a missing function can be: a shared config reaching for a
114
- * `file.copyMany(...)` that does not exist made **every** rman command exit 1 - and had it existed,
115
- * the quieter outcome would have been files copied by `rman list`. Work belongs in a step
116
- * (`run.<script>`'s slots, `version`'s hooks), which is the one place rman runs anything, and a
117
- * step can now be a function - so there is nothing this would enable that is not already possible
118
- * at the right moment.
119
- */
120
- export interface FileScope {
121
- /**
122
- * The absolute path if it exists, **`''` if it does not** - so `a || b || c` picks the first one
123
- * present, and so a miss never reaches the "nullish inside a string" guard that `undefined` would
124
- * trip. Accepts a relative path (against the package directory) or an absolute one.
125
- *
126
- * It returns a path rather than a boolean on purpose: the caller almost always wants the path,
127
- * and a separate `file.path()` to fetch it after a boolean test would read the disk twice and
128
- * invite the two calls to disagree.
129
- */
130
- exists(target: string): string;
131
- /** The absolute path, or **throws** - for a file whose absence is a mistake rather than a case to
132
- * handle. The error names the config path holding the expression, like any other. */
133
- resolve(target: string): string;
134
- /**
135
- * The first of several that exists, or **throws** naming every candidate it tried:
136
- *
137
- * ```yaml
138
- * exec: 'tsc -b ${{ file.resolveFirst("tsconfig-build.json", "tsconfig.build.json", "tsconfig.json") }}'
139
- * ```
140
- *
141
- * The same thing an `exists() || exists() || resolve()` chain does, said once - and it cannot be
142
- * got subtly wrong the way that chain can: ending it in `exists()` leaves `tsc -b ` with no
143
- * argument when nothing matches, and tsc then silently falls back to the directory's default
144
- * rather than reporting that the package has no build config.
145
- */
146
- resolveFirst(...targets: string[]): string;
147
- }
148
- export interface PackageScope {
149
- /** The package's own name, scope included (`@sqb/builder`). */
150
- name: string;
151
- /** Just the scope (`@sqb`), or `undefined` for an unscoped package. */
152
- scope: string | undefined;
153
- /** The name with its scope stripped (`builder`). */
154
- unscopedName: string;
155
- version: string;
156
- /** The package directory's last segment (`builder`) - not always the same as `unscopedName`,
157
- * which is why both exist, and usually what a sibling path (`../../coverage/builder`) is keyed on. */
158
- basename: string;
159
- /** Absolute path to the package's own directory - named as rman's own `Package.dirname` is. */
160
- dirname: string;
161
- /** That directory relative to the repository root (`packages/builder`), which is what a command
162
- * addressing another package from the root usually needs. Empty string for the root itself. */
163
- relativeDir: string;
164
- /**
165
- * Which ecosystem this package belongs to - `'node'` for one read by `rman-node`, empty when no
166
- * plugin claimed it. The same `Package.provider`, so one declaration can address a single
167
- * ecosystem in a polyglot repository (`if: "${{ pkg.provider === 'node' }}"`).
168
- */
169
- provider: string;
170
- /**
171
- * The whole manifest, as a copy - so an expression can reach a field rman itself has no opinion
172
- * about (`${{ pkg.manifest.engines.node }}`).
173
- *
174
- * Named `manifest`, not `json`: which file a package's identity lives in is the ecosystem's
175
- * business now (see `ManifestProvider`), and `json` was that assumption showing through the one
176
- * remaining user-facing name. A config written against `${{ pkg.json... }}` needs the rename.
177
- */
178
- manifest: Record<string, unknown>;
179
- /**
180
- * The version this run is about to write - **bound only during `version`**, and only once its
181
- * plan is computed. Reading it anywhere else throws rather than yielding `undefined`: no other
182
- * command has a target version, so an expression asking for one has been put in the wrong place,
183
- * and a config that quietly evaluates to "undefined" is the failure this evaluator exists to
184
- * prevent.
185
- */
186
- targetVersion: string;
187
- }
188
- /** Facts about the repository, on top of the root package's own - because the repository root *is*
189
- * a package (`repository.name` is what its `package.json` says, `repository.basename` the directory
190
- * it sits in, and the two genuinely differ). Sharing `PackageScope`'s shape is what makes
191
- * `repository.version` read the way `pkg.version` does. */
192
- export interface RepositoryScope extends PackageScope {
193
- monorepo: boolean;
194
- /** Every package in the repository - the root included only when it *is* the one package. */
195
- packages: PackageScope[];
196
- /** One package by name, or `undefined` - for reaching a sibling's directory. */
197
- package(name: string): PackageScope | undefined;
198
- }
199
- export interface GitScope {
200
- branch: string | undefined;
201
- sha: string | undefined;
202
- shortSha: string | undefined;
203
- /** Whether the working tree has uncommitted changes. */
204
- dirty: boolean | undefined;
205
- }
206
- /**
207
- * What a `${{ ... }}` expression can see - the bindings of the fresh global it is evaluated in.
208
- * Namespaced rather than a flat bag of loose names: one obvious place per fact, and room to add
209
- * helpers to `pkg`/`repository` later without crowding the global.
210
- *
211
- * Alongside these, **the config's own top-level keys are bound bare** (`${{ publish.directory }}`,
212
- * `${{ clean.include }}`) - see `interpolateConfig`. They are not listed here because they come
213
- * from the config being interpolated, not from this object; a name here wins over a config key of
214
- * the same name.
215
- *
216
- * **Trap: bare `${{ version }}` is the `version` *options block*, not the package's version
217
- * string** - that is `${{ pkg.version }}`. Same word, two different things, and the plain one
218
- * belongs to the config because every other config key is reachable that way.
219
- */
220
- export interface ConfigScope {
221
- /** The package the config was resolved for - which is what lets one declaration at the root
222
- * still say something package-specific. */
223
- pkg: PackageScope;
224
- repository: RepositoryScope;
225
- /** Paths, resolved against the package the config was resolved for. */
226
- file: FileScope;
227
- /**
228
- * The **contents** of a structured file - `${{ read('tsconfig.json').compilerOptions.outDir }}` -
229
- * where `file` answers only where one is. Resolved against `pkg.dirname` like `file`, so a
230
- * `"[*]"` block asks each package about its own; a repository-level file is reached through
231
- * `read(path.join(repository.dirname, ...))`.
232
- *
233
- * `.json`, `.yml`/`.yaml` and `.ini` by extension, or name it for a file that does not say
234
- * (`read('.npmrc', 'ini')`). **Throws** when the file is absent, as `file.resolve` does - compose
235
- * with `file.exists` when its absence is a case to handle.
236
- *
237
- * **A manifest is `pkg.manifest`, not this.** `read('package.json')` works and is the wrong
238
- * answer: which file a package's identity lives in belongs to the ecosystem, so that expression
239
- * is already wrong in a Cargo package sitting beside a Node one.
240
- *
241
- * The result is **deeply frozen and shared** - see `readStructuredFile`. Spread it to change it.
242
- */
243
- read: ReadFile;
244
- env: Record<string, string | undefined>;
245
- /** rman's own `semver`, for the arithmetic every release config eventually wants
246
- * (`semver.major(pkg.version)`). */
247
- semver: typeof semver;
248
- /**
249
- * Node's own `node:path` - `${{ path.join(pkg.dirname, 'LICENSE') }}`, rather than gluing
250
- * strings with `+ "/" +` and getting a double separator or none.
251
- *
252
- * The platform's flavour, not `path.posix`, so a joined path is the one the shell on *this*
253
- * machine understands; `path.posix` and `path.win32` are reachable through it when a config
254
- * genuinely needs one of them (a Docker image path, say, which is always posix).
255
- */
256
- path: typeof path;
257
- /**
258
- * The checkout: branch, sha, whether the tree is dirty.
259
- *
260
- * **Top level, not `repository.git`** - which is where it used to be, and the move is the point.
261
- * `repository` shares its shape with `pkg` because the repository root *is* a package, and its
262
- * only other members (`monorepo`, `packages`, `package()`) say something about the repository as
263
- * a container of packages. A branch name says nothing about any package; it describes the
264
- * working tree every one of them happens to be sitting in - the same kind of ambient fact as
265
- * `env`, and it belongs beside it.
266
- *
267
- * **Read from git only if an expression actually asks**, then remembered for the whole run: every
268
- * command resolves config, and a repository that never mentions git must not pay for one. See
269
- * `Repository.configScope` for the getter, and `interpolateConfig` for why the context is built
270
- * from property descriptors rather than a spread - a spread would fire this getter on every
271
- * command, which is exactly what moving it up here risked.
272
- */
273
- git: GitScope;
274
- }
275
- /**
276
- * Evaluates every `${{ ... }}` expression in **every** string value of a resolved config, against
277
- * the package it was resolved for:
278
- *
279
- * ```yaml
280
- * "[*]":
281
- * clean:
282
- * include: ["build", "../../coverage/${{ pkg.basename }}"]
283
- * publish:
284
- * directory: build
285
- * docker:
286
- * image: "panates/${{ pkg.basename }}:${{ semver.major(pkg.version) }}"
287
- * run:
288
- * build:
289
- * # the config's own keys are in scope, so this is not a second copy of "build"
290
- * after: "cp README.md ${{ publish.directory }}/"
291
- * ```
292
- *
293
- * Every string, with no list of "interpolated keys" to memorize - a rule with exceptions is a rule
294
- * nobody remembers.
295
- *
296
- * The contents are **real JavaScript**, not a template mini-language, so there is no growing list
297
- * of substitutions to keep adding (`{{major}}`, `{{scope}}`, ...) - see `ConfigScope` for what is
298
- * in scope.
299
- *
300
- * **`${{ }}`, deliberately not `{{ }}`.** A config value may legitimately carry `{{...}}` meant for
301
- * something else entirely (`helm template --set tag={{.Values.tag}}`); with the plainer delimiter
302
- * rman would try to evaluate it. To emit a literal, let an expression produce it, the way GitHub
303
- * Actions does: `${{ '${{' }}`.
304
- *
305
- * A string that is *nothing but* one expression keeps the value's own type (`"${{ pkg.private }}"`
306
- * -> a boolean), since otherwise this could only ever produce strings and settings like
307
- * `run.<script>.skip` would be unreachable. Embedded in surrounding text it is stringified.
308
- *
309
- * Evaluation happens in a fresh V8 context holding only the scope's bindings. That is a clean
310
- * scope, **not a sandbox** - `node:vm` is explicitly not a security mechanism, and no sandbox is
311
- * called for here anyway: a `.rmanrc` that can say `exec: "..."` already runs arbitrary shell, so
312
- * the expression evaluator adds no trust boundary that wasn't already wide open.
313
- *
314
- * A failing expression throws with the config path that holds it, rather than being left in place:
315
- * silently passing through a mistake is how a config ends up quietly doing nothing.
316
- */
317
- export interface InterpolateOptions {
318
- /** Config paths to leave entirely untouched - `DEFERRED_PATHS`, when the whole config is walked. */
319
- skip?: string[];
320
- /** Where `config` sits in the whole config, for a caller interpolating a fragment. */
321
- at?: string[];
322
- }
323
- export declare function interpolateConfig<T>(config: T, scope: ConfigScope, options?: InterpolateOptions): T;
324
- /**
325
- * Config paths left untouched when a repository's config is first resolved, and evaluated only by
326
- * the command that runs them.
327
- *
328
- * `version`'s own hooks are the one place `${{ pkg.targetVersion }}` makes sense, and the version
329
- * being written is not known until `version` has computed its plan - long after the config was
330
- * resolved. Evaluating these eagerly would throw while merely *loading* the repository, so any
331
- * command at all would fail on a config that mentions it.
332
- */
333
- export declare const DEFERRED_PATHS: string[];
334
- /**
335
- * Paths whose value is a **step** - something to run later - rather than a setting to compute now.
336
- * `*` matches one path segment (`run.<script>.exec`).
337
- *
338
- * This is what tells a step function from a value function, and the two live side by side in one
339
- * config:
340
- *
341
- * ```js
342
- * '[*]': {
343
- * clean: { include: ({ vars, value }) => [...value, vars.buildDir] }, // a value: called here
344
- * run: { build: { after: ({ pkg }) => copyDocs(pkg) } }, // a step: called by `run`
345
- * }
346
- * ```
347
- *
348
- * **The key decides, and it already did.** `run.build.exec: 'tsc -b'` is a shell command and
349
- * `publish.directory: 'build'` is a path - not because of anything about the strings, but because of
350
- * where they sit. A function inherits the same rule, so nothing new has to be learned and no marker
351
- * has to be remembered. The alternative was inspecting the function (arity, parameter names), which
352
- * is the kind of guess `loadPlugins` refuses to make about a module's export for the same reason:
353
- * guessing wrong here means running build-time code while merely loading the repository, or
354
- * silently never running it.
355
- *
356
- * A **string** at one of these paths is still interpolated - `exec: 'tsc -b ${{ file.resolve(...) }}'`
357
- * has to keep working - so this is narrower than `DEFERRED_PATHS`, which skips its paths entirely.
358
- */
359
- export declare const STEP_PATHS: string[];
360
- /**
361
- * Keys whose **whole subtree** is code rather than config, so no function under them is a value to
362
- * compute. `plugins` is the only one, and it has to be here: an entry may be the plugin *object*
363
- * itself, and an `RmanPlugin` is almost entirely functions - `manifest.read`, `workspace.resolve`,
364
- * `versionPlanner`, `binPaths`, and every command's `builder` and `handler`.
365
- *
366
- * Measured, and it is why this exists: with `plugins` walked like any other key, resolving the
367
- * config of a repository that named a plugin called that plugin's yargs builder with the config
368
- * scope - `Config function in "plugins[0].commands[0].builder" failed: cmd.option is not a
369
- * function`. A `plugins` entry is loaded by `loadPlugins`, never read as a setting.
370
- */
371
- export declare const CODE_SUBTREES: string[];
372
- /** The `file` namespace for one package's directory - see `FileScope`. */
373
- /**
374
- * `read` in a `${{ ... }}` expression (and in a value function): a structured file's **contents**,
375
- * parsed - where `file` answers only where a path is.
376
- *
377
- * ```yaml
378
- * "[*]":
379
- * run:
380
- * build:
381
- * exec: 'tsc --outDir ${{ read("tsconfig.json").compilerOptions.outDir }}'
382
- * ```
383
- *
384
- * `cache` is shared across every package (see `Repository.configScope`) and keyed by what the file
385
- * *is*, not merely where - so the same file read by twenty packages is parsed once, and a file rman
386
- * itself rewrites mid-run is re-read rather than remembered. See `readStructuredFile`.
387
- */
388
- export declare function createReadScope(dirname: string, cache: Map<string, CachedFile>): ReadFile;
389
- /**
390
- * What `read` can parse.
391
- *
392
- * **`.env` is deliberately absent, and that is the durable part of this list**: `env` is already in
393
- * scope, and a `.env` file exists to be loaded *into* an environment by something else - a config
394
- * reading one as data would mean two different things called the environment.
395
- *
396
- * Nothing else is excluded on principle. `xml` arrived because a `pom.xml` or a `.csproj` holds a
397
- * version exactly the way a `package.json` does, and rman is language-agnostic; the earlier line
398
- * ("no new parsers") did not survive it, since xmldom *is* a new one.
399
- */
400
- export type FileFormat = 'json' | 'yaml' | 'ini' | 'xml';
401
- /** `read(path)`, or `read(path, 'ini')` for a file whose name does not say what it is (`.npmrc`). */
402
- export type ReadFile = (target: string, format?: FileFormat) => unknown;
403
- /** One parsed file, kept against the identity of the bytes it came from - see `readStructuredFile`. */
404
- export interface CachedFile {
405
- /** `mtimeNs:size`. */
406
- stamp: string;
407
- value: unknown;
408
- }
409
- export declare function createFileScope(dirname: string): FileScope;