|
1 | 1 | import { spawnSync } from "node:child_process"; |
2 | | -import { existsSync, readdirSync, readFileSync } from "node:fs"; |
| 2 | +import { appendFileSync, existsSync, readdirSync, readFileSync } from "node:fs"; |
3 | 3 | import { dirname, join, resolve } from "node:path"; |
4 | 4 |
|
5 | 5 | import { assertFixedGroup, assertFixedVersions } from "./publish-state.mjs"; |
6 | 6 |
|
7 | 7 | const expectedRef = "refs/heads/main"; |
| 8 | +const registryPropagationAttempts = 60; |
| 9 | +const registryPropagationDelayMs = 5_000; |
8 | 10 |
|
9 | 11 | if ( |
10 | 12 | process.env.GITHUB_ACTIONS !== "true" || |
@@ -90,10 +92,14 @@ for (const entry of sortForPublishing(workspacePackages)) { |
90 | 92 | const state = await registryVersionState(name, version); |
91 | 93 | if (state === "available") { |
92 | 94 | console.log(`Already published: ${name}@${version}`); |
| 95 | + recordPublishedVersion(name, version); |
93 | 96 | continue; |
94 | 97 | } |
95 | 98 | if (state === "incomplete") { |
96 | | - throw new Error(`${name}@${version} exists in npm metadata but its tarball is unavailable`); |
| 99 | + console.log(`Waiting for npm to finish publishing: ${name}@${version}`); |
| 100 | + await waitForAvailableVersion(name, version); |
| 101 | + recordPublishedVersion(name, version); |
| 102 | + continue; |
97 | 103 | } |
98 | 104 |
|
99 | 105 | console.log(`Publishing: ${name}@${version}`); |
@@ -130,6 +136,7 @@ for (const entry of sortForPublishing(workspacePackages)) { |
130 | 136 | } |
131 | 137 |
|
132 | 138 | await waitForAvailableVersion(name, version); |
| 139 | + recordPublishedVersion(name, version); |
133 | 140 | } |
134 | 141 |
|
135 | 142 | function sortForPublishing(entries) { |
@@ -175,11 +182,20 @@ async function registryVersionState(name, version) { |
175 | 182 | } |
176 | 183 |
|
177 | 184 | async function waitForAvailableVersion(name, version) { |
178 | | - for (let attempt = 0; attempt < 12; attempt += 1) { |
| 185 | + for (let attempt = 0; attempt < registryPropagationAttempts; attempt += 1) { |
179 | 186 | if ((await registryVersionState(name, version)) === "available") return; |
180 | | - await new Promise((resolveDelay) => setTimeout(resolveDelay, 5_000)); |
| 187 | + await new Promise((resolveDelay) => setTimeout(resolveDelay, registryPropagationDelayMs)); |
181 | 188 | } |
182 | | - throw new Error(`${name}@${version} did not become installable within 60 seconds`); |
| 189 | + throw new Error(`${name}@${version} did not become installable within five minutes`); |
| 190 | +} |
| 191 | + |
| 192 | +function recordPublishedVersion(name, version) { |
| 193 | + const outputPath = process.env.CHANGESETS_OUTPUT; |
| 194 | + if (typeof outputPath !== "string" || outputPath.length === 0) return; |
| 195 | + appendFileSync( |
| 196 | + outputPath, |
| 197 | + `${JSON.stringify({ type: "git-tag", tag: `${name}@${version}`, packageName: name })}\n`, |
| 198 | + ); |
183 | 199 | } |
184 | 200 |
|
185 | 201 | function withoutOtp(environment) { |
|
0 commit comments