@@ -3,7 +3,8 @@ const { log } = require('proc-log')
33const pacote = require ( 'pacote' )
44const { read } = require ( 'read' )
55const Table = require ( 'cli-table3' )
6- const { run, git, npm, pkg : cli , spawn } = require ( './util.js' )
6+ const { run, git, npm, pkgPath : cliPath , pkg : cli , spawn } = require ( './util.js' )
7+ const fs = require ( 'fs' ) . promises
78
89const resetdeps = ( ) => npm ( 'run' , 'resetdeps' )
910
@@ -49,22 +50,40 @@ const versionNotExists = async ({ name, version }) => {
4950const getPublishes = async ( { force } ) => {
5051 const publishPackages = [ ]
5152
52- for ( const { pkg } of await cli . mapWorkspaces ( { public : true } ) ) {
53+ for ( const { pkg, pkgPath } of await cli . mapWorkspaces ( { public : true } ) ) {
54+ const updatePkg = async ( cb ) => {
55+ const data = JSON . parse ( await fs . readFile ( pkgPath , 'utf8' ) )
56+ const result = cb ( data )
57+ await fs . writeFile ( pkgPath , JSON . stringify ( result , null , 2 ) )
58+ return result
59+ }
60+
5361 if ( force || await versionNotExists ( pkg ) ) {
5462 publishPackages . push ( {
55- workspace : true ,
63+ workspace : `--workspace= ${ pkg . name } ` ,
5664 name : pkg . name ,
5765 version : pkg . version ,
66+ dependencies : pkg . dependencies ,
67+ devDependencies : pkg . devDependencies ,
5868 tag : await getWorkspaceTag ( pkg ) ,
69+ updatePkg,
5970 } )
6071 }
6172 }
6273
6374 if ( force || await versionNotExists ( cli ) ) {
6475 publishPackages . push ( {
76+ workspace : '' ,
6577 name : cli . name ,
6678 version : cli . version ,
6779 tag : `next-${ semver . major ( cli . version ) } ` ,
80+ dependencies : cli . dependencies ,
81+ devDependencies : cli . devDependencies ,
82+ updatePkg : async ( cb ) => {
83+ const result = cb ( cli )
84+ await fs . writeFile ( cliPath , JSON . stringify ( result , null , 2 ) )
85+ return result
86+ } ,
6887 } )
6988 }
7089
@@ -128,6 +147,36 @@ const main = async (opts) => {
128147 }
129148
130149 let count = - 1
150+
151+ if ( smokePublish ) {
152+ // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run
153+ // this is the equivlent of running `npm version prerelease`, but ensureing all internally used workflows are bumped
154+ for ( const publish of publishes ) {
155+ const { version } = await publish . updatePkg ( ( pkg ) => ( { ...pkg , version : `${ pkg . version } -smoke.0` } ) )
156+ for ( const ipublish of publishes ) {
157+ if ( ipublish . dependencies ?. [ publish . name ] ) {
158+ await ipublish . updatePkg ( ( pkg ) => ( {
159+ ...pkg ,
160+ dependencies : {
161+ ...pkg . dependencies ,
162+ [ publish . name ] : version ,
163+ } ,
164+ } ) )
165+ }
166+ if ( ipublish . devDependencies ?. [ publish . name ] ) {
167+ await ipublish . updatePkg ( ( pkg ) => ( {
168+ ...pkg ,
169+ devDependencies : {
170+ ...pkg . devDependencies ,
171+ [ publish . name ] : version ,
172+ } ,
173+ } ) )
174+ }
175+ }
176+ }
177+ await npm ( 'install' )
178+ }
179+
131180 for ( const publish of publishes ) {
132181 log . info ( `Publishing ${ publish . name } @${ publish . version } to ${ publish . tag } ${ count ++ } /${ publishes . length } ` )
133182 const workspace = publish . workspace && `--workspace=${ publish . name } `
@@ -142,8 +191,6 @@ const main = async (opts) => {
142191 }
143192
144193 if ( smokePublish ) {
145- // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run
146- await npm ( 'version' , 'prerelease' , workspace , '--preid=smoke' , '--ignore-scripts' , '--no-git-tag-version' )
147194 await publishPkg ( '--dry-run' , '--ignore-scripts' )
148195 } else {
149196 await publishPkg (
0 commit comments