@@ -20,30 +20,38 @@ const tracer = wrapTracer(trace.getTracer('Next runtime'))
20
20
const copyHandlerDependencies = async ( ctx : PluginContext ) => {
21
21
await tracer . withActiveSpan ( 'copyHandlerDependencies' , async ( span ) => {
22
22
const promises : Promise < void > [ ] = [ ]
23
- const { included_files : includedFiles = [ ] } = ctx . netlifyConfig . functions ?. [ '*' ] || { }
24
23
// if the user specified some files to include in the lambda
25
24
// we need to copy them to the functions-internal folder
25
+ const { included_files : includedFiles = [ ] } = ctx . netlifyConfig . functions ?. [ '*' ] || { }
26
+
27
+ // we also force including the .env files to ensure those are available in the lambda
28
+ includedFiles . push (
29
+ posixJoin ( ctx . relativeAppDir , '.env' ) ,
30
+ posixJoin ( ctx . relativeAppDir , '.env.production' ) ,
31
+ posixJoin ( ctx . relativeAppDir , '.env.local' ) ,
32
+ posixJoin ( ctx . relativeAppDir , '.env.production.local' ) ,
33
+ )
34
+
26
35
span . setAttribute ( 'next.includedFiles' , includedFiles . join ( ',' ) )
27
- if ( includedFiles . length !== 0 ) {
28
- const resolvedFiles = await Promise . all (
29
- includedFiles . map ( ( globPattern ) => glob ( globPattern , { cwd : process . cwd ( ) } ) ) ,
36
+
37
+ const resolvedFiles = await Promise . all (
38
+ includedFiles . map ( ( globPattern ) => glob ( globPattern , { cwd : process . cwd ( ) } ) ) ,
39
+ )
40
+ for ( const filePath of resolvedFiles . flat ( ) ) {
41
+ promises . push (
42
+ cp (
43
+ join ( process . cwd ( ) , filePath ) ,
44
+ // the serverHandlerDir is aware of the dist dir.
45
+ // The distDir must not be the package path therefore we need to rely on the
46
+ // serverHandlerDir instead of the serverHandlerRootDir
47
+ // therefore we need to remove the package path from the filePath
48
+ join ( ctx . serverHandlerDir , relative ( ctx . relativeAppDir , filePath ) ) ,
49
+ {
50
+ recursive : true ,
51
+ force : true ,
52
+ } ,
53
+ ) ,
30
54
)
31
- for ( const filePath of resolvedFiles . flat ( ) ) {
32
- promises . push (
33
- cp (
34
- join ( process . cwd ( ) , filePath ) ,
35
- // the serverHandlerDir is aware of the dist dir.
36
- // The distDir must not be the package path therefore we need to rely on the
37
- // serverHandlerDir instead of the serverHandlerRootDir
38
- // therefore we need to remove the package path from the filePath
39
- join ( ctx . serverHandlerDir , relative ( ctx . relativeAppDir , filePath ) ) ,
40
- {
41
- recursive : true ,
42
- force : true ,
43
- } ,
44
- ) ,
45
- )
46
- }
47
55
}
48
56
49
57
const fileList = await glob ( 'dist/**/*' , { cwd : ctx . pluginDir } )
0 commit comments