Skip to content

Commit 9c3a64b

Browse files
committed
make the diffs smaller
1 parent b846dbb commit 9c3a64b

5 files changed

Lines changed: 41 additions & 65 deletions

File tree

src/apphosting/localbuilds.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe("localBuild", () => {
1919
it("returns the expected output", async () => {
2020
const bundleConfig = {
2121
version: "v1" as const,
22-
2322
runConfig: {
2423
runCommand: "npm run build:prod",
2524
},

src/deploy/apphosting/deploy.spec.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,8 @@ describe("apphosting", () => {
109109
const bucketName = `firebaseapphosting-sources-${projectNumber}-${location}`;
110110
getProjectNumberStub.resolves(projectNumber);
111111
upsertBucketStub.resolves(bucketName);
112-
createArchiveStub.onFirstCall().resolves({
113-
file: "path/to/foo-1234.zip",
114-
removeCallback: sinon.stub(),
115-
});
116-
createTarArchiveStub.onFirstCall().resolves({
117-
file: "path/to/foo-local-build-1234.tar.gz",
118-
removeCallback: sinon.stub(),
119-
});
112+
createArchiveStub.onFirstCall().resolves("path/to/foo-1234.zip");
113+
createTarArchiveStub.onFirstCall().resolves("path/to/foo-local-build-1234.tar.gz");
120114

121115
uploadObjectStub.onFirstCall().resolves({
122116
bucket: bucketName,
@@ -200,14 +194,8 @@ describe("apphosting", () => {
200194
const bucketName = `firebaseapphosting-sources-${projectNumber}-${location}`;
201195
getProjectNumberStub.resolves(projectNumber);
202196
upsertBucketStub.resolves(bucketName);
203-
createArchiveStub.onFirstCall().resolves({
204-
file: "path/to/foo-1234.zip",
205-
removeCallback: sinon.stub(),
206-
});
207-
createTarArchiveStub.onFirstCall().resolves({
208-
file: "path/to/foo-local-build-1234.tar.gz",
209-
removeCallback: sinon.stub(),
210-
});
197+
createArchiveStub.onFirstCall().resolves("path/to/foo-1234.zip");
198+
createTarArchiveStub.onFirstCall().resolves("path/to/foo-local-build-1234.tar.gz");
211199

212200
uploadObjectStub.onFirstCall().resolves({
213201
bucket: bucketName,

src/deploy/apphosting/deploy.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,37 @@ export default async function (context: Context, options: Options): Promise<void
8282
}
8383
}
8484

85-
let zippedSource: { file: string; removeCallback: () => void } | undefined;
86-
try {
87-
zippedSource = isLocalBuild
88-
? await util.createLocalBuildTarArchive(cfg, rootDir, builtAppDir)
89-
: await util.createSourceDeployArchive(cfg, rootDir);
85+
const zippedSourcePath = isLocalBuild
86+
? await util.createLocalBuildTarArchive(cfg, rootDir, builtAppDir)
87+
: await util.createSourceDeployArchive(cfg, rootDir);
9088

91-
const zippedSourcePath = zippedSource.file;
89+
logLabeledBullet(
90+
"apphosting",
91+
`Zipped ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}`,
92+
);
9293

93-
logLabeledBullet(
94-
"apphosting",
95-
`Zipped ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}`,
96-
);
97-
98-
const backendLocation = context.backendLocations[cfg.backendId];
99-
if (!backendLocation) {
100-
throw new FirebaseError(
101-
`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`,
102-
);
103-
}
104-
logLabeledBullet(
105-
"apphosting",
106-
`Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`,
107-
);
108-
const bucketName = bucketsPerLocation[backendLocation]!;
109-
const { bucket, object } = await gcs.uploadObject(
110-
{
111-
file: zippedSourcePath,
112-
stream: fs.createReadStream(zippedSourcePath),
113-
},
114-
bucketName,
115-
isLocalBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP,
94+
const backendLocation = context.backendLocations[cfg.backendId];
95+
if (!backendLocation) {
96+
throw new FirebaseError(
97+
`Failed to find location for backend ${cfg.backendId}. Please contact support with the contents of your firebase-debug.log to report your issue.`,
11698
);
117-
logLabeledBullet("apphosting", `Uploaded at gs://${bucket}/${object}`);
118-
context.backendStorageUris[cfg.backendId] =
119-
`gs://${bucketName}/${path.basename(zippedSourcePath)}`;
120-
} finally {
121-
if (zippedSource) {
122-
zippedSource.removeCallback();
123-
}
12499
}
100+
logLabeledBullet(
101+
"apphosting",
102+
`Uploading ${isLocalBuild ? "built app" : "source"} for backend ${cfg.backendId}...`,
103+
);
104+
const bucketName = bucketsPerLocation[backendLocation]!;
105+
const { bucket, object } = await gcs.uploadObject(
106+
{
107+
file: zippedSourcePath,
108+
stream: fs.createReadStream(zippedSourcePath),
109+
},
110+
bucketName,
111+
isLocalBuild ? gcs.ContentType.TAR : gcs.ContentType.ZIP,
112+
);
113+
logLabeledBullet("apphosting", `Uploaded at gs://${bucket}/${object}`);
114+
context.backendStorageUris[cfg.backendId] =
115+
`gs://${bucketName}/${path.basename(zippedSourcePath)}`;
125116
}),
126117
);
127118
}

src/deploy/apphosting/util.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("util", () => {
3333
ignore: [],
3434
};
3535

36-
const { file: tarballPath } = await util.createLocalBuildTarArchive(
36+
const tarballPath = await util.createLocalBuildTarArchive(
3737
config,
3838
rootDir,
3939
path.relative(rootDir, distDir),
@@ -61,7 +61,7 @@ describe("util", () => {
6161
ignore: [],
6262
};
6363

64-
const { file: tarballPath } = await util.createLocalBuildTarArchive(
64+
const tarballPath = await util.createLocalBuildTarArchive(
6565
config,
6666
rootDir,
6767
path.relative(rootDir, distDir),

src/deploy/apphosting/util.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export async function createLocalBuildTarArchive(
2424
config: AppHostingSingle,
2525
rootDir: string,
2626
targetSubDir?: string,
27-
): Promise<{ file: string; removeCallback: () => void }> {
28-
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".tar.gz" });
29-
const tmpFileName = tmpFile.name;
27+
): Promise<string> {
28+
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".tar.gz" }).name;
3029

3130
const targetDir = targetSubDir ? path.join(rootDir, targetSubDir) : rootDir;
3231
const ignore = ["firebase-debug.log", "firebase-debug.*.log", ".git"];
@@ -64,13 +63,13 @@ export async function createLocalBuildTarArchive(
6463
await tar.create(
6564
{
6665
gzip: true,
67-
file: tmpFileName,
66+
file: tmpFile,
6867
cwd: rootDir,
6968
portable: true,
7069
},
7170
allFiles,
7271
);
73-
return { file: tmpFileName, removeCallback: tmpFile.removeCallback };
72+
return tmpFile;
7473
}
7574

7675
/**
@@ -81,10 +80,9 @@ export async function createSourceDeployArchive(
8180
config: AppHostingSingle,
8281
rootDir: string,
8382
targetSubDir?: string,
84-
): Promise<{ file: string; removeCallback: () => void }> {
85-
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" });
86-
const tmpFileName = tmpFile.name;
87-
const fileStream = fs.createWriteStream(tmpFileName, {
83+
): Promise<string> {
84+
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
85+
const fileStream = fs.createWriteStream(tmpFile, {
8886
flags: "w",
8987
encoding: "binary",
9088
});
@@ -116,7 +114,7 @@ export async function createSourceDeployArchive(
116114
{ original: err as Error, exit: 1 },
117115
);
118116
}
119-
return { file: tmpFileName, removeCallback: tmpFile.removeCallback };
117+
return tmpFile;
120118
}
121119

122120
function parseGitIgnorePatterns(projectRoot: string, gitIgnorePath = ".gitignore"): string[] {

0 commit comments

Comments
 (0)