@@ -117,10 +117,12 @@ async function runify(packagePath: string, reporter: Consola) {
117
117
}
118
118
119
119
if ( isNext ( pkg ) ) {
120
- await buildNext ( cwd ) ;
120
+ const additionalRequire = pkg ?. buildOptions ?. runify ?. next ?. header ?? null ;
121
+ await buildNext ( cwd , additionalRequire ) ;
121
122
await rewritePackageJson ( pkg , cwd , ( newPkg ) => ( {
122
123
...newPkg ,
123
124
dependencies : pkg . dependencies ,
125
+ type : "commonjs" ,
124
126
} ) ) ;
125
127
} else {
126
128
await compile (
@@ -195,7 +197,7 @@ function isNext(pkg: any): boolean {
195
197
return pkg ?. dependencies ?. next || pkg ?. devDependencies ?. next ;
196
198
}
197
199
198
- async function buildNext ( cwd : string ) {
200
+ async function buildNext ( cwd : string , additionalRequire : string | null ) {
199
201
await new Promise ( ( resolve , reject ) => {
200
202
const child = spawn ( "next" , [ "build" ] , {
201
203
stdio : "inherit" ,
@@ -206,6 +208,17 @@ async function buildNext(cwd: string) {
206
208
} ) ;
207
209
208
210
await fs . mkdirp ( join ( cwd , "dist" ) ) ;
211
+ if ( additionalRequire ) {
212
+ await tsup ( {
213
+ entryPoints : [ join ( cwd , additionalRequire ) ] ,
214
+ outDir : join ( cwd , "dist" ) ,
215
+ target : "node16" ,
216
+ format : [ "cjs" ] ,
217
+ splitting : false ,
218
+ skipNodeModulesBundle : true ,
219
+ } ) ;
220
+ }
221
+
209
222
await Promise . all ( [
210
223
fs . copy ( join ( cwd , ".next" ) , join ( cwd , "dist/.next" ) , {
211
224
filter ( src ) {
@@ -220,11 +233,15 @@ async function buildNext(cwd: string) {
220
233
`#!/usr/bin/env node` ,
221
234
`process.on('SIGTERM', () => process.exit(0))` ,
222
235
`process.on('SIGINT', () => process.exit(0))` ,
236
+ additionalRequire
237
+ ? `require('${ additionalRequire . replace ( ".ts" , "" ) } ')`
238
+ : `` ,
223
239
`
224
240
require('next/dist/server/lib/start-server').startServer({
225
241
dir: __dirname,
226
242
hostname: '0.0.0.0',
227
- port: parseInt(process.env.PORT)
243
+ port: parseInt(process.env.PORT),
244
+ conf: {},
228
245
}).then(async (app)=>{
229
246
const appUrl = 'http://' + app.hostname + ':' + app.port;
230
247
console.log('started server on '+ app.hostname + ':' + app.port + ', url: ' + appUrl);
@@ -257,6 +274,7 @@ async function compile(
257
274
splitting : false ,
258
275
sourcemap : true ,
259
276
clean : true ,
277
+ shims : true ,
260
278
skipNodeModulesBundle : false ,
261
279
noExternal : dependencies ,
262
280
external : buildOptions . external ,
0 commit comments