Skip to content

Commit 122de86

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

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

scripts/verify.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
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+
* Note: This function reads the current package.json (which should have the
23+
* package name already set by setPackageName()) and only modifies the version.
24+
*/
25+
function setDryRunVersion() {
26+
try {
27+
const packageJson = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'))
28+
const timestamp = Date.now()
29+
// Use a version that will never conflict: 0.0.0-verify.{timestamp}
30+
// Preserve all other fields (including name set by setPackageName)
31+
packageJson.version = `0.0.0-verify.${timestamp}`
32+
// Add trailing newline to match file formatting conventions
33+
fs.writeFileSync(PACKAGE_JSON_PATH, JSON.stringify(packageJson, null, 2) + '\n')
34+
return packageJson.version
35+
} catch (err) {
36+
console.error(`❌ Failed to set dry-run version in ${PACKAGE_JSON_PATH}:`, err.message)
37+
throw err
38+
}
39+
}
40+
1241
try {
1342
for (const package of PACKAGES) {
1443
console.log('')
1544
console.log(`📦 Deploying package: ${package} (dry run)`)
1645

17-
const version = getVersion()
18-
const tag = getTag(isCanary(version))
46+
const originalVersion = getVersion()
47+
const tag = getTag(isCanary(originalVersion))
1948

2049
console.log(` > 📝 Updating package name...`)
2150
setPackageName(package)
2251

52+
// Set a temporary version for dry-run to avoid "version already exists" errors
53+
const dryRunVersion = setDryRunVersion()
54+
console.log(` > 🔄 Using temporary version ${dryRunVersion} for dry-run verification`)
55+
2356
console.log(` > 📚 Publishing ${package} on the registry... (dry run)`)
2457
const { status } = spawn.sync(
2558
'npm',

0 commit comments

Comments
 (0)