@@ -23,6 +23,7 @@ const projects = config.projects || config;
2323const nohoist = ( config . projects && config . nohoist ) || [ ] ;
2424
2525const DOWNSTREAM_PKGS = ( process . env . DOWNSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
26+ const UPSTREAM_PKGS = ( process . env . UPSTREAM_PKGS || '' ) . split ( ',' ) . filter ( x => x ) ;
2627
2728const TEMP = tmp . dirSync ( ) ;
2829const TEMP_DIR = TEMP . name ;
@@ -31,16 +32,48 @@ const DOWNSTREAM_CACHE = path.resolve(PKG_DIR, '.downstream_cache');
3132
3233function makeDownstreamCache ( ) {
3334 if ( ! fs . existsSync ( DOWNSTREAM_CACHE ) ) {
34- console . log ( 'making .downstream_cache working directory' ) ;
35+ console . log ( ' ===> making .downstream_cache working directory <=== ' ) ;
3536 fs . mkdirSync ( DOWNSTREAM_CACHE ) ;
3637 }
3738}
3839
3940function localPublish ( packageDir ) {
4041 packageDir = packageDir || PKG_DIR ;
4142 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+ }
4477}
4578
4679function installUpstreamDeps ( upstreamPackages ) {
@@ -78,7 +111,7 @@ function fetchDownstreamProjects(downstreamConfig, prefix, downstreamTreeNode) {
78111 Object . keys ( downstreamConfig ) . forEach ( key => {
79112 const installDir = prefix ? `${ prefix } .${ key } ` : key ;
80113
81- console . log ( ` ===> Fetching downstream project to '${ installDir } ' <===` ) ;
114+ console . log ( ` ===> Fetching downstream project to '${ installDir } ' <===` ) ;
82115 const installSource = downstreamConfig [ key ] ;
83116 const isFile = / ^ \. / . exec ( installSource ) ;
84117 const installSourcePath = prefix ? path . resolve ( DOWNSTREAM_CACHE , prefix , installSource ) : path . resolve ( PKG_DIR , installSource ) ;
@@ -123,31 +156,31 @@ function installWorkspaceDependencies(downstreamInstallDirs) {
123156
124157function runDownstreamTests ( key , upstreamPackages , downstreamTreeNode , successLog ) {
125158 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... <=== ` ) ;
127160 return ;
128161 }
129162
130163 process . chdir ( TEMP_DOWNSTREAM_CACHE ) ;
131164
132165 const name = downstreamTreeNode . installDir ;
133166
134- console . log ( ` ===> '${ name } ': prepping tests <===` ) ;
167+ console . log ( ` ===> '${ name } ': prepping tests <===` ) ;
135168 process . chdir ( downstreamTreeNode . installDir ) ;
136169
137170 if ( ! yargs . argv . workspace ) {
138- console . log ( ` ===> '${ name } ': Installing dependencies <===` ) ;
171+ console . log ( ` ===> '${ name } ': Installing dependencies <===` ) ;
139172 util . _exec ( 'yarn' ) ;
140173 }
141174
142- console . log ( ` ===> '${ name } ': Installing freshly built upstream packages <===` ) ;
175+ console . log ( ` ===> '${ name } ': Installing freshly built upstream packages <===` ) ;
143176 installUpstreamDeps ( upstreamPackages ) ;
144177
145- console . log ( ` ===> '${ name } ': Running tests <===` ) ;
178+ console . log ( ` ===> '${ name } ': Running tests <===` ) ;
146179 runTests ( ) ;
147180
148181 successLog . push ( key ) ;
149182
150- console . log ( ` ===> '${ name } ': Reverting working copy <===` ) ;
183+ console . log ( ` ===> '${ name } ': Reverting working copy <===` ) ;
151184 revertLocalChanges ( downstreamTreeNode . installSource ) ;
152185
153186
@@ -164,32 +197,32 @@ function runDownstreamTests(key, upstreamPackages, downstreamTreeNode, successLo
164197 }
165198}
166199
167- console . log ( ` ===> Creating .downstream_cache working directory <===` ) ;
200+ console . log ( ` ===> Creating .downstream_cache working directory <===` ) ;
168201makeDownstreamCache ( ) ;
169202
170- console . log ( ` ===> Publishing ${ pkgjson . name } to yalc registry <===` ) ;
203+ console . log ( ` ===> Publishing ${ pkgjson . name } to yalc registry <===` ) ;
171204localPublish ( ) ;
172205
173- console . log ( ` ===> Fetching downstream projects <===` ) ;
206+ console . log ( ` ===> Fetching downstream projects <===` ) ;
174207const tree = { children : { } } ;
175208fetchDownstreamProjects ( projects , "" , tree . children ) ;
176209
177210if ( yargs . argv . workspace ) {
178- console . log ( ` ===> Installing downstream dependencies <===` ) ;
211+ console . log ( ` ===> Installing downstream dependencies <===` ) ;
179212 const downstreamDirs = getDownstreamInstallDirs ( tree ) ;
180213 installWorkspaceDependencies ( downstreamDirs ) ;
181214}
182215
183- console . log ( ` ===> Moving working directory to temp dir ${ TEMP_DIR } <===` ) ;
216+ console . log ( ` ===> Moving working directory to temp dir ${ TEMP_DIR } <===` ) ;
184217shelljs . mv ( DOWNSTREAM_CACHE , TEMP_DIR ) ;
185218
186219const successLog = [ ] ;
187220nodeCleanup ( ( ) => {
188221 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 ( ', ' ) } <===` ) ;
190223} ) ;
191224
192- console . log ( ` ===> Running downstream tests <===` ) ;
225+ console . log ( ` ===> Running downstream tests <===` ) ;
193226Object . keys ( tree . children ) . forEach ( key => {
194227 runDownstreamTests ( key , [ pkgjson . name ] , tree . children [ key ] , successLog ) ;
195228} ) ;
0 commit comments