From 8fa0f3ed43f9d76a07297befe455f94fcd4927ec Mon Sep 17 00:00:00 2001 From: Aryan Falahatpisheh Date: Wed, 29 Apr 2026 21:30:33 -0400 Subject: [PATCH] Add 250MB limit --- src/deploy/apphosting/util.spec.ts | 20 ++++++++++++++++++++ src/deploy/apphosting/util.ts | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/deploy/apphosting/util.spec.ts b/src/deploy/apphosting/util.spec.ts index 9ade32530bd..73308ead89c 100644 --- a/src/deploy/apphosting/util.spec.ts +++ b/src/deploy/apphosting/util.spec.ts @@ -4,6 +4,7 @@ import * as path from "path"; import * as tmp from "tmp"; import * as tar from "tar"; import * as util from "./util"; +import { FirebaseError } from "../../error"; describe("util", () => { let tmpDir: tmp.DirResult; @@ -78,5 +79,24 @@ describe("util", () => { expect(files).to.include("dist/index.js"); expect(files).to.not.include("apphosting.yaml"); }); + + it("should throw an error if local build archive size exceeds limit", async () => { + fs.writeFileSync(path.join(distDir, "index.js"), "console.log('hello')"); + + const config = { + backendId: "test-backend", + rootDir: "", + ignore: [], + localBuild: true, + }; + + try { + await util.createLocalBuildTarArchive(config, rootDir, path.relative(rootDir, distDir), 1); + expect.fail("Should have thrown an error"); + } catch (err: unknown) { + expect(err).to.be.instanceOf(FirebaseError); + expect((err as FirebaseError).message).to.match(/The final build artifact is larger than/); + } + }); }); }); diff --git a/src/deploy/apphosting/util.ts b/src/deploy/apphosting/util.ts index b96d76e42e2..24f706566ad 100644 --- a/src/deploy/apphosting/util.ts +++ b/src/deploy/apphosting/util.ts @@ -24,6 +24,7 @@ export async function createLocalBuildTarArchive( config: AppHostingSingle, rootDir: string, targetSubDir?: string, + sizeLimitBytes: number = 250 * 1024 * 1024, ): Promise { const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".tar.gz" }).name; @@ -69,6 +70,16 @@ export async function createLocalBuildTarArchive( }, allFiles, ); + + const stats = fs.statSync(tmpFile); + if (config.localBuild && stats.size > sizeLimitBytes) { + const sizeInMB = stats.size / (1024 * 1024); + const limitInMB = sizeLimitBytes / (1024 * 1024); + throw new FirebaseError( + `The final build artifact is larger than ${limitInMB.toFixed(0)}MB (current size: ${sizeInMB.toFixed(2)}MB). Please reduce the size of your build artifacts.`, + ); + } + return tmpFile; }