Skip to content

Commit 9c26d69

Browse files
fix(ci): use temporary version in verify.js to avoid publish collision [EXT-7068]
1 parent 46520d1 commit 9c26d69

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

scripts/verify.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
11
const spawn = require('cross-spawn')
2+
const fs = require('fs')
23
const {
34
isCanary,
45
getVersion,
56
restorePackageJson,
67
setPackageName,
78
PACKAGES,
89
MODULE_MAIN_PATH,
10+
PACKAGE_JSON_PATH,
911
getTag,
1012
} = require('./shared')
1113

14+
/**
15+
* Generate a unique version for dry-run verification.
16+
*
17+
* This is needed because `npm publish --dry-run` will fail if the current
18+
* version already exists on npm. Since this script runs during semantic-release's
19+
* `verifyConditions` step (BEFORE the next version is determined), we need to
20+
* use a temporary version that definitely doesn't exist on npm.
21+
*/
22+
function setDryRunVersion() {
23+
const packageJson = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'))
24+
const timestamp = Date.now()
25+
// Use a version that will never conflict: 0.0.0-verify.{timestamp}
26+
packageJson.version = `0.0.0-verify.${timestamp}`
27+
fs.writeFileSync(PACKAGE_JSON_PATH, JSON.stringify(packageJson, null, 2))
28+
return packageJson.version
29+
}
30+
1231
try {
1332
for (const package of PACKAGES) {
1433
console.log('')
1534
console.log(`📦 Deploying package: ${package} (dry run)`)
1635

17-
const version = getVersion()
18-
const tag = getTag(isCanary(version))
36+
const originalVersion = getVersion()
37+
const tag = getTag(isCanary(originalVersion))
1938

2039
console.log(` > 📝 Updating package name...`)
2140
setPackageName(package)
2241

42+
// Set a temporary version for dry-run to avoid "version already exists" errors
43+
const dryRunVersion = setDryRunVersion()
44+
console.log(` > 🔄 Using temporary version ${dryRunVersion} for dry-run verification`)
45+
2346
console.log(` > 📚 Publishing ${package} on the registry... (dry run)`)
2447
const { status } = spawn.sync(
2548
'npm',

0 commit comments

Comments
 (0)