@@ -4,11 +4,7 @@ const exec = require('../util/exec')
44const { remove } = require ( 'fs-extra' )
55const logger = require ( '../util/logger' )
66const semver = require ( 'semver' )
7-
8- const mockTrace = ( ) => ( {
9- traceAsyncFn : ( fn ) => fn ( mockTrace ( ) ) ,
10- traceChild : ( ) => mockTrace ( ) ,
11- } )
7+ const execa = require ( 'execa' )
128
139module . exports = ( actionInfo ) => {
1410 return {
@@ -58,117 +54,28 @@ module.exports = (actionInfo) => {
5854 }
5955 }
6056 } ,
61- async linkPackages ( { repoDir = '' , nextSwcPkg, parentSpan } ) {
62- const rootSpan = parentSpan
63- ? parentSpan . traceChild ( 'linkPackages' )
64- : mockTrace ( )
65-
66- return await rootSpan . traceAsyncFn ( async ( ) => {
67- const pkgPaths = new Map ( )
68- const pkgDatas = new Map ( )
69- let pkgs
70-
71- try {
72- pkgs = await fs . readdir ( path . join ( repoDir , 'packages' ) )
73- } catch ( err ) {
74- if ( err . code === 'ENOENT' ) {
75- require ( 'console' ) . log ( 'no packages to link' )
76- return pkgPaths
77- }
78- throw err
79- }
80-
81- await rootSpan
82- . traceChild ( 'prepare packages for packing' )
83- . traceAsyncFn ( async ( ) => {
84- for ( const pkg of pkgs ) {
85- const pkgPath = path . join ( repoDir , 'packages' , pkg )
86- const packedPkgPath = path . join ( pkgPath , `${ pkg } -packed.tgz` )
87-
88- const pkgDataPath = path . join ( pkgPath , 'package.json' )
89- if ( ! fs . existsSync ( pkgDataPath ) ) {
90- require ( 'console' ) . log ( `Skipping ${ pkgDataPath } ` )
91- continue
92- }
93- const pkgData = require ( pkgDataPath )
94- const { name } = pkgData
95- pkgDatas . set ( name , {
96- pkgDataPath,
97- pkg,
98- pkgPath,
99- pkgData,
100- packedPkgPath,
101- } )
102- pkgPaths . set ( name , packedPkgPath )
103- }
104-
105- for ( const pkg of pkgDatas . keys ( ) ) {
106- const { pkgDataPath, pkgData } = pkgDatas . get ( pkg )
107-
108- for ( const pkg of pkgDatas . keys ( ) ) {
109- const { packedPkgPath } = pkgDatas . get ( pkg )
110- if ( ! pkgData . dependencies || ! pkgData . dependencies [ pkg ] )
111- continue
112- pkgData . dependencies [ pkg ] = packedPkgPath
113- }
114-
115- // make sure native binaries are included in local linking
116- if ( pkg === '@next/swc' ) {
117- if ( ! pkgData . files ) {
118- pkgData . files = [ ]
119- }
120- pkgData . files . push ( 'native' )
121- require ( 'console' ) . log (
122- 'using swc binaries: ' ,
123- await exec (
124- `ls ${ path . join ( path . dirname ( pkgDataPath ) , 'native' ) } `
125- )
126- )
127- }
128-
129- if ( pkg === 'next' ) {
130- if ( nextSwcPkg ) {
131- Object . assign ( pkgData . dependencies , nextSwcPkg )
132- } else {
133- if ( pkgDatas . get ( '@next/swc' ) ) {
134- pkgData . dependencies [ '@next/swc' ] =
135- pkgDatas . get ( '@next/swc' ) . packedPkgPath
136- } else {
137- pkgData . files . push ( 'native' )
138- }
139- }
140- }
141-
142- await fs . writeFile (
143- pkgDataPath ,
144- JSON . stringify ( pkgData , null , 2 ) ,
145- 'utf8'
146- )
147- }
148- } )
149-
150- // wait to pack packages until after dependency paths have been updated
151- // to the correct versions
152- await rootSpan
153- . traceChild ( 'packing packages' )
154- . traceAsyncFn ( async ( packingSpan ) => {
155- await Promise . all (
156- Array . from ( pkgDatas . keys ( ) ) . map ( async ( pkgName ) => {
157- await packingSpan
158- . traceChild ( `pack ${ pkgName } ` )
159- . traceAsyncFn ( async ( ) => {
160- const { pkg, pkgPath } = pkgDatas . get ( pkgName )
161- await exec (
162- `cd ${ pkgPath } && yarn pack -f '${ pkg } -packed.tgz'` ,
163- true
164- )
165- } )
166- } )
167- )
168- } )
57+ async linkPackages ( { repoDir, nextSwcVersion } ) {
58+ execa . sync ( 'pnpm' , [ 'turbo' , 'run' , 'test-pack' ] , {
59+ cwd : repoDir ,
60+ env : { NEXT_SWC_VERSION : nextSwcVersion } ,
61+ } )
16962
170- return pkgPaths
63+ const pkgPaths = new Map ( )
64+ const pkgs = await fs . readdir ( path . join ( repoDir , 'packages' ) )
65+
66+ pkgs . forEach ( ( pkgDirname ) => {
67+ const { name } = require ( path . join (
68+ repoDir ,
69+ 'packages' ,
70+ pkgDirname ,
71+ 'package.json'
72+ ) )
73+ pkgPaths . set (
74+ name ,
75+ path . join ( repoDir , 'packages' , pkgDirname , `packed-${ pkgDirname } .tgz` )
76+ )
17177 } )
78+ return pkgPaths
17279 } ,
17380 }
17481}
0 commit comments