1
1
const path = require ( 'path' ) ;
2
+ const fs = require ( 'fs' ) ;
2
3
const { spawn } = require ( 'child_process' ) ;
3
4
const projectRoot = process . cwd ( ) ;
4
5
const rxjsRoot = path . join ( __dirname , '../../' ) ;
6
+ const rxjsObservableRoot = path . join ( __dirname , '../../../observable' ) ;
5
7
const fixturesDirectory = path . join ( __dirname , 'fixtures' ) ;
6
8
const rxjsVersion = require ( path . join ( rxjsRoot , 'package.json' ) ) . version ;
7
9
const tgzPath = path . join ( rxjsRoot , `rxjs-${ rxjsVersion } .tgz` ) ;
10
+ const rxjsObservableTgzPath = path . join ( rxjsObservableRoot , `rxjs-observable-${ rxjsVersion } .tgz` ) ;
8
11
9
12
// These are the fixtures to run the import test against
10
13
// they map to directories in the fixtures directory
@@ -57,6 +60,14 @@ function execAsync(cmd, cwd = '.') {
57
60
58
61
async function main ( ) {
59
62
try {
63
+ console . log ( 'Building and packaging @rxjs/observable...' ) ;
64
+ try {
65
+ await execAsync ( 'yarn build && npm pack' , rxjsObservableRoot ) ;
66
+ } catch ( err ) {
67
+ console . error ( '❌ Failed to build and package @rxjs/observable!' ) ;
68
+ console . error ( err ) ;
69
+ throw err ;
70
+ }
60
71
console . log ( 'Building and packaging RxJS...' ) ;
61
72
try {
62
73
await execAsync ( 'yarn build && npm pack' , rxjsRoot ) ;
@@ -76,6 +87,10 @@ async function main() {
76
87
try {
77
88
console . log ( '\n' ) ;
78
89
console . log ( `Running ${ fixtureName } ...` ) ;
90
+
91
+ console . log ( 'Setting custom dependency resolution for local @rxjs/observable...' ) ;
92
+ addYarnResolution ( fixturePath , '@rxjs/observable' , `file:${ path . relative ( fixturePath , rxjsObservableTgzPath ) } ` ) ;
93
+
79
94
await execAsync ( `yarn install && yarn add ${ tgzPath } ` , fixturePath ) ;
80
95
await execAsync ( 'yarn test' , fixturePath ) ;
81
96
console . log ( `✅ ${ fixtureName } import test passed!` ) ;
@@ -89,6 +104,7 @@ async function main() {
89
104
try {
90
105
await execAsync ( 'yarn remove rxjs' , fixturePath ) ;
91
106
await execAsync ( 'rm -rf ./node_modules ./package-lock.json ./yarn.lock' , fixturePath ) ;
107
+ removeYarnResolution ( fixturePath , '@rxjs/observable' ) ;
92
108
} catch ( err ) {
93
109
console . warn ( 'fixtured not cleaned up' , err ) ;
94
110
}
@@ -101,7 +117,26 @@ async function main() {
101
117
}
102
118
} finally {
103
119
await execAsync ( `rm ${ tgzPath } ` , projectRoot ) ;
120
+ await execAsync ( `rm ${ rxjsObservableTgzPath } ` , rxjsObservableRoot ) ;
104
121
}
105
122
}
106
123
107
124
main ( ) ;
125
+
126
+ function addYarnResolution ( fixturePath , name , version ) {
127
+ const fixturePackageJson = fs . readFileSync ( path . join ( fixturePath , 'package.json' ) ) ;
128
+ const fixturePackageJsonObj = JSON . parse ( fixturePackageJson ) ;
129
+ fixturePackageJsonObj . resolutions = fixturePackageJsonObj . resolutions || { } ;
130
+ fixturePackageJsonObj . resolutions [ name ] = version ;
131
+ fs . writeFileSync ( path . join ( fixturePath , 'package.json' ) , JSON . stringify ( fixturePackageJsonObj , null , 2 ) ) ;
132
+ }
133
+
134
+ function removeYarnResolution ( fixturePath , name ) {
135
+ const fixturePackageJson = fs . readFileSync ( path . join ( fixturePath , 'package.json' ) ) ;
136
+ const fixturePackageJsonObj = JSON . parse ( fixturePackageJson ) ;
137
+ delete fixturePackageJsonObj . resolutions [ name ] ;
138
+ if ( ! Object . keys ( fixturePackageJsonObj . resolutions ) . length ) {
139
+ delete fixturePackageJsonObj . resolutions ;
140
+ }
141
+ fs . writeFileSync ( path . join ( fixturePath , 'package.json' ) , JSON . stringify ( fixturePackageJsonObj , null , 2 ) + '\n' ) ;
142
+ }
0 commit comments