1
1
import { NetlifyPluginOptions } from '@netlify/build'
2
2
import { nodeFileTrace } from '@vercel/nft'
3
3
import { cp , rm , writeFile } from 'fs/promises'
4
- import { join , resolve } from 'node:path'
4
+ import { join , relative , resolve } from 'node:path'
5
5
import {
6
6
PLUGIN_DIR ,
7
7
PLUGIN_NAME ,
@@ -27,13 +27,27 @@ export const createServerHandler = async ({
27
27
join ( PLUGIN_DIR , 'dist/run/handlers/cache.cjs' ) ,
28
28
join ( PLUGIN_DIR , 'dist/run/handlers/next.cjs' ) ,
29
29
] ,
30
- { base : PLUGIN_DIR , ignore : [ 'package.json' , 'node_modules/next/**' ] } ,
30
+ // base in this case is the directory where it should stop looking up.
31
+ // by setting this to `/` we get absolute paths and don't have to worry about wrongly chaining it
32
+ {
33
+ base : '/' ,
34
+ ignore : [ '**/node_modules/next/**' ] ,
35
+ } ,
31
36
)
32
37
33
38
// copy the handler dependencies
34
39
await Promise . all (
35
40
[ ...fileList ] . map ( async ( path ) => {
36
- await cp ( resolve ( PLUGIN_DIR , path ) , resolve ( SERVER_HANDLER_DIR , path ) , { recursive : true } )
41
+ // we have to use a fake cwd that points to the actual repository root. On the deployed version this will be the build directory
42
+ // As in the integration tests the node_modules are not located in the tmp directory
43
+ const cwd = process . env . NETLIFY_FAKE_TEST_CWD || process . cwd ( )
44
+ const absPath = `/${ path } `
45
+ // if the file that got traced is inside the plugin directory resolve it with the plugin directory
46
+ // if it is a node_module resolve it with the process working directory.
47
+ const relPath = relative ( path . includes ( PLUGIN_NAME ) ? PLUGIN_DIR : cwd , absPath )
48
+ await cp ( absPath , resolve ( SERVER_HANDLER_DIR , relPath ) , {
49
+ recursive : true ,
50
+ } )
37
51
} ) ,
38
52
)
39
53
0 commit comments