@@ -46,6 +46,15 @@ async function getUpdatePackages(
4646 return updatePackages ;
4747}
4848
49+ async function getYarnVersion ( context : Context ) : Promise < string > {
50+ const { stdout : output } = await context . sys . exec ( "yarn" , [ "--version" ] , { cwd : context . cwd } ) ;
51+ const version = output . trim ( ) ;
52+ if ( ! semver . valid ( version ) ) {
53+ context . cli . fatal ( `Invalid yarn version "${ version } "` ) ;
54+ }
55+ return version ;
56+ }
57+
4958class PackagePlugin implements Plugin {
5059 public readonly id = "package" ;
5160 public readonly stages = [ DefaultStages . check , DefaultStages . edit , DefaultStages . commit ] ;
@@ -100,6 +109,8 @@ class PackagePlugin implements Plugin {
100109 // we need some yarn plugins to be able to handle this
101110 const yarnRcPath = path . join ( context . cwd , ".yarnrc.yml" ) ;
102111 if ( await fs . pathExists ( yarnRcPath ) ) {
112+ const yarnVersion = await getYarnVersion ( context ) ;
113+
103114 const yarnRc = await fs . readFile ( yarnRcPath , "utf8" ) ;
104115 const yarnPlugins = yarnRc
105116 . split ( "\n" )
@@ -114,11 +125,16 @@ class PackagePlugin implements Plugin {
114125 ) ;
115126 // A list of required plugins and how to import them
116127 const requiredPlugins : Record < string , string > = {
117- "workspace-tools" : "workspace-tools" ,
118- version : "version" ,
119128 changed :
120129 "https://github.com/Dcard/yarn-plugins/releases/latest/download/plugin-changed.js" ,
121130 } ;
131+ if ( semver . lt ( yarnVersion , "4.0.0" ) ) {
132+ // Yarn v4 includes these plugins by default
133+ Object . assign ( requiredPlugins , {
134+ "workspace-tools" : "workspace-tools" ,
135+ version : "version" ,
136+ } ) ;
137+ }
122138 const missingPlugins = Object . keys ( requiredPlugins ) . filter (
123139 ( plugin ) => ! yarnPlugins . includes ( plugin ) ,
124140 ) ;
@@ -137,6 +153,7 @@ Alternatively, you can use ${context.cli.colors.blue("lerna")} to manage the mon
137153
138154 // All good, remember that we use yarn to manage the monorepo
139155 context . setData ( "monorepo" , "yarn" ) ;
156+ context . setData ( "yarn_version" , yarnVersion ) ;
140157
141158 // One last check: make sure there is anything to publish
142159 // We cannot use getEffectivePublishAllFlag here without introducing a circular dependency
@@ -280,11 +297,20 @@ Alternatively, you can use ${context.cli.colors.blue("lerna")} to manage the mon
280297 await deleteStableVersions ( ) ;
281298 const commands = [
282299 publishAll
283- ? [ "yarn" , "workspaces" , "foreach" , "version" , newVersion , "--deferred" ]
300+ ? [
301+ "yarn" ,
302+ "workspaces" ,
303+ "foreach" ,
304+ "--all" ,
305+ "version" ,
306+ newVersion ,
307+ "--deferred" ,
308+ ]
284309 : [
285310 "yarn" ,
286311 "changed" ,
287312 "foreach" ,
313+ "--all" ,
288314 `--git-range=v${ pack . version } ` ,
289315 "version" ,
290316 newVersion ,
0 commit comments