From 4a66070f9befbef25220ba5fd1c538a6b85ecbec Mon Sep 17 00:00:00 2001 From: alexwillingham Date: Tue, 29 Oct 2024 05:33:08 -0400 Subject: [PATCH] fix(bundle): adapted proposal from issue #338 to fix memory leak when skipRebuild is true (#540) --- src/bundle.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index 6008a5d..462d3b1 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -1,6 +1,7 @@ import assert from 'assert'; import { Predicate } from 'effect'; import type { BuildOptions } from 'esbuild'; +import * as pkg from 'esbuild'; import fs from 'fs-extra'; import pMap from 'p-map'; import path from 'path'; @@ -104,11 +105,9 @@ export async function bundle(this: EsbuildServerlessPlugin): Promise { outdir: path.join(buildDirPath, path.dirname(entry)), }; - const pkg = await import('esbuild'); - type ContextFn = (opts: typeof options) => Promise; type WithContext = typeof pkg & { context?: ContextFn }; - const context = await (pkg as WithContext).context?.(options); + const context = buildOptions.skipRebuild ? undefined : await (pkg as WithContext).context?.(options); let result; if (!buildOptions.skipRebuild) {