@@ -3,7 +3,8 @@ const { log } = require('proc-log')
3
3
const pacote = require ( 'pacote' )
4
4
const { read } = require ( 'read' )
5
5
const 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
7
8
8
9
const resetdeps = ( ) => npm ( 'run' , 'resetdeps' )
9
10
@@ -49,22 +50,40 @@ const versionNotExists = async ({ name, version }) => {
49
50
const getPublishes = async ( { force } ) => {
50
51
const publishPackages = [ ]
51
52
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
+
53
61
if ( force || await versionNotExists ( pkg ) ) {
54
62
publishPackages . push ( {
55
- workspace : true ,
63
+ workspace : `--workspace= ${ pkg . name } ` ,
56
64
name : pkg . name ,
57
65
version : pkg . version ,
66
+ dependencies : pkg . dependencies ,
67
+ devDependencies : pkg . devDependencies ,
58
68
tag : await getWorkspaceTag ( pkg ) ,
69
+ updatePkg,
59
70
} )
60
71
}
61
72
}
62
73
63
74
if ( force || await versionNotExists ( cli ) ) {
64
75
publishPackages . push ( {
76
+ workspace : '' ,
65
77
name : cli . name ,
66
78
version : cli . version ,
67
79
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
+ } ,
68
87
} )
69
88
}
70
89
@@ -128,6 +147,36 @@ const main = async (opts) => {
128
147
}
129
148
130
149
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
+
131
180
for ( const publish of publishes ) {
132
181
log . info ( `Publishing ${ publish . name } @${ publish . version } to ${ publish . tag } ${ count ++ } /${ publishes . length } ` )
133
182
const workspace = publish . workspace && `--workspace=${ publish . name } `
@@ -142,8 +191,6 @@ const main = async (opts) => {
142
191
}
143
192
144
193
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' )
147
194
await publishPkg ( '--dry-run' , '--ignore-scripts' )
148
195
} else {
149
196
await publishPkg (
0 commit comments