@@ -10,6 +10,18 @@ const mockTrace = () => ({
10
10
traceChild : ( ) => mockTrace ( ) ,
11
11
} )
12
12
13
+ let turboRepoRoot = path . join ( __dirname , '..' , '..' , '..' , '..' , '..' )
14
+
15
+ // stats-action runs this code without access to the original repo.
16
+ // In that case we just use the temporary directory (everything is temporary anyway in CI)
17
+ if ( turboRepoRoot === '/' ) {
18
+ turboRepoRoot = path . join ( __dirname , '..' , '..' )
19
+ }
20
+
21
+ /** Save turbo cache to persistent storage */
22
+ const turboCacheLocation = path . join ( turboRepoRoot , 'node_modules/.cache/turbo' )
23
+ const packedPkgsDir = path . join ( turboRepoRoot , 'test/tmp/packedPkgs' )
24
+
13
25
module . exports = ( actionInfo ) => {
14
26
return {
15
27
async cloneRepo ( repoPath = '' , dest = '' ) {
@@ -81,9 +93,15 @@ module.exports = (actionInfo) => {
81
93
await rootSpan
82
94
. traceChild ( 'prepare packages for packing' )
83
95
. traceAsyncFn ( async ( ) => {
96
+ await fs . ensureDir ( packedPkgsDir )
97
+ const repoData = require ( path . join ( repoDir , 'package.json' ) )
98
+
84
99
for ( const pkg of pkgs ) {
85
100
const pkgPath = path . join ( repoDir , 'packages' , pkg )
86
- const packedPkgPath = path . join ( pkgPath , `${ pkg } -packed.tgz` )
101
+ const packedPkgPath = path . join (
102
+ packedPkgsDir ,
103
+ `${ pkg } -packed.tgz`
104
+ )
87
105
88
106
const pkgDataPath = path . join ( pkgPath , 'package.json' )
89
107
if ( ! fs . existsSync ( pkgDataPath ) ) {
@@ -103,7 +121,8 @@ module.exports = (actionInfo) => {
103
121
}
104
122
105
123
for ( const pkg of pkgDatas . keys ( ) ) {
106
- const { pkgDataPath, pkgData } = pkgDatas . get ( pkg )
124
+ const { pkgDataPath, pkgData, pkgPath, packedPkgPath } =
125
+ pkgDatas . get ( pkg )
107
126
108
127
for ( const pkg of pkgDatas . keys ( ) ) {
109
128
const { packedPkgPath } = pkgDatas . get ( pkg )
@@ -139,6 +158,27 @@ module.exports = (actionInfo) => {
139
158
}
140
159
}
141
160
161
+ // Turbo requires package manager specification
162
+ pkgData . packageManager =
163
+ pkgData . packageManager || repoData . packageManager
164
+
165
+ pkgData . scripts = {
166
+ ...pkgData . scripts ,
167
+ 'test-pack' : `yarn pack -f ${ packedPkgPath } ` ,
168
+ }
169
+
170
+ await fs . writeJSON ( path . join ( pkgPath , 'turbo.json' ) , {
171
+ pipeline : {
172
+ 'test-pack' : {
173
+ outputs : [ packedPkgPath ] ,
174
+ inputs : [ '*' , '!node_modules/' , '!.turbo/' ] ,
175
+ } ,
176
+ } ,
177
+ } )
178
+
179
+ // Turbo requires pnpm-lock.yaml that is not empty
180
+ await fs . writeFile ( path . join ( pkgPath , 'pnpm-lock.yaml' ) , '' )
181
+
142
182
await fs . writeFile (
143
183
pkgDataPath ,
144
184
JSON . stringify ( pkgData , null , 2 ) ,
@@ -157,9 +197,9 @@ module.exports = (actionInfo) => {
157
197
await packingSpan
158
198
. traceChild ( `pack ${ pkgName } ` )
159
199
. traceAsyncFn ( async ( ) => {
160
- const { pkg , pkgPath } = pkgDatas . get ( pkgName )
200
+ const { pkgPath } = pkgDatas . get ( pkgName )
161
201
await exec (
162
- `cd ${ pkgPath } && yarn pack -f ' ${ pkg } -packed.tgz' ` ,
202
+ `pnpm run --dir=" ${ turboRepoRoot } " turbo run test- pack --cache-dir=" ${ turboCacheLocation } " --cwd=" ${ pkgPath } " ` ,
163
203
true
164
204
)
165
205
} )
0 commit comments