2
2
import execa from 'execa'
3
3
import fs from 'fs-extra'
4
4
import { Span } from 'next/src/trace'
5
+ import { tmpdir } from 'node:os'
5
6
import path from 'path'
6
7
import { NextInstance } from './base'
7
8
@@ -14,6 +15,31 @@ type NetlifyDeployResponse = {
14
15
logs : string
15
16
}
16
17
18
+ async function packNextRuntimeImpl ( ) {
19
+ const runtimePackDir = await fs . mkdtemp ( path . join ( tmpdir ( ) , 'next-runtime-pack' ) )
20
+
21
+ const { stdout } = await execa (
22
+ 'npm' ,
23
+ [ 'pack' , '--json' , '--ignore-scripts' , `--pack-destination=${ runtimePackDir } ` ] ,
24
+ { cwd : process . env . RUNTIME_DIR || `${ process . cwd ( ) } /../next-runtime` } ,
25
+ )
26
+ const [ { filename, name } ] = JSON . parse ( stdout )
27
+
28
+ return {
29
+ runtimePackageName : name ,
30
+ runtimePackageTarballPath : path . join ( runtimePackDir , filename ) ,
31
+ }
32
+ }
33
+
34
+ let packNextRuntimePromise : ReturnType < typeof packNextRuntimeImpl > | null = null
35
+ function packNextRuntime ( ) {
36
+ if ( ! packNextRuntimePromise ) {
37
+ packNextRuntimePromise = packNextRuntimeImpl ( )
38
+ }
39
+
40
+ return packNextRuntimePromise
41
+ }
42
+
17
43
export class NextDeployInstance extends NextInstance {
18
44
private _cliOutput : string
19
45
private _buildId : string
@@ -45,8 +71,10 @@ export class NextDeployInstance extends NextInstance {
45
71
await fs . rename ( nodeModules , nodeModulesBak )
46
72
}
47
73
74
+ const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime ( )
75
+
48
76
// install dependencies
49
- await execa ( 'npm' , [ 'i' , '--legacy-peer-deps' ] , {
77
+ await execa ( 'npm' , [ 'i' , runtimePackageTarballPath , '--legacy-peer-deps' ] , {
50
78
cwd : this . testDir ,
51
79
stdio : 'inherit' ,
52
80
} )
@@ -68,10 +96,7 @@ export class NextDeployInstance extends NextInstance {
68
96
publish = ".next"
69
97
70
98
[[plugins]]
71
- package = "${ path . relative (
72
- this . testDir ,
73
- process . env . RUNTIME_DIR || `${ process . cwd ( ) } /../next-runtime` ,
74
- ) } "
99
+ package = "${ runtimePackageName } "
75
100
`
76
101
77
102
await fs . writeFile ( path . join ( this . testDir , 'netlify.toml' ) , toml )
0 commit comments