@@ -4,6 +4,12 @@ const path = require('path');
4
4
const tmp = require ( 'tmp' ) ;
5
5
const shelljs = require ( 'shelljs' ) ;
6
6
7
+ const yargs = require ( 'yargs' )
8
+ . option ( 'workspace' , {
9
+ alias : 'ws' ,
10
+ description : 'use yarn workspace to save space' ,
11
+ } ) ;
12
+
7
13
const nodeCleanup = require ( 'node-cleanup' ) ;
8
14
const publishYalcPackage = require ( './publish_yalc_package' ) ;
9
15
@@ -31,8 +37,8 @@ function makeDownstreamCache() {
31
37
function localPublish ( packageDir ) {
32
38
packageDir = packageDir || PKG_DIR ;
33
39
process . chdir ( packageDir ) ;
34
- console . log ( 'Publishing using yalc...' ) ;
35
- util . _exec ( 'yalc publish' ) ;
40
+ console . log ( `Building ${ packageDir } and publishing using yalc...` ) ;
41
+ util . _exec ( 'yarn build && yalc publish' ) ;
36
42
}
37
43
38
44
function installUpstreamDeps ( upstreamPackages ) {
@@ -84,7 +90,7 @@ function getDownstreamInstallDirs(downstreamTreeNode) {
84
90
. filter ( x => ! ! x ) ;
85
91
}
86
92
87
- function installDependencies ( downstreamInstallDirs ) {
93
+ function installWorkspaceDependencies ( downstreamInstallDirs ) {
88
94
const yarnWorkspacePackageJsonPath = path . resolve ( DOWNSTREAM_CACHE , "package.json" ) ;
89
95
const yarnWorkspacePackageJson = {
90
96
private : true ,
@@ -102,20 +108,47 @@ function installDependencies(downstreamInstallDirs) {
102
108
util . _exec ( 'yarn && yarn upgrade' ) ;
103
109
}
104
110
105
- function runDownstreamTests ( key , upstreamPackages , downstreamTreeNode ) {
111
+ function runDownstreamTests ( key , upstreamPackages , downstreamTreeNode , successLog ) {
106
112
if ( DOWNSTREAM_PKGS . length && DOWNSTREAM_PKGS . indexOf ( key ) === - 1 ) {
107
113
console . log ( `${ key } not in DOWNSTREAM_PKGS, skipping...` ) ;
108
114
return ;
109
115
}
110
116
111
117
process . chdir ( TEMP_DOWNSTREAM_CACHE ) ;
112
118
113
- console . log ( ` ===> Running '${ key } ' tests <===` ) ;
114
- console . log ( ` ===> Installing freshly built upstream packages <===` ) ;
119
+ const name = downstreamTreeNode . installDir ;
120
+
121
+ console . log ( ` ===> '${ name } ': prepping tests <===` ) ;
115
122
process . chdir ( downstreamTreeNode . installDir ) ;
123
+
124
+ if ( ! yargs . argv . workspace ) {
125
+ console . log ( ` ===> '${ name } ': Installing dependencies <===` ) ;
126
+ util . _exec ( 'yarn && yarn upgrade' ) ;
127
+ }
128
+
129
+ console . log ( ` ===> '${ name } ': Installing freshly built upstream packages <===` ) ;
116
130
installUpstreamDeps ( upstreamPackages ) ;
131
+
132
+ console . log ( ` ===> '${ name } ': Running tests <===` ) ;
117
133
runTests ( ) ;
134
+
135
+ successLog . push ( key ) ;
136
+
137
+ console . log ( ` ===> '${ name } ': Reverting working copy <===` ) ;
118
138
revertLocalChanges ( downstreamTreeNode . installSource ) ;
139
+
140
+
141
+ const downstreamChildren = Object . keys ( downstreamTreeNode . children || { } ) ;
142
+ if ( downstreamChildren . length ) {
143
+ const thisPkg = JSON . parse ( fs . readFileSync ( 'package.json' ) ) . name ;
144
+ const upstreams = upstreamPackages . concat ( thisPkg ) ;
145
+
146
+ localPublish ( process . cwd ( ) ) ;
147
+
148
+ downstreamChildren . forEach ( child => {
149
+ runDownstreamTests ( child , upstreams , downstreamTreeNode . children [ child ] , successLog ) ;
150
+ } ) ;
151
+ }
119
152
}
120
153
121
154
console . log ( ` ===> Creating .downstream_cache working directory <===` ) ;
@@ -128,19 +161,23 @@ console.log(` ===> Fetching downstream projects <===`);
128
161
const tree = { children : { } } ;
129
162
fetchDownstreamProjects ( config , "" , tree . children ) ;
130
163
131
- console . log ( ` ===> Installing downstream dependencies <===` ) ;
132
- const downstreamDirs = getDownstreamInstallDirs ( tree ) ;
133
- installDependencies ( downstreamDirs ) ;
164
+ if ( yargs . argv . workspace ) {
165
+ console . log ( ` ===> Installing downstream dependencies <===` ) ;
166
+ const downstreamDirs = getDownstreamInstallDirs ( tree ) ;
167
+ installWorkspaceDependencies ( downstreamDirs ) ;
168
+ }
134
169
135
170
console . log ( ` ===> Moving working directory to temp dir ${ TEMP_DIR } <===` ) ;
136
171
shelljs . mv ( DOWNSTREAM_CACHE , TEMP_DIR ) ;
137
172
173
+ const successLog = [ ] ;
138
174
nodeCleanup ( ( ) => {
139
175
shelljs . mv ( TEMP_DOWNSTREAM_CACHE , PKG_DIR ) ;
176
+ console . log ( "Successfully ran downstream tests for: " + successLog . join ( ', ' ) ) ;
140
177
} ) ;
141
178
142
179
console . log ( ` ===> Running downstream tests <===` ) ;
143
180
Object . keys ( tree . children ) . forEach ( key => {
144
- console . log ( ` ===> Running tests for '${ key } ' <===` ) ;
145
- runDownstreamTests ( key , [ pkgjson . name ] , tree . children [ key ] ) ;
181
+ runDownstreamTests ( key , [ pkgjson . name ] , tree . children [ key ] , successLog ) ;
146
182
} ) ;
183
+
0 commit comments