@@ -11,7 +11,7 @@ import { bundleExternal, sysNodeBundleCacheDir } from '../bundles/sys-node';
11
11
import { getBanner } from '../utils/banner' ;
12
12
import { type BuildOptions , createReplaceData } from '../utils/options' ;
13
13
import { writePkgJson } from '../utils/write-pkg-json' ;
14
- import { getBaseEsbuildOptions , getEsbuildAliases , runBuilds } from './util' ;
14
+ import { getBaseEsbuildOptions , getEsbuildAliases , getFirstOutputFile , runBuilds } from './util' ;
15
15
16
16
const CONNECTOR_NAME = 'connector.html' ;
17
17
@@ -199,7 +199,10 @@ function clientConnectorPlugin(opts: BuildOptions): Plugin {
199
199
name : 'clientConnectorPlugin' ,
200
200
setup ( build ) {
201
201
build . onEnd ( async ( buildResult ) => {
202
- const bundle = buildResult . outputFiles . find ( ( b ) => b . path . endsWith ( CONNECTOR_NAME ) ) ;
202
+ const bundle = buildResult . outputFiles ?. find ( ( b ) => b . path . endsWith ( CONNECTOR_NAME ) ) ;
203
+ if ( ! bundle ) {
204
+ throw "Couldn't find build result!" ;
205
+ }
203
206
let code = Buffer . from ( bundle . contents ) . toString ( ) ;
204
207
205
208
const tsResults = ts . transpileModule ( code , {
@@ -208,7 +211,7 @@ function clientConnectorPlugin(opts: BuildOptions): Plugin {
208
211
} ,
209
212
} ) ;
210
213
211
- if ( tsResults . diagnostics . length > 0 ) {
214
+ if ( tsResults . diagnostics ? .length ) {
212
215
throw new Error ( tsResults . diagnostics as any ) ;
213
216
}
214
217
@@ -221,7 +224,9 @@ function clientConnectorPlugin(opts: BuildOptions): Plugin {
221
224
compress : { hoist_vars : true , hoist_funs : true , ecma : 5 } ,
222
225
format : { ecma : 5 } ,
223
226
} ) ;
224
- code = minifyResults . code ;
227
+ if ( minifyResults . code ) {
228
+ code = minifyResults . code ;
229
+ }
225
230
}
226
231
227
232
code = banner + code + footer ;
@@ -243,7 +248,7 @@ function serverProcessAliasPlugin(): Plugin {
243
248
name : 'serverProcessAlias' ,
244
249
setup ( build ) {
245
250
build . onEnd ( async ( buildResult ) => {
246
- const bundle = buildResult . outputFiles [ 0 ] ;
251
+ const bundle = getFirstOutputFile ( buildResult ) ;
247
252
let code = Buffer . from ( bundle . contents ) . toString ( ) ;
248
253
code = code . replace ( 'await import("@dev-server-process")' , '(await import("./server-process.js")).default' ) ;
249
254
return fs . writeFile ( bundle . path , code ) ;
@@ -262,7 +267,7 @@ function esm2CJSPlugin(): Plugin {
262
267
name : 'esm2CJS' ,
263
268
setup ( build ) {
264
269
build . onEnd ( async ( buildResult ) => {
265
- const bundle = buildResult . outputFiles [ 0 ] ;
270
+ const bundle = getFirstOutputFile ( buildResult ) ;
266
271
let code = Buffer . from ( bundle . contents ) . toString ( ) ;
267
272
code = code . replace ( 'import_meta.url' , 'new (require("url").URL)("file:" + __filename).href' ) ;
268
273
return fs . writeFile ( bundle . path , code ) ;
@@ -276,7 +281,7 @@ function esm2CJSPlugin(): Plugin {
276
281
* @param opts build options
277
282
* @returns an esbuild plugin
278
283
*/
279
- function contentTypesPlugin ( opts ) {
284
+ function contentTypesPlugin ( opts : BuildOptions ) : Plugin {
280
285
return {
281
286
name : 'contentTypesPlugin' ,
282
287
setup ( build ) {
0 commit comments