@@ -23,6 +23,7 @@ const projects = config.projects || config;
23
23
const nohoist = ( config . projects && config . nohoist ) || [ ] ;
24
24
25
25
const DOWNSTREAM_PKGS = ( process . env . DOWNSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
26
+ const UPSTREAM_PKGS = ( process . env . UPSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
26
27
27
28
const TEMP = tmp . dirSync ( ) ;
28
29
const TEMP_DIR = TEMP . name ;
@@ -31,16 +32,48 @@ const DOWNSTREAM_CACHE = path.resolve(PKG_DIR, '.downstream_cache');
31
32
32
33
function makeDownstreamCache ( ) {
33
34
if ( ! fs . existsSync ( DOWNSTREAM_CACHE ) ) {
34
- console . log ( 'making .downstream_cache working directory' ) ;
35
+ console . log ( ' ===> making .downstream_cache working directory <=== ' ) ;
35
36
fs . mkdirSync ( DOWNSTREAM_CACHE ) ;
36
37
}
37
38
}
38
39
39
40
function localPublish ( packageDir ) {
40
41
packageDir = packageDir || PKG_DIR ;
41
42
process . chdir ( packageDir ) ;
42
- console . log ( `Building ${ packageDir } and publishing using yalc...` ) ;
43
- util . _exec ( 'yarn build && npx yalc publish' ) ;
43
+ console . log ( ` ===> Building ${ packageDir } and publishing using yalc... <===` ) ;
44
+ util . _exec ( 'yarn build' ) ;
45
+
46
+ // Un-yalc any deps in the package.json (after building, but before yalc publishing)
47
+ const packageString = fs . readFileSync ( 'package.json' ) ;
48
+ const package = JSON . parse ( packageString ) ;
49
+ const { resolutions = { } , dependencies = { } , devDependencies = { } } = package ;
50
+
51
+ const yalcLockfile = fs . existsSync ( 'yalc.lock' ) ? JSON . parse ( fs . readFileSync ( 'yalc.lock' ) ) : { } ;
52
+ const yalcPackages = Object . keys ( yalcLockfile . packages || { } )
53
+
54
+ yalcPackages . forEach ( pkg => {
55
+ delete resolutions [ pkg ]
56
+
57
+ if ( dependencies [ pkg ] ) {
58
+ dependencies [ pkg ] = yalcLockfile . packages [ pkg ] . replaced ;
59
+ }
60
+
61
+ if ( devDependencies [ pkg ] ) {
62
+ devDependencies [ pkg ] = yalcLockfile . packages [ pkg ] . replaced ;
63
+ }
64
+ } ) ;
65
+
66
+ if ( yalcPackages . length ) {
67
+ console . log ( ` ===> De-yalc'ed ${ yalcPackages . join ( ', ' ) } from ${ packageDir } /package.json using ${ packageDir } /yarn.lock <===` )
68
+ fs . writeFileSync ( 'package.json' , JSON . stringify ( package , null , 2 ) ) ;
69
+ }
70
+
71
+ util . _exec ( 'npx yalc publish' ) ;
72
+
73
+ if ( yalcPackages . length ) {
74
+ console . log ( ` ===> Restoring yalc'd manifest ${ packageDir } /package.json <===` )
75
+ fs . writeFileSync ( 'package.json' , packageString ) ;
76
+ }
44
77
}
45
78
46
79
function installUpstreamDeps ( upstreamPackages ) {
@@ -78,7 +111,7 @@ function fetchDownstreamProjects(downstreamConfig, prefix, downstreamTreeNode) {
78
111
Object . keys ( downstreamConfig ) . forEach ( key => {
79
112
const installDir = prefix ? `${ prefix } .${ key } ` : key ;
80
113
81
- console . log ( ` ===> Fetching downstream project to '${ installDir } ' <===` ) ;
114
+ console . log ( ` ===> Fetching downstream project to '${ installDir } ' <===` ) ;
82
115
const installSource = downstreamConfig [ key ] ;
83
116
const isFile = / ^ \. / . exec ( installSource ) ;
84
117
const installSourcePath = prefix ? path . resolve ( DOWNSTREAM_CACHE , prefix , installSource ) : path . resolve ( PKG_DIR , installSource ) ;
@@ -123,31 +156,31 @@ function installWorkspaceDependencies(downstreamInstallDirs) {
123
156
124
157
function runDownstreamTests ( key , upstreamPackages , downstreamTreeNode , successLog ) {
125
158
if ( DOWNSTREAM_PKGS . length && DOWNSTREAM_PKGS . indexOf ( key ) === - 1 ) {
126
- console . log ( `${ key } not in DOWNSTREAM_PKGS, skipping...` ) ;
159
+ console . log ( ` ===> ${ key } not in DOWNSTREAM_PKGS, skipping... <=== ` ) ;
127
160
return ;
128
161
}
129
162
130
163
process . chdir ( TEMP_DOWNSTREAM_CACHE ) ;
131
164
132
165
const name = downstreamTreeNode . installDir ;
133
166
134
- console . log ( ` ===> '${ name } ': prepping tests <===` ) ;
167
+ console . log ( ` ===> '${ name } ': prepping tests <===` ) ;
135
168
process . chdir ( downstreamTreeNode . installDir ) ;
136
169
137
170
if ( ! yargs . argv . workspace ) {
138
- console . log ( ` ===> '${ name } ': Installing dependencies <===` ) ;
171
+ console . log ( ` ===> '${ name } ': Installing dependencies <===` ) ;
139
172
util . _exec ( 'yarn' ) ;
140
173
}
141
174
142
- console . log ( ` ===> '${ name } ': Installing freshly built upstream packages <===` ) ;
175
+ console . log ( ` ===> '${ name } ': Installing freshly built upstream packages <===` ) ;
143
176
installUpstreamDeps ( upstreamPackages ) ;
144
177
145
- console . log ( ` ===> '${ name } ': Running tests <===` ) ;
178
+ console . log ( ` ===> '${ name } ': Running tests <===` ) ;
146
179
runTests ( ) ;
147
180
148
181
successLog . push ( key ) ;
149
182
150
- console . log ( ` ===> '${ name } ': Reverting working copy <===` ) ;
183
+ console . log ( ` ===> '${ name } ': Reverting working copy <===` ) ;
151
184
revertLocalChanges ( downstreamTreeNode . installSource ) ;
152
185
153
186
@@ -164,32 +197,32 @@ function runDownstreamTests(key, upstreamPackages, downstreamTreeNode, successLo
164
197
}
165
198
}
166
199
167
- console . log ( ` ===> Creating .downstream_cache working directory <===` ) ;
200
+ console . log ( ` ===> Creating .downstream_cache working directory <===` ) ;
168
201
makeDownstreamCache ( ) ;
169
202
170
- console . log ( ` ===> Publishing ${ pkgjson . name } to yalc registry <===` ) ;
203
+ console . log ( ` ===> Publishing ${ pkgjson . name } to yalc registry <===` ) ;
171
204
localPublish ( ) ;
172
205
173
- console . log ( ` ===> Fetching downstream projects <===` ) ;
206
+ console . log ( ` ===> Fetching downstream projects <===` ) ;
174
207
const tree = { children : { } } ;
175
208
fetchDownstreamProjects ( projects , "" , tree . children ) ;
176
209
177
210
if ( yargs . argv . workspace ) {
178
- console . log ( ` ===> Installing downstream dependencies <===` ) ;
211
+ console . log ( ` ===> Installing downstream dependencies <===` ) ;
179
212
const downstreamDirs = getDownstreamInstallDirs ( tree ) ;
180
213
installWorkspaceDependencies ( downstreamDirs ) ;
181
214
}
182
215
183
- console . log ( ` ===> Moving working directory to temp dir ${ TEMP_DIR } <===` ) ;
216
+ console . log ( ` ===> Moving working directory to temp dir ${ TEMP_DIR } <===` ) ;
184
217
shelljs . mv ( DOWNSTREAM_CACHE , TEMP_DIR ) ;
185
218
186
219
const successLog = [ ] ;
187
220
nodeCleanup ( ( ) => {
188
221
shelljs . mv ( TEMP_DOWNSTREAM_CACHE , PKG_DIR ) ;
189
- console . log ( " Successfully ran downstream tests for: " + successLog . join ( ', ' ) ) ;
222
+ console . log ( ` ===> Successfully ran downstream tests for: ${ successLog . join ( ', ' ) } <===` ) ;
190
223
} ) ;
191
224
192
- console . log ( ` ===> Running downstream tests <===` ) ;
225
+ console . log ( ` ===> Running downstream tests <===` ) ;
193
226
Object . keys ( tree . children ) . forEach ( key => {
194
227
runDownstreamTests ( key , [ pkgjson . name ] , tree . children [ key ] , successLog ) ;
195
228
} ) ;
0 commit comments