@intentius/chant 0.124.100 → 0.124.102

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 (270) hide show
  1. package/dist/action-pins.d.ts +2 -0
  2. package/dist/action-pins.js +3 -0
  3. package/dist/ci-detect.d.ts +13 -0
  4. package/dist/ci-detect.js +12 -0
  5. package/dist/ci-evidence-claims.d.ts +12 -0
  6. package/dist/ci-evidence-claims.js +12 -0
  7. package/dist/ci-system.d.ts +66 -0
  8. package/dist/ci-system.js +61 -0
  9. package/dist/cli/handlers/build.js +27 -0
  10. package/dist/cli/handlers/release-doctor.d.ts +12 -0
  11. package/dist/cli/handlers/release-doctor.js +118 -0
  12. package/dist/cli/handlers/release-init.d.ts +10 -0
  13. package/dist/cli/handlers/release-init.js +374 -0
  14. package/dist/cli/handlers/release.d.ts +43 -2
  15. package/dist/cli/handlers/release.js +667 -39
  16. package/dist/cli/handlers/run-generate.js +11 -0
  17. package/dist/cli/main.d.ts +2 -0
  18. package/dist/cli/main.js +44 -101
  19. package/dist/cli/parse-args.js +48 -0
  20. package/dist/cli/registry.d.ts +16 -0
  21. package/dist/cli/release-commands/artifacts.d.ts +3 -0
  22. package/dist/cli/release-commands/artifacts.js +14 -0
  23. package/dist/cli/release-commands/candidates.d.ts +3 -0
  24. package/dist/cli/release-commands/candidates.js +16 -0
  25. package/dist/cli/release-commands/changed.d.ts +3 -0
  26. package/dist/cli/release-commands/changed.js +14 -0
  27. package/dist/cli/release-commands/compose.d.ts +3 -0
  28. package/dist/cli/release-commands/compose.js +16 -0
  29. package/dist/cli/release-commands/cut.d.ts +3 -0
  30. package/dist/cli/release-commands/cut.js +50 -0
  31. package/dist/cli/release-commands/doctor.d.ts +3 -0
  32. package/dist/cli/release-commands/doctor.js +14 -0
  33. package/dist/cli/release-commands/export.d.ts +3 -0
  34. package/dist/cli/release-commands/export.js +12 -0
  35. package/dist/cli/release-commands/images.d.ts +3 -0
  36. package/dist/cli/release-commands/images.js +13 -0
  37. package/dist/cli/release-commands/index.d.ts +8 -0
  38. package/dist/cli/release-commands/index.js +52 -0
  39. package/dist/cli/release-commands/init.d.ts +3 -0
  40. package/dist/cli/release-commands/init.js +19 -0
  41. package/dist/cli/release-commands/list.d.ts +3 -0
  42. package/dist/cli/release-commands/list.js +10 -0
  43. package/dist/cli/release-commands/next.d.ts +3 -0
  44. package/dist/cli/release-commands/next.js +13 -0
  45. package/dist/cli/release-commands/publish.d.ts +3 -0
  46. package/dist/cli/release-commands/publish.js +22 -0
  47. package/dist/cli/release-commands/stamp.d.ts +3 -0
  48. package/dist/cli/release-commands/stamp.js +15 -0
  49. package/dist/cli/release-commands/status.d.ts +3 -0
  50. package/dist/cli/release-commands/status.js +17 -0
  51. package/dist/cli/release-commands/tag.d.ts +3 -0
  52. package/dist/cli/release-commands/tag.js +12 -0
  53. package/dist/cli/release-commands/types.d.ts +20 -0
  54. package/dist/cli/release-commands/types.js +1 -0
  55. package/dist/cli/release-commands/verify.d.ts +3 -0
  56. package/dist/cli/release-commands/verify.js +15 -0
  57. package/dist/cli/release-commands/workflow.d.ts +3 -0
  58. package/dist/cli/release-commands/workflow.js +15 -0
  59. package/dist/cloud-lister/index.d.ts +4 -1
  60. package/dist/cloud-lister/index.js +2 -1
  61. package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
  62. package/dist/cloud-lister/kubernetes-components.js +642 -0
  63. package/dist/cloud-lister/kubernetes.d.ts +18 -0
  64. package/dist/cloud-lister/kubernetes.js +26 -1
  65. package/dist/cloud-lister/mask.d.ts +5 -1
  66. package/dist/cloud-lister/mask.js +14 -5
  67. package/dist/components/cli-support.d.ts +1 -1
  68. package/dist/components/cli-support.js +1 -1
  69. package/dist/config-environments.d.ts +8 -1
  70. package/dist/config-environments.js +2 -0
  71. package/dist/config-import.d.ts +1 -1
  72. package/dist/config-import.js +6 -2
  73. package/dist/config-sandbox.d.ts +1 -1
  74. package/dist/config-sandbox.js +3 -3
  75. package/dist/config.d.ts +369 -10
  76. package/dist/config.js +127 -7
  77. package/dist/deep-observation.js +9 -3
  78. package/dist/floor-table.data.js +21 -1
  79. package/dist/forge-remote.d.ts +13 -0
  80. package/dist/forge-remote.js +15 -0
  81. package/dist/lexicon.d.ts +45 -4
  82. package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
  83. package/dist/lifecycle/__fixtures__/package-files.js +72 -0
  84. package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
  85. package/dist/lifecycle/__fixtures__/publish-fakes.js +275 -3
  86. package/dist/lifecycle/publish-attachments.d.ts +2 -1
  87. package/dist/lifecycle/publish-attachments.js +19 -2
  88. package/dist/lifecycle/publish-cargo.d.ts +99 -0
  89. package/dist/lifecycle/publish-cargo.js +412 -0
  90. package/dist/lifecycle/publish-credentials.d.ts +1 -1
  91. package/dist/lifecycle/publish-credentials.js +13 -0
  92. package/dist/lifecycle/publish-declaration.d.ts +322 -4
  93. package/dist/lifecycle/publish-declaration.js +340 -9
  94. package/dist/lifecycle/publish-forge.d.ts +45 -2
  95. package/dist/lifecycle/publish-forge.js +434 -34
  96. package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
  97. package/dist/lifecycle/publish-git-ssh.js +30 -4
  98. package/dist/lifecycle/publish-github.d.ts +40 -2
  99. package/dist/lifecycle/publish-github.js +100 -3
  100. package/dist/lifecycle/publish-helm.d.ts +83 -0
  101. package/dist/lifecycle/publish-helm.js +452 -0
  102. package/dist/lifecycle/publish-homebrew.d.ts +7 -9
  103. package/dist/lifecycle/publish-homebrew.js +34 -197
  104. package/dist/lifecycle/publish-index.d.ts +141 -0
  105. package/dist/lifecycle/publish-index.js +719 -0
  106. package/dist/lifecycle/publish-marketplace.js +77 -0
  107. package/dist/lifecycle/publish-maven.d.ts +79 -0
  108. package/dist/lifecycle/publish-maven.js +364 -0
  109. package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
  110. package/dist/lifecycle/publish-mcp-registry.js +305 -0
  111. package/dist/lifecycle/publish-npm.d.ts +27 -1
  112. package/dist/lifecycle/publish-npm.js +216 -3
  113. package/dist/lifecycle/publish-nuget.d.ts +93 -0
  114. package/dist/lifecycle/publish-nuget.js +377 -0
  115. package/dist/lifecycle/publish-oci.d.ts +91 -2
  116. package/dist/lifecycle/publish-oci.js +247 -8
  117. package/dist/lifecycle/publish-package-files.d.ts +16 -0
  118. package/dist/lifecycle/publish-package-files.js +39 -0
  119. package/dist/lifecycle/publish-pypi.d.ts +138 -0
  120. package/dist/lifecycle/publish-pypi.js +657 -0
  121. package/dist/lifecycle/publish-record.d.ts +6 -3
  122. package/dist/lifecycle/publish-record.js +6 -3
  123. package/dist/lifecycle/publish-rubygems.d.ts +84 -0
  124. package/dist/lifecycle/publish-rubygems.js +366 -0
  125. package/dist/lifecycle/publish-signing.d.ts +147 -0
  126. package/dist/lifecycle/publish-signing.js +257 -0
  127. package/dist/lifecycle/publish-targets.d.ts +37 -1
  128. package/dist/lifecycle/publish-targets.js +102 -0
  129. package/dist/lifecycle/publish-tauri.js +43 -0
  130. package/dist/lifecycle/publish-train-names.d.ts +57 -0
  131. package/dist/lifecycle/publish-train-names.js +123 -0
  132. package/dist/lifecycle/publish-verify.d.ts +121 -0
  133. package/dist/lifecycle/publish-verify.js +130 -0
  134. package/dist/lifecycle/query.js +8 -0
  135. package/dist/lifecycle/release-artifacts.d.ts +290 -0
  136. package/dist/lifecycle/release-artifacts.js +808 -0
  137. package/dist/lifecycle/release-changelog.d.ts +13 -1
  138. package/dist/lifecycle/release-changelog.js +35 -2
  139. package/dist/lifecycle/release-cut.d.ts +64 -4
  140. package/dist/lifecycle/release-cut.js +147 -34
  141. package/dist/lifecycle/release-doctor.d.ts +113 -0
  142. package/dist/lifecycle/release-doctor.js +1198 -0
  143. package/dist/lifecycle/release-green.d.ts +86 -0
  144. package/dist/lifecycle/release-green.js +286 -0
  145. package/dist/lifecycle/release-init-registries.d.ts +48 -0
  146. package/dist/lifecycle/release-init-registries.js +97 -0
  147. package/dist/lifecycle/release-init.d.ts +275 -0
  148. package/dist/lifecycle/release-init.js +984 -0
  149. package/dist/lifecycle/release-intents.d.ts +73 -0
  150. package/dist/lifecycle/release-intents.js +128 -0
  151. package/dist/lifecycle/release-next.d.ts +111 -0
  152. package/dist/lifecycle/release-next.js +251 -0
  153. package/dist/lifecycle/release-prerelease.d.ts +19 -0
  154. package/dist/lifecycle/release-prerelease.js +30 -0
  155. package/dist/lifecycle/release-publish.d.ts +256 -10
  156. package/dist/lifecycle/release-publish.js +247 -35
  157. package/dist/lifecycle/release-status-change.d.ts +226 -0
  158. package/dist/lifecycle/release-status-change.js +478 -0
  159. package/dist/lifecycle/release-status.d.ts +11 -0
  160. package/dist/lifecycle/release-status.js +1 -1
  161. package/dist/lifecycle/release-store.d.ts +73 -2
  162. package/dist/lifecycle/release-store.js +32 -1
  163. package/dist/lifecycle/release-tag.d.ts +142 -0
  164. package/dist/lifecycle/release-tag.js +322 -0
  165. package/dist/lifecycle/release-verify.d.ts +73 -1
  166. package/dist/lifecycle/release-verify.js +117 -2
  167. package/dist/lifecycle/release-version-formats.d.ts +73 -0
  168. package/dist/lifecycle/release-version-formats.js +570 -0
  169. package/dist/lifecycle/release-version.d.ts +58 -10
  170. package/dist/lifecycle/release-version.js +164 -36
  171. package/dist/lifecycle/release-workstation.d.ts +3 -2
  172. package/dist/lifecycle/release-workstation.js +3 -2
  173. package/dist/op/generate-pipeline.js +1 -1
  174. package/dist/op/local-executor.d.ts +1 -1
  175. package/dist/op/local-executor.js +2 -2
  176. package/dist/op/op-waves-evidence.js +9 -2
  177. package/dist/pr-forge-base.js +4 -2
  178. package/dist/pr-forge.d.ts +20 -2
  179. package/dist/pr-forge.js +46 -10
  180. package/dist/release-floors.d.ts +8 -1
  181. package/dist/release-floors.js +9 -2
  182. package/dist/sensitive-key.d.ts +12 -0
  183. package/dist/sensitive-key.js +52 -0
  184. package/dist/tool-pins.d.ts +40 -0
  185. package/dist/tool-pins.js +66 -0
  186. package/dist/ts-loader.d.ts +8 -0
  187. package/dist/ts-loader.js +19 -0
  188. package/dist/wave-runtime.mjs +345 -342
  189. package/dist/workspace/ci-forge.d.ts +17 -0
  190. package/dist/workspace/ci-forge.js +17 -0
  191. package/dist/workspace/ci-init.js +1 -1
  192. package/dist/workspace/composites.schema.json +1 -0
  193. package/dist/workspace/declaration.d.ts +8 -0
  194. package/dist/workspace/declaration.js +12 -0
  195. package/dist/workspace/declaration.schema.json +8 -0
  196. package/dist/workspace/environments.d.ts +2 -0
  197. package/dist/workspace/environments.js +1 -1
  198. package/dist/workspace/identity-gate-rule.d.ts +61 -5
  199. package/dist/workspace/identity-gate-rule.js +81 -12
  200. package/dist/workspace/lexicon-outputs.d.ts +1 -1
  201. package/dist/workspace/lexicon-outputs.js +1 -1
  202. package/dist/workspace/member-pipeline.d.ts +2 -1
  203. package/dist/workspace/member-pipeline.js +5 -2
  204. package/dist/workspace/reason-codes.d.ts +2 -0
  205. package/dist/workspace/reason-codes.js +3 -1
  206. package/dist/workspace/release-changed.d.ts +75 -4
  207. package/dist/workspace/release-changed.js +205 -34
  208. package/dist/workspace/release-changed.schema.json +20 -2
  209. package/dist/workspace/release-steps/artifacts.d.ts +7 -0
  210. package/dist/workspace/release-steps/artifacts.js +45 -0
  211. package/dist/workspace/release-steps/builds.d.ts +12 -0
  212. package/dist/workspace/release-steps/builds.js +38 -0
  213. package/dist/workspace/release-steps/doctor.d.ts +8 -0
  214. package/dist/workspace/release-steps/doctor.js +14 -0
  215. package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
  216. package/dist/workspace/release-steps/goreleaser.js +36 -0
  217. package/dist/workspace/release-steps/green.d.ts +3 -0
  218. package/dist/workspace/release-steps/green.js +6 -0
  219. package/dist/workspace/release-steps/images.d.ts +22 -0
  220. package/dist/workspace/release-steps/images.js +59 -0
  221. package/dist/workspace/release-steps/index.d.ts +9 -0
  222. package/dist/workspace/release-steps/index.js +50 -0
  223. package/dist/workspace/release-steps/nfpm.d.ts +13 -0
  224. package/dist/workspace/release-steps/nfpm.js +29 -0
  225. package/dist/workspace/release-steps/nuget.d.ts +14 -0
  226. package/dist/workspace/release-steps/nuget.js +16 -0
  227. package/dist/workspace/release-steps/pypi.d.ts +15 -0
  228. package/dist/workspace/release-steps/pypi.js +21 -0
  229. package/dist/workspace/release-steps/qemu.d.ts +21 -0
  230. package/dist/workspace/release-steps/qemu.js +35 -0
  231. package/dist/workspace/release-steps/signing.d.ts +18 -0
  232. package/dist/workspace/release-steps/signing.js +30 -0
  233. package/dist/workspace/release-steps/stamp.d.ts +3 -0
  234. package/dist/workspace/release-steps/stamp.js +4 -0
  235. package/dist/workspace/release-steps/targets.d.ts +31 -0
  236. package/dist/workspace/release-steps/targets.js +40 -0
  237. package/dist/workspace/release-steps/types.d.ts +104 -0
  238. package/dist/workspace/release-steps/types.js +2 -0
  239. package/dist/workspace/release-steps/verify.d.ts +3 -0
  240. package/dist/workspace/release-steps/verify.js +4 -0
  241. package/dist/workspace/release-toolchains.d.ts +59 -0
  242. package/dist/workspace/release-toolchains.js +133 -0
  243. package/dist/workspace/release-train-workflow.d.ts +36 -0
  244. package/dist/workspace/release-train-workflow.js +121 -0
  245. package/dist/workspace/release-train.d.ts +3 -1
  246. package/dist/workspace/release-train.js +20 -3
  247. package/dist/workspace/release-workflow.d.ts +183 -59
  248. package/dist/workspace/release-workflow.js +570 -201
  249. package/dist/workspace/releases.schema.json +70 -1
  250. package/dist/workspace/search-contract.d.ts +1 -1
  251. package/dist/workspace/security.js +9 -2
  252. package/dist/workspace/train-cut.d.ts +182 -0
  253. package/dist/workspace/train-cut.js +504 -0
  254. package/dist/workspace/train-prepare.d.ts +64 -0
  255. package/dist/workspace/train-prepare.js +313 -0
  256. package/dist/workspace/train-publish.d.ts +177 -0
  257. package/dist/workspace/train-publish.js +574 -0
  258. package/dist/workspace/train-range-labels.d.ts +33 -0
  259. package/dist/workspace/train-range-labels.js +109 -0
  260. package/dist/workspace/train-shell.d.ts +5 -0
  261. package/dist/workspace/train-shell.js +17 -0
  262. package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
  263. package/dist/workspace/trust/check-evidence-report.js +3 -7
  264. package/dist/workspace/trust/seal.d.ts +13 -3
  265. package/dist/workspace/trust/seal.js +14 -4
  266. package/dist/workspace/work-cli.d.ts +3 -2
  267. package/dist/workspace/work-cli.js +3 -2
  268. package/dist/workspace/workspace-ledger.d.ts +14 -1
  269. package/dist/workspace/workspace-ledger.js +33 -7
  270. package/package.json +1 -1
