@@ -18,15 +18,15 @@ import * as util from './util.js';
18
18
import * as git from './git-util.js' ;
19
19
import * as npm from './npm/util.js' ;
20
20
21
- const exec = ( cmd , args ) => {
21
+ const exec = ( cmd , args , options ) => {
22
22
// Use `Observable` support if merged https://github.com/sindresorhus/execa/pull/26
23
- const cp = execa ( cmd , args ) ;
23
+ const cp = execa ( cmd , args , options ) ;
24
24
25
25
return merge ( cp . stdout , cp . stderr , cp ) . pipe ( filter ( Boolean ) ) ;
26
26
} ;
27
27
28
28
// eslint-disable-next-line complexity
29
- const np = async ( input = 'patch' , options , { pkg, rootDir} ) => {
29
+ const np = async ( input = 'patch' , options , { pkg, rootDir, isYarnBerry } ) => {
30
30
if ( ! hasYarn ( ) && options . yarn ) {
31
31
throw new Error ( 'Could not use Yarn without yarn.lock file' ) ;
32
32
}
@@ -36,10 +36,22 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
36
36
options . cleanup = false ;
37
37
}
38
38
39
+ function getPackageManagerName ( ) {
40
+ if ( options . yarn === true ) {
41
+ if ( isYarnBerry ) {
42
+ return 'Yarn Berry' ;
43
+ }
44
+
45
+ return 'Yarn' ;
46
+ }
47
+
48
+ return 'npm' ;
49
+ }
50
+
39
51
const runTests = options . tests && ! options . yolo ;
40
52
const runCleanup = options . cleanup && ! options . yolo ;
41
53
const pkgManager = options . yarn === true ? 'yarn' : 'npm' ;
42
- const pkgManagerName = options . yarn === true ? 'Yarn' : 'npm' ;
54
+ const pkgManagerName = getPackageManagerName ( ) ;
43
55
const hasLockFile = fs . existsSync ( path . resolve ( rootDir , options . yarn ? 'yarn.lock' : 'package-lock.json' ) ) || fs . existsSync ( path . resolve ( rootDir , 'npm-shrinkwrap.json' ) ) ;
44
56
const isOnGitHub = options . repoUrl && hostedGitInfo . fromUrl ( options . repoUrl ) ?. type === 'github' ;
45
57
const testScript = options . testScript || 'test' ;
@@ -88,6 +100,13 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
88
100
89
101
const shouldEnable2FA = options [ '2fa' ] && options . availability . isAvailable && ! options . availability . isUnknown && ! pkg . private && ! npm . isExternalRegistry ( pkg ) ;
90
102
103
+ // Yarn berry doesn't support git commiting/tagging, so use npm
104
+ const shouldUseYarnForVersioning = options . yarn === true && ! isYarnBerry ;
105
+ const shouldUseNpmForVersioning = options . yarn === false || isYarnBerry ;
106
+
107
+ // To prevent the process from hanging due to watch mode (e.g. when running `vitest`)
108
+ const ciEnvOptions = { env : { CI : 'true' } } ;
109
+
91
110
const tasks = new Listr ( [
92
111
{
93
112
title : 'Prerequisite check' ,
@@ -105,10 +124,11 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
105
124
task : ( ) => deleteAsync ( 'node_modules' ) ,
106
125
} ,
107
126
{
108
- title : ' Installing dependencies using Yarn' ,
127
+ title : ` Installing dependencies using ${ pkgManagerName } ` ,
109
128
enabled : ( ) => options . yarn === true ,
110
- task : ( ) => (
111
- exec ( 'yarn' , [ 'install' , '--frozen-lockfile' , '--production=false' ] ) . pipe (
129
+ task ( ) {
130
+ const args = isYarnBerry ? [ 'install' , '--immutable' ] : [ 'install' , '--frozen-lockfile' , '--production=false' ] ;
131
+ return exec ( 'yarn' , args ) . pipe (
112
132
catchError ( async error => {
113
133
if ( ( ! error . stderr . startsWith ( 'error Your lockfile needs to be updated' ) ) ) {
114
134
return ;
@@ -120,8 +140,8 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
120
140
121
141
throw new Error ( 'yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again.' ) ;
122
142
} ) ,
123
- )
124
- ) ,
143
+ ) ;
144
+ } ,
125
145
} ,
126
146
{
127
147
title : 'Installing dependencies using npm' ,
@@ -134,14 +154,14 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
134
154
] : [ ] ,
135
155
...runTests ? [
136
156
{
137
- title : ' Running tests using npm' ,
157
+ title : ` Running tests using ${ pkgManagerName } ` ,
138
158
enabled : ( ) => options . yarn === false ,
139
- task : ( ) => exec ( 'npm' , testCommand ) ,
159
+ task : ( ) => exec ( 'npm' , testCommand , ciEnvOptions ) ,
140
160
} ,
141
161
{
142
- title : ' Running tests using Yarn' ,
162
+ title : ` Running tests using ${ pkgManagerName } ` ,
143
163
enabled : ( ) => options . yarn === true ,
144
- task : ( ) => exec ( 'yarn' , testCommand ) . pipe (
164
+ task : ( ) => exec ( 'yarn' , testCommand , ciEnvOptions ) . pipe (
145
165
catchError ( error => {
146
166
if ( error . message . includes ( `Command "${ testScript } " not found` ) ) {
147
167
return [ ] ;
@@ -153,8 +173,8 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
153
173
} ,
154
174
] : [ ] ,
155
175
{
156
- title : ' Bumping version using Yarn' ,
157
- enabled : ( ) => options . yarn === true ,
176
+ title : ` Bumping version using ${ pkgManagerName } ` ,
177
+ enabled : ( ) => shouldUseYarnForVersioning ,
158
178
skip ( ) {
159
179
if ( options . preview ) {
160
180
let previewText = `[Preview] Command not executed: yarn version --new-version ${ input } ` ;
@@ -178,7 +198,7 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
178
198
} ,
179
199
{
180
200
title : 'Bumping version using npm' ,
181
- enabled : ( ) => options . yarn === false ,
201
+ enabled : ( ) => shouldUseNpmForVersioning ,
182
202
skip ( ) {
183
203
if ( options . preview ) {
184
204
let previewText = `[Preview] Command not executed: npm version ${ input } ` ;
@@ -205,14 +225,14 @@ const np = async (input = 'patch', options, {pkg, rootDir}) => {
205
225
title : `Publishing package using ${ pkgManagerName } ` ,
206
226
skip ( ) {
207
227
if ( options . preview ) {
208
- const args = getPackagePublishArguments ( options ) ;
228
+ const args = getPackagePublishArguments ( options , isYarnBerry ) ;
209
229
return `[Preview] Command not executed: ${ pkgManager } ${ args . join ( ' ' ) } .` ;
210
230
}
211
231
} ,
212
232
task ( context , task ) {
213
233
let hasError = false ;
214
234
215
- return publish ( context , pkgManager , task , options )
235
+ return publish ( context , pkgManager , isYarnBerry , task , options )
216
236
. pipe (
217
237
catchError ( async error => {
218
238
hasError = true ;
0 commit comments