Skip to content

Commit

Permalink
fix(bundle): adapted proposal from issue #338 to fix memory leak when…
Browse files Browse the repository at this point in the history
… skipRebuild is true (#540)
  • Loading branch information
alexwillingham authored Oct 29, 2024
1 parent 607a3ae commit 4a66070
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/bundle.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -104,11 +105,9 @@ export async function bundle(this: EsbuildServerlessPlugin): Promise<void> {
outdir: path.join(buildDirPath, path.dirname(entry)),
};

const pkg = await import('esbuild');

type ContextFn = (opts: typeof options) => Promise<BuildContext>;
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) {
Expand Down

0 comments on commit 4a66070

Please sign in to comment.