@@ -0,0 +1,305 @@
1
+ /**
2
+ * The MCP Registry target (#5162): a `server.json` published to the official
3
+ * MCP Registry, https://registry.modelcontextprotocol.io, so MCP clients find
4
+ * the server. A `server.json` names the npm packages, PyPI packages or OCI
5
+ * images that run the server, and the registry checks they exist, so this
6
+ * target reveals after every other target (`revealsLast`).
7
+ *
8
+ * It speaks the registry's HTTP API directly, the requests `mcp-publisher
9
+ * login github-oidc` and `mcp-publisher publish` make, so no tool is
10
+ * downloaded or run:
11
+ *
12
+ * - `POST /v0.1/auth/github-oidc` with `{ "oidc_token": ... }` exchanges the
13
+ * GitHub Actions OIDC token, requested with the registry's origin
14
+ * (`https://registry.modelcontextprotocol.io`) as its audience, for a
15
+ * registry token that lasts minutes. `POST /v0.1/auth/github-at` does the
16
+ * same for a GitHub token (`{ "github_token": ... }`).
17
+ * - `GET /v0.1/servers/{name}/versions/{version}` says whether a version is
18
+ * already published.
19
+ * - `POST /v0.1/publish` with the `server.json` as the body and the registry
20
+ * token as a bearer credential publishes it.
21
+ *
22
+ * The registry has no draft and refuses a version it already holds, and it
23
+ * does not let a version be replaced. So the stage sends nothing: it checks
24
+ * the `server.json` against the release, exchanges for a token to prove the
25
+ * credentials work, and reads whether the version is there. The reveal
26
+ * publishes.
27
+ *
28
+ * The `server.json` must belong to this release: its `version` is the
29
+ * release's label (from its first digit), and each package that names a
30
+ * version, and each OCI image's tag, is the same. Anything else is refused in
31
+ * the plan (`publish-mcp-registry-version-mismatch`,
32
+ * `publish-mcp-registry-package-mismatch`), so a release can't publish a
33
+ * listing for another version. `release.version.files` stamps the label into
34
+ * the file.
35
+ */
36
+ import { readFileSync } from "node:fs";
37
+ import { readCredential } from "./publish-credentials.js";
38
+ import { releaseVersion } from "./publish-homebrew.js";
39
+ import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
40
+ import { trainName, waitUntilServed } from "./publish-train-names.js";
41
+ import { PublishTargetError } from "./release-publish.js";
42
+ /** The first chant with the `mcp-registry` publish target: a `server.json` published to the MCP Registry after the packages it names, with GitHub OIDC, and the `mcp-registry-*` checks of `chant release doctor` (#5162). */
43
+ export const PUBLISH_MCP_REGISTRY_FLOOR = "0.124.101";
44
+ export const MCP_REGISTRY = "https://registry.modelcontextprotocol.io";
45
+ /** The variable a `github-token` target reads by default. */
46
+ export const MCP_GITHUB_TOKEN_ENV = "MCP_GITHUB_TOKEN";
47
+ /** The variable a `registry-token` target reads by default. */
48
+ export const MCP_REGISTRY_TOKEN_ENV = "MCP_REGISTRY_TOKEN";
49
+ /** The declaration's `auth`, refused when `tokenEnv` is set beside the OIDC exchange, which reads none. */
50
+ export function mcpRegistryAuth(decl) {
51
+ const auth = decl.auth ?? "github-oidc";
52
+ if (auth === "github-oidc" && decl.tokenEnv !== undefined) {
53
+ throw new PublishTargetError("publish-mcp-registry-auth-invalid", "tokenEnv names a token, and auth: github-oidc reads none", "Leave tokenEnv out, or set auth to github-token or registry-token in release.publish.");
54
+ }
55
+ return auth;
56
+ }
57
+ /** The variables the target's credential is read from, whose values are masked. */
58
+ export function mcpRegistryTokenEnv(decl) {
59
+ const auth = decl.auth ?? "github-oidc";
60
+ if (auth === "github-oidc")
61
+ return ["ACTIONS_ID_TOKEN_REQUEST_TOKEN"];
62
+ return [decl.tokenEnv ?? (auth === "github-token" ? MCP_GITHUB_TOKEN_ENV : MCP_REGISTRY_TOKEN_ENV)];
63
+ }
64
+ /** The registry's origin, which is the audience of the OIDC token: scheme and lowercased host. */
65
+ export function mcpRegistryAudience(registry) {
66
+ const u = new URL(registry);
67
+ return `${u.protocol}//${u.host.toLowerCase()}`;
68
+ }
69
+ /** The tag of an OCI image reference, `null` for one with a digest or no tag. */
70
+ function ociTag(identifier) {
71
+ if (identifier.includes("@"))
72
+ return null;
73
+ const last = identifier.slice(identifier.lastIndexOf("/") + 1);
74
+ const colon = last.indexOf(":");
75
+ return colon < 0 ? "" : last.slice(colon + 1);
76
+ }
77
+ /**
78
+ * Read `text` as a `server.json` and check it is the release's: `label` is
79
+ * the release's label. Throws {@link PublishTargetError}.
80
+ */
81
+ export function checkServerJson(text, path, label) {
82
+ let raw;
83
+ try {
84
+ raw = JSON.parse(text);
85
+ }
86
+ catch (err) {
87
+ throw new PublishTargetError("publish-mcp-registry-server-invalid", `${path} is not JSON: ${err instanceof Error ? err.message : String(err)}`, "Fix the file, or check it with: mcp-publisher validate");
88
+ }
89
+ const o = raw;
90
+ if (typeof raw !== "object" || raw === null || typeof o.name !== "string" || !o.name || typeof o.version !== "string" || !o.version) {
91
+ throw new PublishTargetError("publish-mcp-registry-server-invalid", `${path} needs a name and a version`, "A server.json names the server as io.github.<owner>/<name> or <reversed domain>/<name>.");
92
+ }
93
+ if (o.packages !== undefined && !Array.isArray(o.packages)) {
94
+ throw new PublishTargetError("publish-mcp-registry-server-invalid", `${path}'s packages is not a list`);
95
+ }
96
+ const version = releaseVersion(label);
97
+ if (label === null || version === null) {
98
+ throw new PublishTargetError("publish-mcp-registry-version-mismatch", `${path} can't be matched to this release: it has no label with a version in it`, "Cut the release with a label such as 1.4.0.");
99
+ }
100
+ const fix = `Stamp the label into the file with release.version.files in chant.config.ts, or set the version to ${version}.`;
101
+ if (o.version !== version && o.version !== label) {
102
+ throw new PublishTargetError("publish-mcp-registry-version-mismatch", `${path} has version ${o.version}, and this release is ${label}`, fix);
103
+ }
104
+ const packages = (o.packages ?? []).map((p) => (typeof p === "object" && p !== null ? p : {}));
105
+ packages.forEach((p, i) => {
106
+ const where = `${path}'s packages[${i}]${p.identifier ? ` (${p.identifier})` : ""}`;
107
+ if (p.registryType === "oci") {
108
+ const tag = typeof p.identifier === "string" ? ociTag(p.identifier) : null;
109
+ if (typeof p.identifier === "string" && tag !== null && tag !== version && tag !== label) {
110
+ throw new PublishTargetError("publish-mcp-registry-package-mismatch", `${where} names the tag ${tag || "(none)"}, and this release is ${label}`, `Name the image as <image>:${version}, or by digest.`);
111
+ }
112
+ }
113
+ else if (p.registryType === "mcpb") {
114
+ // An mcpb package is a file at a URL; its version, when it has one, is checked below.
115
+ if (p.version !== undefined && p.version !== version && p.version !== label) {
116
+ throw new PublishTargetError("publish-mcp-registry-package-mismatch", `${where} has version ${p.version}, and this release is ${label}`, fix);
117
+ }
118
+ }
119
+ else if (p.version !== version && p.version !== label) {
120
+ throw new PublishTargetError("publish-mcp-registry-package-mismatch", `${where} has version ${p.version ?? "(none)"}, and this release is ${label}`, fix);
121
+ }
122
+ });
123
+ return { name: o.name, version: o.version, packages };
124
+ }
125
+ const packageKey = (p) => `${p.registryType ?? ""}:${p.identifier ?? ""}:${p.version ?? ""}`;
126
+ export function mcpRegistryTarget(decl, deps) {
127
+ const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
128
+ const auth = mcpRegistryAuth(decl);
129
+ const tokenNames = mcpRegistryTokenEnv(decl);
130
+ const path = decl.server ?? "server.json";
131
+ const registry = (decl.registry ?? MCP_REGISTRY).replace(/\/+$/, "");
132
+ const setup = (ctx) => {
133
+ const abs = memberFile(ctx.cwd, path);
134
+ const bytes = readFileSync(abs);
135
+ const digest = bytesDigest(new Uint8Array(bytes));
136
+ checkReleaseDigest(ctx.release, "asset", ctx.cwd, path, [digest]);
137
+ const server = checkServerJson(bytes.toString("utf-8"), path, ctx.label);
138
+ let token = null;
139
+ if (auth === "github-oidc") {
140
+ if (!(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL && ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)) {
141
+ throw new PublishTargetError("publish-credentials-missing", "the MCP Registry target publishes with GitHub OIDC, and this run has no OIDC token: not a GitHub Actions job with id-token: write", "Give the job permissions: id-token: write, or set auth to github-token or registry-token.");
142
+ }
143
+ }
144
+ else {
145
+ token = readCredential(ctx.env, tokenNames, ctx.redactor);
146
+ if (!token) {
147
+ throw new PublishTargetError("publish-credentials-missing", `the MCP Registry target reads its token from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]} in the job's or the shell's environment.`);
148
+ }
149
+ }
150
+ const item = { name: `${server.name}@${server.version}`, destination: `${registry}/v0.1/servers/${encodeURIComponent(server.name)}/versions/${encodeURIComponent(server.version)}`, digest };
151
+ return { bytes, server, token, item };
152
+ };
153
+ const call = async (url, init) => {
154
+ const res = await fetchImpl(url, { ...init, headers: { "user-agent": "chant", accept: "application/json", ...init.headers } });
155
+ const text = await res.text().catch(() => "");
156
+ let json = null;
157
+ try {
158
+ json = text ? JSON.parse(text) : null;
159
+ }
160
+ catch {
161
+ json = null;
162
+ }
163
+ return { status: res.status, text, json };
164
+ };
165
+ const why = (ctx, r) => {
166
+ const j = r.json;
167
+ const said = typeof j?.detail === "string" ? j.detail : typeof j?.title === "string" ? j.title : r.text.slice(0, 300);
168
+ return ctx.redactor.redact(`it answered ${r.status}${said ? `: ${said}` : ""}`);
169
+ };
170
+ /** The OIDC token for the registry's origin, from GitHub Actions' token service. */
171
+ const oidcToken = async (ctx) => {
172
+ const url = new URL(ctx.env.ACTIONS_ID_TOKEN_REQUEST_URL ?? "");
173
+ url.searchParams.set("audience", mcpRegistryAudience(registry));
174
+ const res = await call(url.toString(), { method: "GET", headers: { authorization: `Bearer ${ctx.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN ?? ""}` } });
175
+ const value = res.json?.value;
176
+ if (res.status !== 200 || typeof value !== "string" || !value) {
177
+ throw new PublishTargetError("publish-mcp-registry-auth", ctx.redactor.redact(`GitHub Actions gave no OIDC token for ${mcpRegistryAudience(registry)}: it answered ${res.status}`), "Give the job permissions: id-token: write.");
178
+ }
179
+ ctx.redactor.add(value);
180
+ return value;
181
+ };
182
+ /** A registry token: exchanged for the OIDC or GitHub token, or the one the variable holds. It lasts minutes, so each step gets its own. */
183
+ const registryToken = async (ctx, token) => {
184
+ if (auth === "registry-token")
185
+ return token.value;
186
+ const exchange = auth === "github-oidc"
187
+ ? { path: "/v0.1/auth/github-oidc", body: { oidc_token: await oidcToken(ctx) } }
188
+ : { path: "/v0.1/auth/github-at", body: { github_token: token.value } };
189
+ const res = await call(`${registry}${exchange.path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(exchange.body) });
190
+ const value = res.json?.registry_token;
191
+ if (res.status !== 200 || typeof value !== "string" || !value) {
192
+ throw new PublishTargetError("publish-mcp-registry-auth", `the MCP Registry at ${registry} gave no registry token: ${why(ctx, res)}`, auth === "github-oidc" ? "The registry takes a GitHub Actions run as the owner of io.github.<owner>/*. Name the server io.github.<owner>/<name> for the repository's owner." : "Check the token, and that its owner may publish the server's namespace.");
193
+ }
194
+ ctx.redactor.add(value);
195
+ return value;
196
+ };
197
+ /** The packages the registry holds for the version, or null when it holds none. */
198
+ const served = async (ctx, server) => {
199
+ const res = await call(`${registry}/v0.1/servers/${encodeURIComponent(server.name)}/versions/${encodeURIComponent(server.version)}`, { method: "GET", headers: {} });
200
+ if (res.status === 404)
201
+ return null;
202
+ if (res.status !== 200)
203
+ throw new PublishTargetError("publish-mcp-registry-failed", `reading ${server.name}@${server.version} on the MCP Registry: ${why(ctx, res)}`);
204
+ const held = res.json?.server?.packages;
205
+ return (Array.isArray(held) ? held : []).map(packageKey).sort();
206
+ };
207
+ const target = {
208
+ kind: "mcp-registry",
209
+ name: `mcp-registry ${path}`,
210
+ destination: registry,
211
+ credentialEnv: tokenNames,
212
+ key: publishTargetKey(decl),
213
+ // Its stage sends nothing (the registry has no draft), so the verify commands can't see it.
214
+ uploadsAtReveal: true,
215
+ revealsLast: true,
216
+ /** #5165: the server, and each package its `server.json` lists: npm, PyPI, Cargo, NuGet, and OCI images. */
217
+ async names(ctx) {
218
+ const raw = JSON.parse(readFileSync(memberFile(ctx.cwd, path), "utf-8"));
219
+ const needs = new Set();
220
+ for (const p of Array.isArray(raw.packages) ? raw.packages : []) {
221
+ if (typeof p?.identifier !== "string" || !p.identifier)
222
+ continue;
223
+ if (p.registryType === "npm")
224
+ needs.add(trainName("npm", p.identifier));
225
+ else if (p.registryType === "pypi")
226
+ needs.add(trainName("pypi", p.identifier));
227
+ else if (p.registryType === "oci")
228
+ needs.add(trainName("oci", p.identifier));
229
+ else if (p.registryType === "cargo")
230
+ needs.add(trainName("cargo", p.identifier));
231
+ else if (p.registryType === "nuget")
232
+ needs.add(`nuget:${p.identifier.toLowerCase()}`);
233
+ }
234
+ return { provides: typeof raw.name === "string" ? [trainName("mcp", raw.name)] : [], needs: [...needs] };
235
+ },
236
+ /** #5165: whether the registry holds the release's version of the server `server.json` names. */
237
+ async published(ctx) {
238
+ const raw = JSON.parse(readFileSync(memberFile(ctx.cwd, path), "utf-8"));
239
+ const version = releaseVersion(ctx.label);
240
+ if (typeof raw.name !== "string" || !version)
241
+ return null;
242
+ return (await served(ctx, { name: raw.name, version, packages: [] })) !== null;
243
+ },
244
+ /** #5165: wait until the registry serves the version the reveal published. */
245
+ async visible(ctx, published) {
246
+ const ids = published.items.map((i) => /^(.+)@([^@]+)$/.exec(i.name)).filter((m) => m !== null);
247
+ if (ids.length === 0)
248
+ return;
249
+ await waitUntilServed(ctx, deps, {
250
+ what: "the MCP Registry",
251
+ code: "publish-mcp-registry-not-served",
252
+ check: async () => {
253
+ const missing = [];
254
+ for (const m of ids)
255
+ if ((await served(ctx, { name: m[1], version: m[2], packages: [] })) === null)
256
+ missing.push(m[0]);
257
+ return missing;
258
+ },
259
+ });
260
+ },
261
+ async plan(ctx) {
262
+ return [setup(ctx).item];
263
+ },
264
+ async stage(ctx) {
265
+ const { server, token, item } = setup(ctx);
266
+ if (token)
267
+ ctx.log(`using the token from ${token.from}`);
268
+ await registryToken(ctx, token);
269
+ ctx.log(`the MCP Registry at ${registry} takes the credentials for ${server.name}; the reveal asks for a new token, since one lasts minutes`);
270
+ const held = await served(ctx, server);
271
+ if (held === null) {
272
+ ctx.log(`${item.name} is not on the MCP Registry yet; it is published at the reveal, after the targets that publish its packages`);
273
+ return { target: target.name, destination: target.destination, items: [item], state: {} };
274
+ }
275
+ const mine = server.packages.map(packageKey).sort();
276
+ if (held.join("\n") !== mine.join("\n")) {
277
+ throw new PublishTargetError("publish-mcp-registry-version-exists", `the MCP Registry already has ${item.name} with other packages than ${path} names`, "A registry version can't be replaced: cut a release with a new version.");
278
+ }
279
+ ctx.log(`${item.name} is already on the MCP Registry with the same packages`);
280
+ return { target: target.name, destination: target.destination, items: [{ ...item, present: true }], state: { present: "true" } };
281
+ },
282
+ async reveal(ctx, staged) {
283
+ const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
284
+ if (staged.state.present === "true")
285
+ return { target: target.name, destination: target.destination, items: items.map((i) => ({ ...i, present: true })) };
286
+ const { bytes, server, token, item } = setup(ctx);
287
+ // After an upload whose record was lost the version is there already: check it rather than send it twice.
288
+ if ((await served(ctx, server)) !== null) {
289
+ ctx.log(`${item.name} is already on the MCP Registry`);
290
+ return { target: target.name, destination: target.destination, items: items.map((i) => ({ ...i, present: true })) };
291
+ }
292
+ const bearer = await registryToken(ctx, token);
293
+ ctx.log(`publishing ${item.name} to the MCP Registry`);
294
+ const res = await call(`${registry}/v0.1/publish`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${bearer}` }, body: bytes.toString("utf-8") });
295
+ if (res.status < 200 || res.status > 299) {
296
+ throw new PublishTargetError("publish-mcp-registry-failed", `publishing ${item.name} to the MCP Registry: ${why(ctx, res)}`, res.status === 401 || res.status === 403 ? `The token does not cover the namespace of ${server.name}. With GitHub OIDC the name must be io.github.<owner>/<name> for the repository's owner.` : undefined);
297
+ }
298
+ if ((await served(ctx, server)) === null) {
299
+ throw new PublishTargetError("publish-mcp-registry-not-served", `the MCP Registry accepted ${item.name} and does not serve it`);
300
+ }
301
+ return { target: target.name, destination: target.destination, items };
302
+ },
303
+ };
304
+ return target;
305
+ }
@@ -52,7 +52,7 @@
52
52
  * environment, and everything it prints is redacted before chant prints it.
