88
99import chalk from 'chalk' ;
1010import prompts from 'prompts' ;
11+ import semver from 'semver' ;
1112
1213import { ValidationError } from '../errors' ;
1314import { type ReleaseOptions } from '../release' ;
@@ -18,7 +19,42 @@ import {
1819 getRemoteHeadCommitHash ,
1920 isWorkingTreeClean ,
2021} from '../git_utils' ;
21- import { getAuthenticatedUser , getYarnRegistryServer } from '../yarn_utils' ;
22+ import {
23+ getNpmAuthenticatedUser ,
24+ getNpmRegistryServer ,
25+ getNpmVersion ,
26+ } from '../npm_utils' ;
27+ import { getYarnVersion } from '../yarn_utils' ;
28+
29+ const checkNpmYarnVersions = async ( options : ReleaseOptions ) => {
30+ const { logger } = options ;
31+
32+ let npmVersion , yarnVersion ;
33+ try {
34+ npmVersion = await getNpmVersion ( ) ;
35+ } catch ( err ) {
36+ throw new ValidationError (
37+ 'Unable to check npm version. Ensure `npm` is installed and available in PATH'
38+ ) ;
39+ }
40+
41+ // npm v11.5.1 is required for trusted publishing
42+ if ( semver . lt ( npmVersion , '11.5.1' ) ) {
43+ throw new ValidationError (
44+ 'The version of npm installed on your system is lower than the required version. Please install npm v11.5.1 or newer.'
45+ ) ;
46+ }
47+
48+ try {
49+ yarnVersion = await getYarnVersion ( ) ;
50+ } catch ( err ) {
51+ throw new ValidationError (
52+ 'Unable to check yarn version. Ensure `yarn` is installed and available in PATH'
53+ ) ;
54+ }
55+
56+ logger . info ( `Using npm v${ npmVersion } and yarn v${ yarnVersion } ` ) ;
57+ } ;
2258
2359/**
2460 * Check current git branch, working tree status and more to ensure
@@ -40,7 +76,7 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
4076 if ( ! ( await isWorkingTreeClean ( ) ) ) {
4177 throw new ValidationError (
4278 'Git working tree is dirty. Please clean up your working tree' +
43- ' from any uncommited changes and try again.' ,
79+ ' from any uncommited changes and try again.' ,
4480 `To clean local changes and restore the branch to remote state,` +
4581 ` please run:\n ${ chalk . yellowBright (
4682 `git reset --hard upstream/${ currentBranch } `
@@ -75,14 +111,16 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
75111 ) } ) on branch ${ chalk . underline . bold ( currentBranch ) } `
76112 ) ;
77113
114+ await checkNpmYarnVersions ( options ) ;
115+
78116 if ( ! options . skipAuthCheck ) {
79- const registryUser = await getAuthenticatedUser ( ) ;
117+ const registryUser = await getNpmAuthenticatedUser ( ) ;
80118 if ( ! registryUser ) {
81119 throw new ValidationError (
82120 'Authentication to npmjs is required. Please log in before running' +
83121 ' this command again.' ,
84122 `To authenticate run the following command:\n` +
85- ` ${ chalk . yellowBright ( 'yarn npm login' ) } `
123+ ` ${ chalk . yellowBright ( 'npm login' ) } `
86124 ) ;
87125 }
88126
@@ -91,11 +129,11 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
91129 logger . info ( 'Skipping the registry authentication check' ) ;
92130 }
93131
94- const npmRegistry = await getYarnRegistryServer ( ) ;
95- if ( npmRegistry ) {
132+ const npmRegistry = await getNpmRegistryServer ( ) ;
133+ if ( ! npmRegistry . isOfficial ) {
96134 logger . warning (
97135 chalk . yellow (
98- `A custom npm registry server (${ npmRegistry } ) will be used!`
136+ `A custom npm registry server (${ npmRegistry . url } ) will be used!`
99137 )
100138 ) ;
101139 } else {
0 commit comments