Skip to content

Commit c0895ef

Browse files
committed
refactor(producer): /simplify pass on lambda-local harness imports
Three small cleanups on top of the lambda-local harness: - Drop the unused createReadStream import + its `void` workaround comment. The aws-lambda handler's tar / S3 transport pulls createReadStream from its own imports; this file never references it directly. - Hoist the dynamic `await import("node:fs")` calls for writeFileSync out of FilesystemBackedFakeS3.send into the static import block. Repeated PutObject calls don't need to repay the dynamic-import cost. - Hoist the dynamic `await import("@hyperframes/aws-lambda")` call for untarDirectory similarly. Drops the now-redundant duplicate aws-lambda import statement. The PutObject body branch also collapses: `body instanceof Buffer` and `typeof body === "string"` both call writeFileSync identically, so they share one branch. No behavior changes.
1 parent 8e8012e commit c0895ef

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

‎packages/producer/src/regression-harness-lambda-local.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
*/
2424

2525
import {
26-
createReadStream,
2726
createWriteStream,
2827
existsSync,
2928
mkdirSync,
3029
readFileSync,
3130
statSync,
31+
writeFileSync,
3232
} from "node:fs";
3333
import { dirname, join } from "node:path";
3434
import { pipeline } from "node:stream/promises";
3535
import { Readable } from "node:stream";
3636
import type { Fps } from "@hyperframes/core";
37+
import { downloadS3ObjectToFile, tarDirectory, untarDirectory } from "@hyperframes/aws-lambda";
3738
import { handler } from "@hyperframes/aws-lambda/handler";
3839
import type {
3940
AssembleEvent,
@@ -45,7 +46,6 @@ import type {
4546
RenderChunkLambdaResult,
4647
SerializableDistributedRenderConfig,
4748
} from "@hyperframes/aws-lambda";
48-
import { downloadS3ObjectToFile, tarDirectory } from "@hyperframes/aws-lambda";
4949

5050
/** Inputs for {@link runLambdaLocalRender}. Same contract as `runDistributedSimulatedRender`. */
5151
export interface RunLambdaLocalInput {
@@ -153,7 +153,6 @@ export async function runLambdaLocalRender(input: RunLambdaLocalInput): Promise<
153153
if (input.format === "png-sequence") {
154154
const tarPath = join(s3Root, finalKey);
155155
mkdirSync(input.renderedOutputPath, { recursive: true });
156-
const { untarDirectory } = await import("@hyperframes/aws-lambda");
157156
await untarDirectory(tarPath, input.renderedOutputPath);
158157
} else {
159158
await downloadS3ObjectToFile(
@@ -195,14 +194,10 @@ class FilesystemBackedFakeS3 {
195194
if (cmdName === "PutObjectCommand") {
196195
mkdirSync(dirname(fsPath), { recursive: true });
197196
const body = input.Body;
198-
if (body instanceof Buffer) {
199-
const { writeFileSync } = await import("node:fs");
197+
if (body instanceof Buffer || typeof body === "string") {
200198
writeFileSync(fsPath, body);
201199
} else if (body && typeof (body as NodeJS.ReadableStream).pipe === "function") {
202200
await pipeline(body as NodeJS.ReadableStream, createWriteStream(fsPath));
203-
} else if (typeof body === "string") {
204-
const { writeFileSync } = await import("node:fs");
205-
writeFileSync(fsPath, body);
206201
} else {
207202
throw new Error(`FakeS3: PutObject body shape not supported (${typeof body})`);
208203
}
@@ -224,12 +219,6 @@ class FilesystemBackedFakeS3 {
224219
}
225220
}
226221

227-
// Reference `createReadStream` so the dynamic node:fs import above isn't
228-
// dropped by aggressive bundlers; the handler's tar / S3 transport
229-
// internally relies on the real createReadStream when it's the one
230-
// reading.
231-
void createReadStream;
232-
233222
// Re-export the Fps type so callers that pass through this module's
234223
// boundary don't need a second @hyperframes/core dep declaration.
235224
export type { Fps };

0 commit comments

Comments
 (0)