@@ -2,21 +2,36 @@ import fs from "node:fs";
22import path from "node:path" ;
33
44import type { BuildOptions } from "@opennextjs/aws/build/helper.js" ;
5+ import { build } from "esbuild" ;
56
67import { Config } from "../../../config" ;
8+ import { extractProjectEnvVars } from "../../utils" ;
79
810/**
9- * Copies the template files present in the cloudflare adapter package into the standalone node_modules folder
11+ * Copies the template files present in the cloudflare adapter package into the
12+ * standalone node_modules folder and applies necessary transformations.
1013 */
11- export function copyPackageCliFiles ( packageDistDir : string , config : Config , openNextConfig : BuildOptions ) {
14+ export async function copyPackageCliFiles (
15+ packageDistDir : string ,
16+ config : Config ,
17+ openNextConfig : BuildOptions
18+ ) {
1219 console . log ( "# copyPackageTemplateFiles" ) ;
1320 const sourceDir = path . join ( packageDistDir , "cli" ) ;
1421 const destinationDir = path . join ( config . paths . internal . package , "cli" ) ;
1522
1623 fs . cpSync ( sourceDir , destinationDir , { recursive : true } ) ;
1724
18- fs . copyFileSync (
19- path . join ( packageDistDir , "cli" , "templates" , "worker.ts" ) ,
20- path . join ( openNextConfig . outputDir , "worker.ts" )
21- ) ;
25+ const envVars = extractProjectEnvVars ( openNextConfig ) ;
26+ await build ( {
27+ entryPoints : [ path . join ( packageDistDir , "cli" , "templates" , "worker.ts" ) ] ,
28+ outfile : path . join ( openNextConfig . outputDir , "worker.js" ) ,
29+ format : "esm" ,
30+ target : "esnext" ,
31+ bundle : false ,
32+ minify : false ,
33+ define : {
34+ __OPENNEXT_BUILD_TIME_ENV : JSON . stringify ( envVars ) ,
35+ } ,
36+ } ) ;
2237}
0 commit comments