From c205eb5d9d34cfaef4ce4eb8b28f2ac58ffb180e Mon Sep 17 00:00:00 2001 From: Julien Barbay Date: Fri, 15 Sep 2023 22:06:15 +0700 Subject: [PATCH] fix: allow extending the js banner (#77) Co-authored-by: Luke Shay <38476395+lukeshay@users.noreply.github.com> --- packages/adapter/src/shared.ts | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/packages/adapter/src/shared.ts b/packages/adapter/src/shared.ts index 23503d2..657ca8c 100644 --- a/packages/adapter/src/shared.ts +++ b/packages/adapter/src/shared.ts @@ -13,21 +13,26 @@ const DEFAULT_CONFIG: BuildOptions = { target: "node16", }; -export const createEsBuildConfig = (entryFile: string, outDir: string, { esBuildOptions = {} }: Args) => - mergeAndConcat(DEFAULT_CONFIG, esBuildOptions, { - banner: { - js: [ - "import { createRequire as topLevelCreateRequire } from 'module';", - "const require = topLevelCreateRequire(import.meta.url);", - ].join(""), - }, - entryPoints: [entryFile], - format: "esm", - outdir: outDir, - outExtension: { - ".js": ".mjs", - }, - }) as BuildOptions; +export const createEsBuildConfig = ( + entryFile: string, + outDir: string, + { esBuildOptions = {} }: Args +) => + mergeAndConcat(DEFAULT_CONFIG, esBuildOptions, { + banner: { + js: [ + "import { createRequire as topLevelCreateRequire } from 'module';", + 'const require = topLevelCreateRequire(import.meta.url);', + esBuildOptions.banner?.js ?? '', + ].join(''), + }, + entryPoints: [entryFile], + format: 'esm', + outdir: outDir, + outExtension: { + '.js': '.mjs', + }, + }) as BuildOptions export const bundleEntry = async (entryFile: string, outDir: string, args: Args) => { await build(createEsBuildConfig(entryFile, outDir, args));