@astra-kit/rp 0.0.0-stage → 0.10.0

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 (125) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +352 -2
  4. package/bin/astra-rp.js +51 -0
  5. package/package.json +93 -4
  6. package/src/build-gate.js +157 -0
  7. package/src/changelog-blocks.js +53 -0
  8. package/src/changelog.js +108 -0
  9. package/src/constants/build-gate.js +30 -0
  10. package/src/constants/changelog-draft.js +180 -0
  11. package/src/constants/changelog.js +74 -0
  12. package/src/constants/ci-release.js +346 -0
  13. package/src/constants/cli.js +12 -0
  14. package/src/constants/create-version.js +523 -0
  15. package/src/constants/guard-publish.js +29 -0
  16. package/src/constants/index.js +18 -0
  17. package/src/constants/monorepo.js +57 -0
  18. package/src/constants/package-manager.js +56 -0
  19. package/src/constants/registry.js +72 -0
  20. package/src/constants/terminal-ui.js +93 -0
  21. package/src/constants/version-files.js +63 -0
  22. package/src/constants/versions.js +60 -0
  23. package/src/create-version/artifact.js +343 -0
  24. package/src/create-version/changelog-draft-workspace.js +124 -0
  25. package/src/create-version/changelog-draft.js +380 -0
  26. package/src/create-version/changelog.js +264 -0
  27. package/src/create-version/ci-config.js +54 -0
  28. package/src/create-version/ci-publication-history.js +113 -0
  29. package/src/create-version/ci-release-identity-step.js +58 -0
  30. package/src/create-version/ci-setup.js +794 -0
  31. package/src/create-version/ci.js +555 -0
  32. package/src/create-version/committed-tree.js +75 -0
  33. package/src/create-version/config.js +489 -0
  34. package/src/create-version/errors.js +46 -0
  35. package/src/create-version/github-workflow.js +199 -0
  36. package/src/create-version/index.js +54 -0
  37. package/src/create-version/json.js +32 -0
  38. package/src/create-version/jsonc.js +76 -0
  39. package/src/create-version/jsr.js +96 -0
  40. package/src/create-version/local-changes.js +178 -0
  41. package/src/create-version/npm-auth.js +142 -0
  42. package/src/create-version/npm.js +812 -0
  43. package/src/create-version/plan.js +1200 -0
  44. package/src/create-version/process.js +334 -0
  45. package/src/create-version/registry-config.js +121 -0
  46. package/src/create-version/registry-http.js +62 -0
  47. package/src/create-version/registry.js +220 -0
  48. package/src/create-version/release-execution.js +45 -0
  49. package/src/create-version/release-tag-config.js +76 -0
  50. package/src/create-version/run.js +2087 -0
  51. package/src/create-version/state.js +461 -0
  52. package/src/create-version/strict-utf8.js +11 -0
  53. package/src/create-version/templates/release.yml +52 -0
  54. package/src/create-version/templates/vercel-ignore-build.mjs +66 -0
  55. package/src/guard-publish.js +77 -0
  56. package/src/index.js +42 -0
  57. package/src/monorepo/plan.js +475 -0
  58. package/src/monorepo/release-commit.js +46 -0
  59. package/src/monorepo/run.js +927 -0
  60. package/src/monorepo/state.js +206 -0
  61. package/src/monorepo/workspaces.js +327 -0
  62. package/src/package-manager.js +107 -0
  63. package/src/terminal-ui.js +548 -0
  64. package/src/testing.js +70 -0
  65. package/src/version-files.js +142 -0
  66. package/src/versions.js +303 -0
  67. package/types/build-gate.d.ts +43 -0
  68. package/types/changelog-blocks.d.ts +33 -0
  69. package/types/changelog.d.ts +61 -0
  70. package/types/constants/build-gate.d.ts +23 -0
  71. package/types/constants/changelog-draft.d.ts +138 -0
  72. package/types/constants/changelog.d.ts +56 -0
  73. package/types/constants/ci-release.d.ts +284 -0
  74. package/types/constants/cli.d.ts +11 -0
  75. package/types/constants/create-version.d.ts +397 -0
  76. package/types/constants/guard-publish.d.ts +25 -0
  77. package/types/constants/index.d.ts +17 -0
  78. package/types/constants/monorepo.d.ts +45 -0
  79. package/types/constants/package-manager.d.ts +40 -0
  80. package/types/constants/registry.d.ts +79 -0
  81. package/types/constants/terminal-ui.d.ts +73 -0
  82. package/types/constants/version-files.d.ts +51 -0
  83. package/types/constants/versions.d.ts +47 -0
  84. package/types/create-version/artifact.d.ts +113 -0
  85. package/types/create-version/changelog-draft-workspace.d.ts +33 -0
  86. package/types/create-version/changelog-draft.d.ts +127 -0
  87. package/types/create-version/changelog.d.ts +141 -0
  88. package/types/create-version/ci-config.d.ts +33 -0
  89. package/types/create-version/ci-publication-history.d.ts +51 -0
  90. package/types/create-version/ci-release-identity-step.d.ts +12 -0
  91. package/types/create-version/ci-setup.d.ts +148 -0
  92. package/types/create-version/ci.d.ts +145 -0
  93. package/types/create-version/committed-tree.d.ts +55 -0
  94. package/types/create-version/config.d.ts +128 -0
  95. package/types/create-version/errors.d.ts +39 -0
  96. package/types/create-version/github-workflow.d.ts +41 -0
  97. package/types/create-version/index.d.ts +28 -0
  98. package/types/create-version/json.d.ts +21 -0
  99. package/types/create-version/jsonc.d.ts +21 -0
  100. package/types/create-version/jsr.d.ts +52 -0
  101. package/types/create-version/local-changes.d.ts +52 -0
  102. package/types/create-version/npm-auth.d.ts +60 -0
  103. package/types/create-version/npm.d.ts +331 -0
  104. package/types/create-version/plan.d.ts +369 -0
  105. package/types/create-version/process.d.ts +151 -0
  106. package/types/create-version/registry-config.d.ts +56 -0
  107. package/types/create-version/registry-http.d.ts +22 -0
  108. package/types/create-version/registry.d.ts +86 -0
  109. package/types/create-version/release-execution.d.ts +22 -0
  110. package/types/create-version/release-tag-config.d.ts +18 -0
  111. package/types/create-version/run.d.ts +407 -0
  112. package/types/create-version/state.d.ts +204 -0
  113. package/types/create-version/strict-utf8.d.ts +10 -0
  114. package/types/guard-publish.d.ts +49 -0
  115. package/types/index.d.ts +23 -0
  116. package/types/monorepo/plan.d.ts +68 -0
  117. package/types/monorepo/release-commit.d.ts +29 -0
  118. package/types/monorepo/run.d.ts +68 -0
  119. package/types/monorepo/state.d.ts +96 -0
  120. package/types/monorepo/workspaces.d.ts +86 -0
  121. package/types/package-manager.d.ts +58 -0
  122. package/types/terminal-ui.d.ts +196 -0
  123. package/types/testing.d.ts +31 -0
  124. package/types/version-files.d.ts +59 -0
  125. package/types/versions.d.ts +158 -0
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Gathers the snapshot consumed by `plan.js`: current branch, uncommitted
3
+ * changes, `main` compared with `origin/main`, the version and subject of
4
+ * `HEAD`, the commit of a detached release tag on `origin`, the last release,
5
+ * the commits waiting to be released, the pull request of a feature branch,
6
+ * the published versions, the npm credentials (when the plan would publish to
7
+ * npm) and pending migrations.
8
+ *
9
+ * Every reader is read-only; the only network operations are `git fetch`,
10
+ * `git ls-remote`, `gh pr view`, `npm view`, `npm whoami`, `npm owner ls` and
11
+ * whatever the project migrations adapter reads.
12
+ *
13
+ * @module create-version/state
14
+ */
15
+ import { checkNpmPublishAccess, lookupPublishedVersions } from "./npm.js";
16
+ export type GitReader = import("./process.js").GitReader;
17
+ export type ReleaseState = import("./plan.js").ReleaseState;
18
+ export type PullRequestSnapshot = import("./plan.js").PullRequestSnapshot;
19
+ export type MigrationCheck = import("./config.js").MigrationCheck;
20
+ export type LastReleaseSnapshot = import("./plan.js").LastReleaseSnapshot;
21
+ export type ReleaseSnapshot = ReleaseState & {
22
+ packageName: string;
23
+ releasedVersion: string | null;
24
+ lastRelease: LastReleaseSnapshot | null;
25
+ };
26
+ /**
27
+ * Finds the last release on a revision: the newest commit that changed the
28
+ * top-level `version` of `package.json`. It covers `X.Y.Z` release commits,
29
+ * other release subjects and projects that bumped versions by hand.
30
+ *
31
+ * @param {GitReader} reader - Git reader.
32
+ * @param {string} revision - Revision such as `origin/main`.
33
+ * @returns {Promise<LastReleaseSnapshot | null>} Last release with its subject and whether its
34
+ * `vX.Y.Z` tag points at it, or `null` without history.
35
+ */
36
+ export declare function findLastRelease(reader: GitReader, revision: string): Promise<LastReleaseSnapshot | null>;
37
+ /**
38
+ * Looks up the pull request of a branch with the GitHub CLI.
39
+ *
40
+ * @param {string} repositoryRoot - Repository root.
41
+ * @param {string} branchName - Head branch.
42
+ * @returns {Promise<{ pullRequest: PullRequestSnapshot | null, githubError: string | null }>} Pull request or error.
43
+ */
44
+ export declare function lookupPullRequest(repositoryRoot: string, branchName: string): Promise<{
45
+ pullRequest: PullRequestSnapshot | null;
46
+ githubError: string | null;
47
+ }>;
48
+ /**
49
+ * Reads the `[Unreleased]` block of the working-tree CHANGELOG.md.
50
+ *
51
+ * @param {string} repositoryRoot - Repository root.
52
+ * @returns {{ exists: boolean, entryCount: number, unknownSections: string[] }} Unreleased state.
53
+ */
54
+ export declare function readChangelogState(repositoryRoot: string): {
55
+ exists: boolean;
56
+ entryCount: number;
57
+ unknownSections: string[];
58
+ };
59
+ /**
60
+ * Runs the project migrations check, turning any failure into an `unknown` result.
61
+ *
62
+ * @param {(() => Promise<MigrationCheck> | MigrationCheck) | null} checkMigrations - Adapter bound to its hook context.
63
+ * @returns {Promise<MigrationCheck | null>} Migration state, or `null` for projects without migrations.
64
+ */
65
+ export declare function readMigrations(checkMigrations: (() => Promise<MigrationCheck> | MigrationCheck) | null): Promise<MigrationCheck | null>;
66
+ /**
67
+ * Lists the published versions on the registry the working-tree manifest publishes to, so the
68
+ * diagnosis sees the same versions `npm publish` would conflict with.
69
+ *
70
+ * @param {typeof lookupPublishedVersions} lookupNpm - npm lookup adapter.
71
+ * @param {Record<string, unknown>} manifest - Working-tree `package.json`.
72
+ * @param {string} repositoryRoot - Repository root.
73
+ * @returns {Promise<import("./npm.js").NpmLookup>} Published versions, or a failed lookup when the registry is invalid
74
+ * or npm cannot report it.
75
+ */
76
+ export declare function lookupNpmOnPublishRegistry(lookupNpm: typeof lookupPublishedVersions, manifest: Record<string, unknown>, repositoryRoot: string): Promise<import("./npm.js").NpmLookup>;
77
+ /**
78
+ * Lists the published versions of a package for the diagnosis: on the selected registry, or on the
79
+ * registry the working-tree manifest publishes to when no registry is selected; shared with the monorepo mode.
80
+ *
81
+ * @param {import("./registry.js").RegistrySelection | undefined} registrySelection - Selected registry, if any.
82
+ * @param {Record<string, unknown>} manifest - Working-tree manifest of the package.
83
+ * @param {string} repositoryRoot - Repository root, where routing and credentials are read.
84
+ * @param {string} packageRoot - Package directory.
85
+ * @param {typeof lookupPublishedVersions} lookupNpm - npm lookup adapter.
86
+ * @returns {Promise<import("./npm.js").NpmLookup>} Published versions, or a failed lookup.
87
+ */
88
+ export declare function lookupPackageVersions(registrySelection: import("./registry.js").RegistrySelection | undefined, manifest: Record<string, unknown>, repositoryRoot: string, packageRoot: string, lookupNpm: typeof lookupPublishedVersions): Promise<import("./npm.js").NpmLookup>;
89
+ /**
90
+ * Checks the credentials that would publish a package and confirms a first publication against its
91
+ * published versions (see {@link confirmFirstPublication}); shared with the monorepo mode.
92
+ *
93
+ * @param {import("./registry.js").RegistrySelection | undefined} registrySelection - Selected registry, if any.
94
+ * @param {Record<string, unknown>} manifest - Working-tree manifest of the package.
95
+ * @param {string} repositoryRoot - Repository root, where routing and credentials are read.
96
+ * @param {string} packageRoot - Package directory.
97
+ * @param {typeof checkNpmPublishAccess} checkNpmAccess - npm credential check adapter.
98
+ * @param {import("./npm.js").NpmLookup | null} npm - Published versions, or `null` when npm is not tracked.
99
+ * @returns {Promise<import("./npm.js").NpmAuthCheck>} Credential check.
100
+ */
101
+ export declare function checkPackageAccess(registrySelection: import("./registry.js").RegistrySelection | undefined, manifest: Record<string, unknown>, repositoryRoot: string, packageRoot: string, checkNpmAccess: typeof checkNpmPublishAccess, npm: import("./npm.js").NpmLookup | null): Promise<import("./npm.js").NpmAuthCheck>;
102
+ /**
103
+ * Reads the changelog of a package for the diagnosis: its `[Unreleased]` block and whether it was
104
+ * updated since the last release; shared with the monorepo mode.
105
+ *
106
+ * @param {GitReader} reader - Git reader.
107
+ * @param {string} repositoryRoot - Repository root.
108
+ * @param {string} packageRoot - Package directory holding the changelog.
109
+ * @param {string} changelogPath - Changelog path relative to the root.
110
+ * @param {string | null} lastReleaseSha - Commit of the last release, or `null` without one.
111
+ * @returns {Promise<ReleaseSnapshot["changelog"]>} Changelog state.
112
+ */
113
+ export declare function readPackageChangelogState(reader: GitReader, repositoryRoot: string, packageRoot: string, changelogPath: string, lastReleaseSha: string | null): Promise<ReleaseSnapshot["changelog"]>;
114
+ /**
115
+ * Checks the npm credentials on the registry the working-tree manifest publishes to.
116
+ *
117
+ * @param {typeof checkNpmPublishAccess} checkAccess - npm credential check adapter.
118
+ * @param {Record<string, unknown>} manifest - Working-tree `package.json`.
119
+ * @param {string} repositoryRoot - Repository root.
120
+ * @returns {Promise<import("./npm.js").NpmAuthCheck>} Check result; an `unknown` one when the registry cannot be resolved.
121
+ */
122
+ export declare function checkNpmAuthOnPublishRegistry(checkAccess: typeof checkNpmPublishAccess, manifest: Record<string, unknown>, repositoryRoot: string): Promise<import("./npm.js").NpmAuthCheck>;
123
+ /**
124
+ * Confirms a first publication (`npm owner ls` answered E404) against the versions `npm view`
125
+ * listed with the same token. Registries hide a private package from users without access, so an
126
+ * owner E404 only means "new package" when `npm view` does not list versions either: when it does,
127
+ * the package exists and the token cannot manage it, which blocks like a user that is not an owner.
128
+ *
129
+ * @param {import("./npm.js").NpmAuthCheck} npmAuth - Credential check.
130
+ * @param {import("./npm.js").NpmLookup | null} npm - Published versions, or `null` when npm is not tracked.
131
+ * @returns {import("./npm.js").NpmAuthCheck} The same check, or a `notOwner` one when the package already has versions.
132
+ */
133
+ export declare function confirmFirstPublication(npmAuth: import("./npm.js").NpmAuthCheck, npm: import("./npm.js").NpmLookup | null): import("./npm.js").NpmAuthCheck;
134
+ export type RepositorySnapshot = {
135
+ currentBranch: string | null;
136
+ workingTreeChanges: string[];
137
+ branch: import("./plan.js").FeatureBranchSnapshot | null;
138
+ pullRequest: PullRequestSnapshot | null;
139
+ githubError: string | null;
140
+ main: {
141
+ aheadCommits: import("./process.js").CommitRecord[];
142
+ behindCount: number;
143
+ };
144
+ remoteMainExists: boolean;
145
+ };
146
+ /**
147
+ * @typedef {{
148
+ * currentBranch: string | null,
149
+ * workingTreeChanges: string[],
150
+ * branch: import("./plan.js").FeatureBranchSnapshot | null,
151
+ * pullRequest: PullRequestSnapshot | null,
152
+ * githubError: string | null,
153
+ * main: { aheadCommits: import("./process.js").CommitRecord[], behindCount: number },
154
+ * remoteMainExists: boolean,
155
+ * }} RepositorySnapshot
156
+ * What every release mode reads from Git before looking at packages: the branch and its pull
157
+ * request, the working tree and `main` compared with `origin/main`.
158
+ */
159
+ /**
160
+ * Fetches `origin` and reads the repository part of the snapshot, shared by the single-package and
161
+ * the monorepo modes.
162
+ *
163
+ * @param {{
164
+ * repositoryRoot: string,
165
+ * reader: GitReader,
166
+ * onProgress: (label: string) => void,
167
+ * lookupPullRequestFor: typeof lookupPullRequest,
168
+ * }} options - Repository, reader, progress callback and pull request adapter.
169
+ * @returns {Promise<RepositorySnapshot>} Repository snapshot.
170
+ */
171
+ export declare function readRepositorySnapshot({ repositoryRoot, reader, onProgress, lookupPullRequestFor }: {
172
+ repositoryRoot: string;
173
+ reader: GitReader;
174
+ onProgress: (label: string) => void;
175
+ lookupPullRequestFor: typeof lookupPullRequest;
176
+ }): Promise<RepositorySnapshot>;
177
+ /**
178
+ * Gathers the complete release snapshot.
179
+ *
180
+ * @param {{
181
+ * repositoryRoot: string,
182
+ * trackNpm?: boolean,
183
+ * checkMigrations?: (() => Promise<MigrationCheck> | MigrationCheck) | null,
184
+ * onProgress?: (label: string) => void,
185
+ * lookupNpm?: typeof lookupPublishedVersions,
186
+ * checkNpmAuth?: ((snapshot: ReleaseSnapshot) => boolean) | null,
187
+ * checkNpmAccess?: typeof checkNpmPublishAccess,
188
+ * lookupPullRequestFor?: typeof lookupPullRequest,
189
+ * registrySelection?: import("./registry.js").RegistrySelection,
190
+ * }} options - Repository, adapters and progress callback. `checkNpmAuth` receives the snapshot
191
+ * without credentials and decides whether the npm credentials are checked (when the plan would publish to npm).
192
+ * @returns {Promise<ReleaseSnapshot>} Snapshot accepted by `buildReleasePlan`.
193
+ */
194
+ export declare function collectReleaseState({ repositoryRoot, trackNpm, checkMigrations, onProgress, lookupNpm, checkNpmAuth, checkNpmAccess, lookupPullRequestFor, registrySelection, }: {
195
+ repositoryRoot: string;
196
+ trackNpm?: boolean;
197
+ checkMigrations?: (() => Promise<MigrationCheck> | MigrationCheck) | null;
198
+ onProgress?: (label: string) => void;
199
+ lookupNpm?: typeof lookupPublishedVersions;
200
+ checkNpmAuth?: ((snapshot: ReleaseSnapshot) => boolean) | null;
201
+ checkNpmAccess?: typeof checkNpmPublishAccess;
202
+ lookupPullRequestFor?: typeof lookupPullRequest;
203
+ registrySelection?: import("./registry.js").RegistrySelection;
204
+ }): Promise<ReleaseSnapshot>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Strict UTF-8 decoding for files the release rewrites as text.
3
+ *
4
+ * @module create-version/strict-utf8
5
+ */
6
+ /**
7
+ * Strict UTF-8 decoder: invalid bytes (such as an ISO-8859-1 file) throw instead of turning into
8
+ * U+FFFD, and a byte order mark is kept as text, so writing the text back never changes other bytes.
9
+ */
10
+ export declare const STRICT_UTF8_DECODER: import("util").TextDecoder;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `prepublishOnly` guard of the packages released with astra-rp: they are published with npm by
3
+ * `create-version` (run through the project's package manager), which verifies the tarball against
4
+ * `npm pack --dry-run`, so a `pnpm publish` (or yarn/bun) is blocked.
5
+ *
6
+ * The guard only blocks package managers it recognizes. Without a user agent,
7
+ * or with an unknown one, the publisher cannot be determined and it allows the
8
+ * publication. It can be bypassed on purpose with `--ignore-scripts`.
9
+ *
10
+ * @module guard-publish
11
+ */
12
+ export type PublishGuardDecision = {
13
+ allowed: boolean;
14
+ packageManager: string | null;
15
+ message: string | null;
16
+ exitCode: number;
17
+ };
18
+ /**
19
+ * @typedef {{ allowed: boolean, packageManager: string | null, message: string | null, exitCode: number }} PublishGuardDecision
20
+ */
21
+ /**
22
+ * Finds the blocked package manager that runs the publication.
23
+ *
24
+ * @param {string | undefined} userAgent - Value of `npm_config_user_agent`.
25
+ * @returns {string | null} Blocked package manager name, or `null` for npm, unknown or missing user agents.
26
+ */
27
+ export declare function findBlockedPublishPackageManager(userAgent: string | undefined): string | null;
28
+ /**
29
+ * Builds the explanation printed when a publication is blocked.
30
+ *
31
+ * @param {string} packageManager - Blocked package manager name (pnpm, yarn or bun), which is also
32
+ * the one the project uses: the message names its own create-version command.
33
+ * @returns {string} Message in Spanish with what to run instead.
34
+ */
35
+ export declare function buildBlockedPublishMessage(packageManager: string): string;
36
+ /**
37
+ * Decides whether the publication may continue.
38
+ *
39
+ * @param {string | undefined} userAgent - Value of `npm_config_user_agent`.
40
+ * @returns {PublishGuardDecision} Decision, message to print on stderr and exit code.
41
+ */
42
+ export declare function decidePublishGuard(userAgent: string | undefined): PublishGuardDecision;
43
+ /**
44
+ * Decides with the user agent of an environment (the current process by default).
45
+ *
46
+ * @param {NodeJS.ProcessEnv} [environment] - Environment of the lifecycle script.
47
+ * @returns {PublishGuardDecision} Decision for its `npm_config_user_agent`.
48
+ */
49
+ export declare function decidePublishGuardForEnvironment(environment?: NodeJS.ProcessEnv): PublishGuardDecision;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `@astra-kit/rp`: dependency-free release process.
3
+ *
4
+ * - `@astra-kit/rp/versions`: stable `X.Y.Z` rules; only the next patch, minor or major is allowed.
5
+ * - `@astra-kit/rp/build-gate`: Vercel `ignoreCommand` decision built on those rules.
6
+ * - `@astra-kit/rp/changelog`: release history generated from Git commits.
7
+ * - `@astra-kit/rp/guard-publish`: `prepublishOnly` guard that blocks pnpm, yarn and bun publications.
8
+ * - `@astra-kit/rp/package-manager`: detection of pnpm, bun, npm or yarn and the commands each one runs.
9
+ * - `@astra-kit/rp/version-files`: rewrites the marked version lines of `versionFiles`.
10
+ * - `@astra-kit/rp/terminal-ui`: boxes, spinners and prompts for release commands.
11
+ * - `@astra-kit/rp/testing`: shared version bump fixtures for consumer test suites.
12
+ * - `@astra-kit/rp/constants`: every constant above, grouped by domain.
13
+ *
14
+ * @module @astra-kit/rp
15
+ */
16
+ export * from "./build-gate.js";
17
+ export * from "./changelog.js";
18
+ export * from "./guard-publish.js";
19
+ export * from "./package-manager.js";
20
+ export * from "./version-files.js";
21
+ export * from "./versions.js";
22
+ export { ICON, countTerminalRows, formatDuration, getPromptWaitMs, measureActiveMs, paint, print, renderBanner, renderBox, renderRow, renderStepHeader, resolveBoxWidth, resolveNumberKey, select, startSpinner, visibleWidth, wrapStyledLine, } from "./terminal-ui.js";
23
+ export * from "./constants/index.js";
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Pure planning of a monorepo release. Receives the snapshot of `state.js`
3
+ * and decides, without touching Git or npm, what is still missing:
4
+ *
5
+ * - a new release: the packages with commits under their paths are the
6
+ * candidates; the run asks the version of each one (or skips it) before
7
+ * verifying manual changelogs, applying migrations, running the checks and creating one release commit with a tag
8
+ * per package (which closes the `[Unreleased]` section of every released changelog), prepares, pushes and publishes in dependency order;
9
+ * - the resume of a local release commit that never reached `origin`, or of
10
+ * tagged releases on `origin/main` that npm does not have yet;
11
+ * - nothing, when no package changed;
12
+ * - blockers explaining what to fix first.
13
+ *
14
+ * @module monorepo/plan
15
+ */
16
+ export type MonorepoSnapshot = import("./state.js").MonorepoSnapshot;
17
+ export type PackageSnapshot = import("./state.js").PackageSnapshot;
18
+ export type ReleaseCapabilities = import("../create-version/plan.js").ReleaseCapabilities;
19
+ export type ReleasePlanStep = import("../create-version/plan.js").ReleasePlanStep;
20
+ export type ReleaseBlocker = import("../create-version/plan.js").ReleaseBlocker;
21
+ export type ProjectCommands = import("../package-manager.js").ProjectCommands;
22
+ export type PendingPackageRelease = {
23
+ name: string;
24
+ version: string;
25
+ tag: string;
26
+ commitSha: string;
27
+ publish: boolean;
28
+ };
29
+ export type MonorepoPlan = {
30
+ mode: string;
31
+ steps: ReleasePlanStep[];
32
+ blockers: ReleaseBlocker[];
33
+ warnings: string[];
34
+ candidates: string[];
35
+ pendingReleases: PendingPackageRelease[];
36
+ };
37
+ /**
38
+ * Lists the uncommitted changes a run with `--ignore-local-changes` sets aside: every change,
39
+ * except the package changelogs in a new release (its bump commits them).
40
+ *
41
+ * @param {MonorepoSnapshot} state - Snapshot.
42
+ * @param {string} mode - Planned mode.
43
+ * @returns {string[]} `git status --porcelain` lines to set aside.
44
+ */
45
+ export declare function listMonorepoChangesToSetAside(state: MonorepoSnapshot, mode: string): string[];
46
+ /**
47
+ * Names the packages whose npm credentials the diagnosis checks: the ones the plan could publish.
48
+ *
49
+ * @param {MonorepoPlan} plan - Plan built without credentials.
50
+ * @returns {string[]} Package names.
51
+ */
52
+ export declare function listPackagesToAuthenticate(plan: MonorepoPlan): string[];
53
+ /**
54
+ * Decides what is still missing to release the monorepo from `main`.
55
+ *
56
+ * @param {MonorepoSnapshot} state - Snapshot gathered by `collectMonorepoState`.
57
+ * @param {ReleaseCapabilities} capabilities - Steps the project configured.
58
+ * @param {{ tagFormat: string, ignoreLocalChanges?: boolean, skipUnpublished?: boolean, selectAllPackages?: boolean }} options -
59
+ * Tag format and command-line options. `skipUnpublished` allows a new release despite missing publications;
60
+ * `selectAllPackages` requires updated changelogs for every candidate because the flags do not allow skips.
61
+ * @returns {MonorepoPlan} Ordered plan.
62
+ */
63
+ export declare function buildMonorepoPlan(state: MonorepoSnapshot, capabilities: ReleaseCapabilities, { tagFormat, ignoreLocalChanges, skipUnpublished, selectAllPackages }: {
64
+ tagFormat: string;
65
+ ignoreLocalChanges?: boolean;
66
+ skipUnpublished?: boolean;
67
+ selectAllPackages?: boolean;
68
+ }): MonorepoPlan;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Subject of the single release commit of a monorepo release:
3
+ * `release: @scope/a@1.2.0, @scope/b@0.3.1`. It records which packages the
4
+ * commit released, so a run can resume a local release commit that never
5
+ * reached `origin`.
6
+ *
7
+ * @module monorepo/release-commit
8
+ */
9
+ export type PackageRelease = {
10
+ name: string;
11
+ version: string;
12
+ };
13
+ /**
14
+ * @typedef {{ name: string, version: string }} PackageRelease
15
+ */
16
+ /**
17
+ * Builds the subject of a release commit.
18
+ *
19
+ * @param {readonly PackageRelease[]} releases - Released packages, in publication order.
20
+ * @returns {string} Subject.
21
+ */
22
+ export declare function buildMonorepoReleaseSubject(releases: readonly PackageRelease[]): string;
23
+ /**
24
+ * Reads the packages a release commit subject lists.
25
+ *
26
+ * @param {string | null | undefined} subject - Commit subject.
27
+ * @returns {PackageRelease[] | null} Released packages, or `null` when the subject is not a release commit.
28
+ */
29
+ export declare function parseMonorepoReleaseSubject(subject: string | null | undefined): PackageRelease[] | null;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Monorepo mode of `astra-rp create-version`: diagnoses every released
3
+ * workspace package, shows the plan and ships one release commit with a tag
4
+ * per package, then publishes each package in dependency order.
5
+ *
6
+ * It reuses the single-package steps that do not depend on the package
7
+ * (sync of `main`, migrations, checks, local changes, npm credentials,
8
+ * verified artifacts) and adds the per-package ones. Every step is derived
9
+ * from the current state, so running the command again after a failure
10
+ * resumes from the first missing step, including publications that npm never
11
+ * received: each one is prepared and published from its own release commit.
12
+ *
13
+ * @module monorepo/run
14
+ */
15
+ export type ReleaseUnit = import("./workspaces.js").ReleaseUnit;
16
+ export type MonorepoSnapshot = import("./state.js").MonorepoSnapshot;
17
+ export type PackageSnapshot = import("./state.js").PackageSnapshot;
18
+ export type MonorepoPlan = import("./plan.js").MonorepoPlan;
19
+ export type PendingPackageRelease = import("./plan.js").PendingPackageRelease;
20
+ export type ResolvedCreateVersionConfig = import("../create-version/config.js").ResolvedCreateVersionConfig;
21
+ export type ReleaseOptions = import("../create-version/plan.js").ReleaseOptions;
22
+ export type GitReader = import("../create-version/process.js").GitReader;
23
+ export type ChosenRelease = {
24
+ unit: ReleaseUnit;
25
+ snapshot: PackageSnapshot;
26
+ version: string;
27
+ tag: string;
28
+ commitSha: string | null;
29
+ };
30
+ export type MonorepoContext = {
31
+ repositoryRoot: string;
32
+ config: ResolvedCreateVersionConfig;
33
+ state: MonorepoSnapshot;
34
+ options: ReleaseOptions;
35
+ reader: GitReader;
36
+ commands: import("../package-manager.js").ProjectCommands;
37
+ tagFormat: string;
38
+ units: ReleaseUnit[];
39
+ plan: MonorepoPlan;
40
+ chosen: ChosenRelease[];
41
+ changelogFiles: import("../create-version/changelog.js").PreservedReleaseFile[];
42
+ preparedRoots: Set<string>;
43
+ pushed: boolean;
44
+ published: {
45
+ name: string;
46
+ version: string;
47
+ registryUrl: string | null;
48
+ registryLabel?: string;
49
+ packageName?: string;
50
+ }[];
51
+ };
52
+ /**
53
+ * Runs `create-version` in monorepo mode (`packages` in the configuration).
54
+ *
55
+ * @param {{
56
+ * repositoryRoot: string,
57
+ * config: ResolvedCreateVersionConfig,
58
+ * options: ReleaseOptions,
59
+ * startedAt: number,
60
+ * }} run - Repository, resolved configuration, command-line options and start time.
61
+ * @returns {Promise<number>} Exit code.
62
+ */
63
+ export declare function runMonorepoCreateVersion({ repositoryRoot, config, options: initialOptions, startedAt }: {
64
+ repositoryRoot: string;
65
+ config: ResolvedCreateVersionConfig;
66
+ options: ReleaseOptions;
67
+ startedAt: number;
68
+ }): Promise<number>;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Snapshot of a monorepo release: the repository part shared with the
3
+ * single-package mode (branch, working tree, `main` versus `origin/main`,
4
+ * pull request) plus, for every released package, its last release, the
5
+ * commits waiting to be released under its paths, its changelog and its
6
+ * published versions.
7
+ *
8
+ * Every reader is read-only; the network operations are `git fetch`,
9
+ * `git ls-remote`, `gh pr view` and the npm lookups.
10
+ *
11
+ * @module monorepo/state
12
+ */
13
+ import { checkNpmPublishAccess, lookupPublishedVersions } from "../create-version/npm.js";
14
+ import { lookupPullRequest } from "../create-version/state.js";
15
+ export type ReleaseUnit = import("./workspaces.js").ReleaseUnit;
16
+ export type GitReader = import("../create-version/process.js").GitReader;
17
+ export type CommitRecord = import("../create-version/process.js").CommitRecord;
18
+ export type NpmLookup = import("../create-version/npm.js").NpmLookup;
19
+ export type NpmAuthCheck = import("../create-version/npm.js").NpmAuthCheck;
20
+ export type MigrationCheck = import("../create-version/config.js").MigrationCheck;
21
+ export type PackageLastRelease = {
22
+ sha: string;
23
+ version: string | null;
24
+ subject: string | null;
25
+ tag: string | null;
26
+ tagged: boolean;
27
+ tagOnOrigin: boolean;
28
+ };
29
+ export type PackageSnapshot = {
30
+ unit: ReleaseUnit;
31
+ manifest: Record<string, unknown>;
32
+ releasedVersion: string | null;
33
+ lastRelease: PackageLastRelease | null;
34
+ unreleasedCommits: CommitRecord[];
35
+ changelog: {
36
+ exists: boolean;
37
+ entryCount: number;
38
+ unknownSections: string[];
39
+ updated: boolean;
40
+ reason: string | null;
41
+ };
42
+ npm: NpmLookup | null;
43
+ npmAuth: NpmAuthCheck | null;
44
+ };
45
+ export type MonorepoSnapshot = import("../create-version/state.js").RepositorySnapshot & {
46
+ headSha: string | null;
47
+ headSubject: string | null;
48
+ packages: PackageSnapshot[];
49
+ migrations: MigrationCheck | null;
50
+ };
51
+ /**
52
+ * Finds the last release of a package on a revision: the newest commit that changed its `version`,
53
+ * unless that version is an untagged `0.0.0` placeholder of a package that was never released.
54
+ *
55
+ * @param {GitReader} reader - Git reader.
56
+ * @param {string} revision - Revision such as `origin/main`.
57
+ * @param {ReleaseUnit} unit - Released package.
58
+ * @param {string} tagFormat - Tag format.
59
+ * @param {ReadonlySet<string>} remoteTags - Tags on `origin`.
60
+ * @returns {Promise<PackageLastRelease | null>} Last release, or `null` without history or when the
61
+ * newest version change is the untagged commit that added the package or leaves it at `0.0.0`
62
+ * (neither pointed at by the package's own tag nor listed in a `release: …` commit).
63
+ */
64
+ export declare function findLastPackageRelease(reader: GitReader, revision: string, unit: ReleaseUnit, tagFormat: string, remoteTags: ReadonlySet<string>): Promise<PackageLastRelease | null>;
65
+ /**
66
+ * Gathers the monorepo release snapshot.
67
+ *
68
+ * @param {{
69
+ * repositoryRoot: string,
70
+ * units: readonly ReleaseUnit[],
71
+ * tagFormat: string,
72
+ * trackNpm?: boolean,
73
+ * checkMigrations?: (() => Promise<MigrationCheck> | MigrationCheck) | null,
74
+ * onProgress?: (label: string) => void,
75
+ * lookupNpm?: typeof lookupPublishedVersions,
76
+ * checkNpmAuthFor?: ((snapshot: MonorepoSnapshot) => string[]) | null,
77
+ * checkNpmAccess?: typeof checkNpmPublishAccess,
78
+ * lookupPullRequestFor?: typeof lookupPullRequest,
79
+ * registrySelection?: import("../create-version/registry.js").RegistrySelection,
80
+ * }} options - Repository, released packages, adapters and progress callback. `checkNpmAuthFor`
81
+ * receives the snapshot without credentials and names the packages whose credentials are checked.
82
+ * @returns {Promise<MonorepoSnapshot>} Snapshot accepted by `buildMonorepoPlan`.
83
+ */
84
+ export declare function collectMonorepoState({ repositoryRoot, units, tagFormat, trackNpm, checkMigrations, onProgress, lookupNpm, checkNpmAuthFor, checkNpmAccess, lookupPullRequestFor, registrySelection, }: {
85
+ repositoryRoot: string;
86
+ units: readonly ReleaseUnit[];
87
+ tagFormat: string;
88
+ trackNpm?: boolean;
89
+ checkMigrations?: (() => Promise<MigrationCheck> | MigrationCheck) | null;
90
+ onProgress?: (label: string) => void;
91
+ lookupNpm?: typeof lookupPublishedVersions;
92
+ checkNpmAuthFor?: ((snapshot: MonorepoSnapshot) => string[]) | null;
93
+ checkNpmAccess?: typeof checkNpmPublishAccess;
94
+ lookupPullRequestFor?: typeof lookupPullRequest;
95
+ registrySelection?: import("../create-version/registry.js").RegistrySelection;
96
+ }): Promise<MonorepoSnapshot>;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Workspace discovery of the monorepo mode: which packages a repository
3
+ * holds, which of them are released (every non-`private` one) and which paths
4
+ * count as changes of each released package.
5
+ *
6
+ * A released package changes when its own directory changes, and also when a
7
+ * `private` workspace package it depends on changes (transitively): internal
8
+ * packages are usually bundled into their consumers (`noExternal`), so a fix
9
+ * there ships only through a new release of each consumer.
10
+ *
11
+ * @module monorepo/workspaces
12
+ */
13
+ export type WorkspacePackage = {
14
+ name: string;
15
+ directory: string;
16
+ private: boolean;
17
+ version: string | null;
18
+ manifest: Record<string, unknown>;
19
+ };
20
+ export type ReleaseUnit = {
21
+ name: string;
22
+ directory: string;
23
+ component: string;
24
+ manifestPath: string;
25
+ changelogPath: string;
26
+ version: string | null;
27
+ changePaths: string[];
28
+ publishedDependencies: string[];
29
+ };
30
+ /**
31
+ * Reads the workspace patterns the root `package.json` declares (`workspaces` as a list, or as an
32
+ * object with `packages`, as Yarn and Bun accept).
33
+ *
34
+ * @param {Record<string, unknown> | null} rootManifest - Root `package.json`.
35
+ * @returns {string[]} Patterns.
36
+ */
37
+ export declare function readDeclaredWorkspaces(rootManifest: Record<string, unknown> | null): string[];
38
+ /**
39
+ * Expands workspace patterns into package directories. Supported: exact directories
40
+ * (`packages/cli`), direct children (`packages/*`) and exclusions (`!packages/internal`).
41
+ *
42
+ * @param {string} repositoryRoot - Repository root.
43
+ * @param {readonly string[]} patterns - Workspace patterns.
44
+ * @returns {string[]} Directories relative to the root that hold a `package.json`, sorted.
45
+ * @throws {Error} When a pattern escapes the repository or uses a glob beyond a trailing `/*`.
46
+ */
47
+ export declare function expandWorkspacePatterns(repositoryRoot: string, patterns: readonly string[]): string[];
48
+ /**
49
+ * Lists the workspace packages of a repository.
50
+ *
51
+ * @param {string} repositoryRoot - Repository root.
52
+ * @param {"workspaces" | readonly string[]} packages - `packages` of the configuration: the root workspaces, or explicit patterns.
53
+ * @returns {WorkspacePackage[]} Packages with a `name` (private ones without it are skipped), sorted by directory.
54
+ * @throws {Error} When a matched manifest is malformed, non-private without a `name` or without a stable `X.Y.Z` `version`, no package is found or two packages share a name.
55
+ */
56
+ export declare function discoverWorkspacePackages(repositoryRoot: string, packages: "workspaces" | readonly string[]): WorkspacePackage[];
57
+ /**
58
+ * Turns the workspace packages into release units: one per non-`private` package.
59
+ *
60
+ * @param {readonly WorkspacePackage[]} workspacePackages - Result of {@link discoverWorkspacePackages}.
61
+ * @returns {ReleaseUnit[]} Released packages, sorted by directory.
62
+ */
63
+ export declare function resolveReleaseUnits(workspacePackages: readonly WorkspacePackage[]): ReleaseUnit[];
64
+ /**
65
+ * Orders packages so every one comes after the released packages it installs.
66
+ *
67
+ * @template {{ name: string, publishedDependencies: string[] }} T
68
+ * @param {readonly T[]} units - Packages to publish.
69
+ * @returns {T[]} Same packages, dependencies first (stable for independent packages).
70
+ */
71
+ export declare function sortByPublicationOrder<T extends {
72
+ name: string;
73
+ publishedDependencies: string[];
74
+ }>(units: readonly T[]): T[];
75
+ /**
76
+ * Builds the Git tag of a package release.
77
+ *
78
+ * @param {string} tagFormat - Format with `{version}` and optionally `{component}` / `{name}`.
79
+ * @param {{ name: string, component: string }} unit - Released package.
80
+ * @param {string} version - Released version.
81
+ * @returns {string} Tag such as `widget-v1.2.0`.
82
+ */
83
+ export declare function formatPackageTag(tagFormat: string, unit: {
84
+ name: string;
85
+ component: string;
86
+ }, version: string): string;