@@ -53,11 +53,20 @@ const copyHandlerDependencies = async (ctx: PluginContext) => {
53
53
)
54
54
}
55
55
56
+ // We need to create a package.json file with type: module to make sure that the runtime modules
57
+ // are handled correctly as ESM modules
58
+ promises . push (
59
+ writeFile (
60
+ join ( ctx . serverHandlerRuntimeModulesDir , 'package.json' ) ,
61
+ JSON . stringify ( { type : 'module' } ) ,
62
+ ) ,
63
+ )
64
+
56
65
const fileList = await glob ( 'dist/**/*' , { cwd : ctx . pluginDir } )
57
66
58
67
for ( const filePath of fileList ) {
59
68
promises . push (
60
- cp ( join ( ctx . pluginDir , filePath ) , join ( ctx . serverHandlerDir , '.netlify' , filePath ) , {
69
+ cp ( join ( ctx . pluginDir , filePath ) , join ( ctx . serverHandlerRuntimeModulesDir , filePath ) , {
61
70
recursive : true ,
62
71
force : true ,
63
72
} ) ,
@@ -85,13 +94,6 @@ const writeHandlerManifest = async (ctx: PluginContext) => {
85
94
)
86
95
}
87
96
88
- const writePackageMetadata = async ( ctx : PluginContext ) => {
89
- await writeFile (
90
- join ( ctx . serverHandlerRootDir , 'package.json' ) ,
91
- JSON . stringify ( { type : 'module' } ) ,
92
- )
93
- }
94
-
95
97
const applyTemplateVariables = ( template : string , variables : Record < string , string > ) => {
96
98
return Object . entries ( variables ) . reduce ( ( acc , [ key , value ] ) => {
97
99
return acc . replaceAll ( key , value )
@@ -138,15 +140,14 @@ export const clearStaleServerHandlers = async (ctx: PluginContext) => {
138
140
*/
139
141
export const createServerHandler = async ( ctx : PluginContext ) => {
140
142
await tracer . withActiveSpan ( 'createServerHandler' , async ( ) => {
141
- await mkdir ( join ( ctx . serverHandlerDir , '.netlify' ) , { recursive : true } )
143
+ await mkdir ( join ( ctx . serverHandlerRuntimeModulesDir ) , { recursive : true } )
142
144
143
145
await copyNextServerCode ( ctx )
144
146
await copyNextDependencies ( ctx )
145
147
await copyHandlerDependencies ( ctx )
146
148
if ( ! ctx . useFrameworksAPI ) {
147
149
await writeHandlerManifest ( ctx )
148
150
}
149
- await writePackageMetadata ( ctx )
150
151
await writeHandlerFile ( ctx )
151
152
152
153
await verifyHandlerDirStructure ( ctx )
0 commit comments