-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add script for setting npm
latest
tag on v2 modules
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable no-sync, no-console, import/no-dynamic-require */ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const execa = require('execa') | ||
const semver = require('semver') | ||
|
||
main() | ||
|
||
async function main() { | ||
const pkgsPath = path.join(__dirname, '..', 'packages', '@sanity') | ||
const pkgs = fs | ||
.readdirSync(pkgsPath) | ||
.filter((pkg) => fs.statSync(path.join(pkgsPath, pkg)).isDirectory()) | ||
|
||
for (const pkg of pkgs) { | ||
const pkgName = `@sanity/${pkg}` | ||
const latestVersion = (await execa('npm', ['show', pkgName, 'version'])).stdout.trim() | ||
|
||
// For 3.x modules, we want to keep that as latest | ||
if (!latestVersion.startsWith('2.')) { | ||
continue | ||
} | ||
|
||
// If on 2.x range, check if the in-repo version is newer than what is published as `latest`. | ||
// This happens because we publish blindly with `--tag v2`, but for modules that were removed | ||
// in v3, we actually want the latest 2.x version to be the latest version. | ||
const localVersion = require(path.join(pkgsPath, pkg, 'package.json')).version | ||
if ( | ||
!localVersion || | ||
!localVersion.startsWith('2.') || | ||
semver.gte(latestVersion, localVersion) | ||
) { | ||
console.log('%s is at latest already, skipping', pkgName) | ||
continue | ||
} | ||
|
||
console.log( | ||
'%s is newer locally (%s) than latest (%s) - adjusting `latest` tag', | ||
pkgName, | ||
localVersion, | ||
latestVersion | ||
) | ||
|
||
console.log( | ||
(await execa('npm', ['dist-tag', 'add', `${pkgName}@${localVersion}`, 'latest'])).stdout | ||
) | ||
} | ||
} |