53
53
  */
54
54
  import type { NpmPublishDeclaration } from "./publish-declaration.js";
55
- import { type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
55
+ import { PublishTargetError, type PublishContext, type PublishDeps, type PublishTarget } from "./release-publish.js";
56
56
  export interface NpmPackage {
57
57
  path: string;
58
58
  abs: string;
@@ -106,4 +106,30 @@ export declare function checkDeclaredPackageImages(decls: ReadonlyArray<{
106
106
  type: string;
107
107
  packages?: readonly string[];
108
108
  }>, release: PublishContext["release"], cwd: string, bin?: string, env?: NodeJS.ProcessEnv): void;
109
+ /** Whether the registry has ever published the package. Throws a {@link PublishTargetError} when it can't say. */
110
+ export type NpmPublishedLookup = (name: string, registry: string | undefined) => boolean;
111
+ /** The default {@link NpmPublishedLookup}: `npm view <name> version`, with the registry the target declares. A 404 is "never published"; any other failure is the registry's error. */
112
+ export declare function npmPublishedLookup(bin?: string, env?: NodeJS.ProcessEnv): NpmPublishedLookup;
113
+ /** The packages the npm targets of `decls` publish, by name, with the registry each target declares. Directories without a readable, non-private package.json are left for the publish's plan to refuse. */
114
+ export declare function declaredNpmPackages(decls: ReadonlyArray<{
115
+ type: string;
116
+ packages?: readonly string[];
117
+ registry?: string;
118
+ }>, cwd: string): Array<{
119
+ name: string;
120
+ registry: string | undefined;
121
+ }>;
122
+ /** The refusal for packages the registry has never had: npm trusted publishing can't create a package. */
123
+ export declare function neverPublishedError(names: readonly string[]): PublishTargetError;
124
+ /**
125
+ * Refuses a cut whose npm targets name a package the registry has never
126
+ * published (#5230). Run by the cut before anything is recorded or tagged, and
127
+ * by the train cut before its first member. A registry that can't answer is a
128
+ * refusal too (`publish-npm-registry-unreadable`), not a pass.
129
+ */
130
+ export declare function checkPackagesPublished(decls: ReadonlyArray<{
131
+ type: string;
132
+ packages?: readonly string[];
133
+ registry?: string;
134
+ }>, cwd: string, lookup?: NpmPublishedLookup): void;
109
135
  export declare function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget;
@@ -51,14 +51,16 @@
51
51
  * registry refuses the attestation on the token path. npm runs with the run's
52
52
  * environment, and everything it prints is redacted before chant prints it.
53
53
  */
54
- import { execFileSync, spawn } from "node:child_process";
54
+ import { execFileSync, spawn, spawnSync } from "node:child_process";
55
55
  import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
56
56
  import { tmpdir } from "node:os";
57
57
  import { join, relative, resolve, sep } from "node:path";
58
58
  import { packageSbom } from "./publish-attachments.js";
59
59
  import { checkReleaseDigest, fileDigest, isDir, memberFile, publishTargetKey } from "./publish-targets.js";
60
+ import { trainName } from "./publish-train-names.js";
60
61
  import { readPins, unknownPins } from "./release-images.js";
61
- import { NPM_STAGE_TAG, PublishTargetError } from "./release-publish.js";
62
+ import { NPM_STAGE_TAG, PublishTargetError, statusMessage } from "./release-publish.js";
63
+ import { prereleaseOf } from "./release-prerelease.js";
62
64
  /** npm's output when a publish could not authenticate, as publish-packages.sh matches it. */
63
65
  const NPM_AUTH_FAILED = /ENEEDAUTH|E401|need auth/;
64
66
  /** Read a package's name and version, from its directory or its packed `.tgz`, and find the SBOM it carries. */
@@ -101,6 +103,24 @@ function readPackage(ctx, path, sbom) {
101
103
  const carried = packageSbom(abs, directory, path, pkg.name, sbom, ctx.requireSbom === true);
102
104
  return { path, abs, name: pkg.name, version: pkg.version, ...(digest ? { digest } : {}), ...(carried ? { sbom: carried.file } : {}) };
103
105
  }
106
+ /** A package's package.json, from its directory or its packed `.tgz`, or null when it can't be read. Checks no digest (#5136). */
107
+ function packageManifest(abs) {
108
+ try {
109
+ const text = isDir(abs)
110
+ ? readFileSync(join(abs, "package.json"), "utf-8")
111
+ : execFileSync("tar", ["-xzOf", abs, "package/package.json"], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
112
+ const pkg = JSON.parse(text);
113
+ return pkg !== null && typeof pkg === "object" ? pkg : null;
114
+ }
115
+ catch {
116
+ return null;
117
+ }
118
+ }
119
+ /** `<name>@<version>` split at its last `@`, so a scoped name keeps its own. */
120
+ function splitSpec(spec) {
121
+ const at = spec.lastIndexOf("@");
122
+ return at > 0 ? [spec.slice(0, at), spec.slice(at + 1)] : [spec, ""];
123
+ }
104
124
  /** The arguments of one `npm publish`, which stages under `tag`. */
105
125
  export function npmPublishArgs(decl, abs, ctx, tag = NPM_STAGE_TAG) {
106
126
  return [
@@ -245,13 +265,63 @@ export function checkDeclaredPackageImages(decls, release, cwd, bin = "npm", env
245
265
  checkPackageImages(release, cwd, pkgs, bin, env);
246
266
  }
247
267
  }
268
+ /** The default {@link NpmPublishedLookup}: `npm view <name> version`, with the registry the target declares. A 404 is "never published"; any other failure is the registry's error. */
269
+ export function npmPublishedLookup(bin = "npm", env = process.env) {
270
+ return (name, registry) => {
271
+ const r = spawnSync(bin, ["view", name, "version", ...(registry ? ["--registry", registry] : [])], { encoding: "utf-8", env });
272
+ if (r.status === 0)
273
+ return true;
274
+ const out = `${r.stdout ?? ""}\n${r.stderr ?? ""}`;
275
+ if (/\bE404\b|\b404 Not Found\b/.test(out))
276
+ return false;
277
+ throw new PublishTargetError("publish-npm-registry-unreadable", `npm view ${name} exited ${r.status ?? "without a status"}, so whether ${name} has ever been published is unknown: ${(r.error?.message ?? out).trim().split("\n").filter(Boolean).at(-1) ?? "no output"}`, "Check that npm can reach the registry, and cut again.");
278
+ };
279
+ }
280
+ /** The packages the npm targets of `decls` publish, by name, with the registry each target declares. Directories without a readable, non-private package.json are left for the publish's plan to refuse. */
281
+ export function declaredNpmPackages(decls, cwd) {
282
+ const out = new Map();
283
+ for (const decl of decls) {
284
+ if (decl.type !== "npm")
285
+ continue;
286
+ for (const path of decl.packages ?? []) {
287
+ const abs = resolve(cwd, path);
288
+ if (!existsSync(abs) || !isDir(abs))
289
+ continue;
290
+ try {
291
+ const pkg = JSON.parse(readFileSync(join(abs, "package.json"), "utf-8"));
292
+ if (typeof pkg.name === "string" && pkg.private !== true && !out.has(`${decl.registry ?? ""}\n${pkg.name}`))
293
+ out.set(`${decl.registry ?? ""}\n${pkg.name}`, { name: pkg.name, registry: decl.registry });
294
+ }
295
+ catch {
296
+ // Not a package the plan can read.
297
+ }
298
+ }
299
+ }
300
+ return [...out.values()];
301
+ }
302
+ /** The refusal for packages the registry has never had: npm trusted publishing can't create a package. */
303
+ export function neverPublishedError(names) {
304
+ const list = names.join(", ");
305
+ return new PublishTargetError("publish-npm-never-published", `${list} ${names.length === 1 ? "has" : "have"} never been published to npm, and trusted publishing can't create a package, so its first publish would fail partway through the release`, `Publish one placeholder version of ${list} by hand (npm login, then npm publish), then add the trusted publisher on npmjs.com under the package's Settings, and cut again.`);
306
+ }
307
+ /**
308
+ * Refuses a cut whose npm targets name a package the registry has never
309
+ * published (#5230). Run by the cut before anything is recorded or tagged, and
310
+ * by the train cut before its first member. A registry that can't answer is a
311
+ * refusal too (`publish-npm-registry-unreadable`), not a pass.
312
+ */
313
+ export function checkPackagesPublished(decls, cwd, lookup = npmPublishedLookup()) {
314
+ const missing = declaredNpmPackages(decls, cwd).filter((p) => !lookup(p.name, p.registry)).map((p) => p.name);
315
+ if (missing.length > 0)
316
+ throw neverPublishedError(missing);
317
+ }
248
318
  export function npmTarget(decl, deps) {
249
319
  const bin = deps.npm ?? "npm";
250
320
  const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
251
321
  const now = deps.now ?? Date.now;
252
322
  const registry = decl.registry ?? "the registry npm's config names";
253
323
  const shown = (tag) => `${registry}, dist-tag ${tag}`;
254
- const revealTag = (ctx) => ctx.tag ?? "latest";
324
+ const revealTag = (ctx) => ctx.tag ?? prereleaseOf(ctx.label)?.distTag ?? "latest";
255
325
  // Under `stage: false` a package goes straight to the reveal tag, and the reveal moves no tag (#4040).
256
326
  const staging = decl.stage !== false;
257
327
  const stageTag = (ctx) => (staging ? NPM_STAGE_TAG : revealTag(ctx));
@@ -392,8 +462,151 @@ export function npmTarget(decl, deps) {
392
462
  rmSync(dir, { recursive: true, force: true });
393
463
  }
394
464
  };
465
+ /** Whether `dist-tags.<tag>` of `name` is `version` yet; a 404 is not yet, any other failure is the registry's error. */
466
+ const tagged = async (ctx, name, version, tag) => {
467
+ const r = await npm(ctx, ["view", name, `dist-tags.${tag}`, ...(decl.registry ? ["--registry", decl.registry] : [])]);
468
+ if (r.code === 0)
469
+ return r.output.some((l) => l.trim() === version || l.trim() === JSON.stringify(version));
470
+ if (r.output.some((l) => NPM_VIEW_NOT_YET.test(l)))
471
+ return false;
472
+ const said = r.output.filter((l) => /^npm (error|ERR!)/.test(l)).at(-1) ?? r.output.at(-1) ?? "npm printed nothing";
473
+ throw new PublishTargetError("publish-npm-registry-failed", `npm view ${name} dist-tags.${tag} exited ${r.code} while the train waited for ${name}@${version} to be ${tag}: ${said}`, "Each package was published. Once the registry answers, run the publish again: it publishes nothing twice.");
474
+ };
395
475
  return {
396
476
  kind: "npm",
477
+ stagesVisibly: !staging,
478
+ async names(ctx) {
479
+ const provides = [];
480
+ const needs = new Set();
481
+ for (const path of decl.packages) {
482
+ const pkg = packageManifest(memberFile(ctx.cwd, path));
483
+ if (!pkg)
484
+ continue;
485
+ if (typeof pkg.name === "string")
486
+ provides.push(trainName("npm", pkg.name));
487
+ for (const field of ["dependencies", "peerDependencies", "optionalDependencies"]) {
488
+ const deps = pkg[field];
489
+ if (deps && typeof deps === "object")
490
+ for (const n of Object.keys(deps))
491
+ needs.add(trainName("npm", n));
492
+ }
493
+ }
494
+ return { provides, needs: [...needs].filter((n) => !provides.includes(n)) };
495
+ },
496
+ async published(ctx) {
497
+ for (const path of decl.packages) {
498
+ const pkg = packageManifest(memberFile(ctx.cwd, path));
499
+ if (!pkg || typeof pkg.name !== "string")
500
+ return null;
501
+ const version = ctx.label ?? (typeof pkg.version === "string" ? pkg.version : null);
502
+ if (version === null)
503
+ return null;
504
+ if (!(await onRegistry(ctx, { path, abs: "", name: pkg.name, version })))
505
+ return false;
506
+ }
507
+ return true;
508
+ },
509
+ async visible(ctx, published) {
510
+ const tag = revealTag(ctx);
511
+ const cap = decl.registryWait === undefined ? undefined : decl.registryWait * 1000;
512
+ const start = now();
513
+ let logged;
514
+ let missing = published.items.filter((i) => !i.refused && i.attachment === undefined).map((i) => splitSpec(i.name));
515
+ for (;;) {
516
+ const still = [];
517
+ for (const [name, version] of missing)
518
+ if (!(await tagged(ctx, name, version, tag)))
519
+ still.push([name, version]);
520
+ missing = still;
521
+ if (missing.length === 0)
522
+ return;
523
+ const names = missing.map(([n, v]) => `${n}@${v}`).join(", ");
524
+ const waited = now() - start;
525
+ if (cap !== undefined && waited >= cap) {
526
+ throw new PublishTargetError("publish-npm-not-served", `the registry did not resolve ${tag} to ${names} within ${Math.round(cap / 1000)}s, so the packages that depend on them were not published`, "Once npm serves them, run the publish again: it publishes nothing twice and goes on from there. `registryWait` sets the wait.");
527
+ }
528
+ if (logged === undefined || now() - logged >= NPM_REGISTRY_PROGRESS_MS) {
529
+ ctx.log(`waiting for ${tag} to resolve to ${names}${waited > 0 ? ` (${Math.round(waited / 1000)}s so far)` : ""}`);
530
+ logged = now();
531
+ }
532
+ await sleep(NPM_REGISTRY_POLL_MS);
533
+ }
534
+ },
535
+ /**
536
+ * #5163: deprecate marks each version with `npm deprecate`; yank does
537
+ * that and moves the dist-tag off it to the head release's version;
538
+ * restore clears the message and moves the tag back when this release is
539
+ * the head. npm never unpublishes here: its policy allows that only for
540
+ * 72 hours and with no dependents, and a name and version can never be
541
+ * published again after it.
542
+ */
543
+ async setStatus(ctx) {
544
+ const reg = decl.registry ? ["--registry", decl.registry] : [];
545
+ // The tag the publish moved: the channel, else a prerelease's dist-tag (#5166), else latest.
546
+ const tag = revealTag(ctx);
547
+ const pkgs = ctx.revealed.filter((i) => i.attachment === undefined && !i.refused).map((i) => splitSpec(i.name));
548
+ const actions = [];
549
+ const fail = (what, r, fix) => {
550
+ throw new PublishTargetError("release-status-npm-failed", `${what} exited ${r.code}: ${r.output.filter((l) => /^npm (error|ERR!)/.test(l)).at(-1) ?? r.output.at(-1) ?? "npm printed nothing"}`, fix);
551
+ };
552
+ const message = ctx.status === "active" ? "" : statusMessage(ctx);
553
+ for (const [name, version] of pkgs) {
554
+ const what = ctx.status === "active" ? `npm deprecate ${name}@${version} "" (clears the deprecation)` : `npm deprecate ${name}@${version} "${message}"`;
555
+ if (ctx.apply) {
556
+ const r = await npm(ctx, ["deprecate", `${name}@${version}`, message, ...reg]);
557
+ for (const line of r.output)
558
+ ctx.log(` ${line}`);
559
+ if (r.code !== 0)
560
+ fail(`npm deprecate ${name}@${version}`, r, "Deprecating needs npm credentials that may publish the package.");
561
+ }
562
+ actions.push({ what });
563
+ }
564
+ if (ctx.status === "yanked" && pkgs.length > 0) {
565
+ // npm's unpublish rules: within 72 hours and with no dependents, and the version can never be published again.
566
+ actions.push({ what: `not unpublished: ${pkgs.map(([n, v]) => `${n}@${v}`).join(", ")} stay on the registry, deprecated, since npm allows an unpublish only within 72 hours and with no dependents` });
567
+ }
568
+ if (ctx.status === "deprecated")
569
+ return actions;
570
+ // The dist-tag: off this release on a yank, back onto it on a restore when it is the head.
571
+ const headPkgs = new Map((ctx.head?.items ?? []).filter((i) => i.attachment === undefined && !i.refused).map((i) => splitSpec(i.name)));
572
+ const toHead = ctx.head !== null && ctx.head.releaseDigest !== ctx.release.releaseDigest;
573
+ if (ctx.status === "active" && !(ctx.head && ctx.head.releaseDigest === ctx.release.releaseDigest))
574
+ return actions;
575
+ for (const [name, version] of pkgs) {
576
+ const target = ctx.status === "active" ? version : headPkgs.get(name);
577
+ if (target === undefined) {
578
+ actions.push({
579
+ what: `${tag} of ${name} stays where it is`,
580
+ refused: {
581
+ code: "release-status-no-previous",
582
+ message: `no earlier active release published ${name} under ${tag}, and npm keeps ${tag} on some version, so it can't move off ${version}`,
583
+ fix: toHead ? undefined : "Cut and publish a release to move it to, or restore an earlier one.",
584
+ },
585
+ });
586
+ continue;
587
+ }
588
+ const what = ctx.status === "active" ? `npm dist-tag add ${name}@${version} ${tag}` : `npm dist-tag add ${name}@${target} ${tag}, if ${tag} is ${version}`;
589
+ if (!ctx.apply) {
590
+ actions.push({ what });
591
+ continue;
592
+ }
593
+ const view = await npm(ctx, ["view", name, `dist-tags.${tag}`, ...reg]);
594
+ if (view.code !== 0)
595
+ fail(`npm view ${name} dist-tags.${tag}`, view);
596
+ const now = view.output.map((l) => l.trim().replace(/^"|"$/g, "")).find((l) => l.length > 0 && !/^npm\s/.test(l)) ?? "";
597
+ if (now === target || (ctx.status === "yanked" && now !== version)) {
598
+ actions.push({ what: `${tag} of ${name} is ${now || "unset"}; not moved`, already: true });
599
+ continue;
600
+ }
601
+ const r = await npm(ctx, ["dist-tag", "add", `${name}@${target}`, tag, ...reg]);
602
+ for (const line of r.output)
603
+ ctx.log(` ${line}`);
604
+ if (r.code !== 0)
605
+ fail(`npm dist-tag add ${name}@${target} ${tag}`, r, `Moving a dist-tag needs npm credentials that may change dist-tags; over OIDC that is "Allow npm dist-tag" on the package's trusted-publisher record.`);
606
+ actions.push({ what: `npm dist-tag add ${name}@${target} ${tag}` });
607
+ }
608
+ return actions;
609
+ },
397
610
  name: `npm (${decl.packages.length} package${decl.packages.length === 1 ? "" : "s"})`,
398
611
  destination: `npm ${registry}`,
399
612
  credentialEnv: [],