mirror of
https://github.com/pnpm/action-setup.git
synced 2026-09-10 03:03:23 +08:00
fix: use native bootstrap only for pnpm 12
Route pnpm 12-only versions and ranges through the plain pnpm native package while preserving the existing Node and @pnpm/exe bootstrap paths for older releases.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
// Usage: node scripts/update-bootstrap.mjs [version]
|
||||
// Usage: node scripts/update-bootstrap.mjs [legacy-version] [native-version]
|
||||
// Regenerates the bootstrap lockfiles used by action-setup to install pnpm via npm.
|
||||
|
||||
import { execSync } from 'child_process'
|
||||
@@ -10,21 +10,24 @@ import { tmpdir } from 'os'
|
||||
|
||||
const BOOTSTRAP_DIR = new URL('../src/install-pnpm/bootstrap/', import.meta.url).pathname
|
||||
|
||||
const version = process.argv[2] || resolveLatestVersion()
|
||||
const legacyVersion = process.argv[2] || resolveLatestVersion(11)
|
||||
const nativeVersion = process.argv[3] || resolveLatestVersion(12)
|
||||
|
||||
console.log(`Updating bootstrap lockfiles to pnpm@${version} ...`)
|
||||
console.log(`Updating bootstrap lockfiles to pnpm@${legacyVersion} and pnpm@${nativeVersion} ...`)
|
||||
|
||||
generateLock('pnpm-lock.json', { pnpm: version }, 'bootstrap-pnpm')
|
||||
generateLock('pnpm-lock.json', { pnpm: legacyVersion }, 'bootstrap-pnpm')
|
||||
generateLock('exe-lock.json', { '@pnpm/exe': legacyVersion }, 'bootstrap-exe')
|
||||
generateLock('native-lock.json', { pnpm: nativeVersion }, 'bootstrap-native-pnpm')
|
||||
|
||||
console.log('Done!')
|
||||
|
||||
function resolveLatestVersion() {
|
||||
function resolveLatestVersion(major) {
|
||||
const json = execSync('npm view pnpm dist-tags --json', { encoding: 'utf8' })
|
||||
const parsed = JSON.parse(json)
|
||||
const tags = Array.isArray(parsed) ? parsed[0] : parsed
|
||||
const version = tags['next-12'] || tags['latest-12']
|
||||
const version = tags[`next-${major}`] || tags[`latest-${major}`]
|
||||
if (!version) {
|
||||
console.error('Could not determine latest pnpm version from npm dist-tags')
|
||||
console.error(`Could not determine latest pnpm v${major} version from npm dist-tags`)
|
||||
process.exit(1)
|
||||
}
|
||||
return version
|
||||
@@ -39,7 +42,8 @@ function generateLock(filename, dependencies, name) {
|
||||
const parsed = JSON.parse(lock)
|
||||
parsed.name = name
|
||||
writeFileSync(join(BOOTSTRAP_DIR, filename), JSON.stringify(parsed, null, 2) + '\n')
|
||||
console.log(` ${filename} -> ${Object.values(dependencies)[0]}@${version}`)
|
||||
const [packageName, packageVersion] = Object.entries(dependencies)[0]
|
||||
console.log(` ${filename} -> ${packageName}@${packageVersion}`)
|
||||
} finally {
|
||||
rmSync(tmp, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user