Skip to content

Commit 0668426

Browse files
authored
Generalize createArchive for any directory. (#9131)
* Generalize createArchive for any directory.
1 parent d83bc88 commit 0668426

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

src/deploy/apphosting/deploy.spec.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ describe("apphosting", () => {
8989
}),
9090
);
9191
createBucketStub.resolves();
92-
createArchiveStub.resolves({
93-
projectSourcePath: "my-project/",
94-
zippedSourcePath: "path/to/foo-1234.zip",
95-
});
92+
createArchiveStub.resolves("path/to/foo-1234.zip");
9693
uploadObjectStub.resolves({
9794
bucket: "firebaseapphosting-sources-12345678-us-central1",
9895
object: "foo-1234",
@@ -109,10 +106,7 @@ describe("apphosting", () => {
109106
getProjectNumberStub.resolves("000000000000");
110107
getBucketStub.resolves();
111108
createBucketStub.resolves();
112-
createArchiveStub.resolves({
113-
projectSourcePath: "my-project/",
114-
zippedSourcePath: "path/to/foo-1234.zip",
115-
});
109+
createArchiveStub.resolves("path/to/foo-1234.zip");
116110
uploadObjectStub.resolves({
117111
bucket: "firebaseapphosting-sources-12345678-us-central1",
118112
object: "foo-1234",

src/deploy/apphosting/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export default async function (context: Context, options: Options): Promise<void
7373
}
7474

7575
for (const cfg of context.backendConfigs.values()) {
76-
const { projectSourcePath, zippedSourcePath } = await createArchive(cfg, options.projectRoot);
76+
const projectSourcePath = options.projectRoot ? options.projectRoot : process.cwd();
77+
const zippedSourcePath = await createArchive(cfg, projectSourcePath);
7778
const backendLocation = context.backendLocations.get(cfg.backendId);
7879
if (!backendLocation) {
7980
throw new FirebaseError(

src/deploy/apphosting/util.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,27 @@ import * as fsAsync from "../../fsAsync";
1010
* Locates the source code for a backend and creates an archive to eventually upload to GCS.
1111
* Based heavily on functions upload logic in src/deploy/functions/prepareFunctionsUpload.ts.
1212
*/
13-
export async function createArchive(
14-
config: AppHostingSingle,
15-
projectRoot?: string,
16-
): Promise<{ projectSourcePath: string; zippedSourcePath: string }> {
13+
export async function createArchive(config: AppHostingSingle, rootDir: string): Promise<string> {
1714
const tmpFile = tmp.fileSync({ prefix: `${config.backendId}-`, postfix: ".zip" }).name;
1815
const fileStream = fs.createWriteStream(tmpFile, {
1916
flags: "w",
2017
encoding: "binary",
2118
});
2219
const archive = archiver("zip");
2320

24-
if (!projectRoot) {
25-
projectRoot = process.cwd();
26-
}
2721
// We must ignore firebase-debug.log or weird things happen if you're in the public dir when you deploy.
2822
const ignore = config.ignore || ["node_modules", ".git"];
2923
ignore.push("firebase-debug.log", "firebase-debug.*.log");
30-
const gitIgnorePatterns = parseGitIgnorePatterns(projectRoot);
24+
const gitIgnorePatterns = parseGitIgnorePatterns(rootDir);
3125
ignore.push(...gitIgnorePatterns);
3226
try {
3327
const files = await fsAsync.readdirRecursive({
34-
path: projectRoot,
28+
path: rootDir,
3529
ignore: ignore,
3630
isGitIgnore: true,
3731
});
3832
for (const file of files) {
39-
const name = path.relative(projectRoot, file.name);
33+
const name = path.relative(rootDir, file.name);
4034
archive.file(file.name, {
4135
name,
4236
mode: file.mode,
@@ -49,7 +43,7 @@ export async function createArchive(
4943
{ original: err as Error, exit: 1 },
5044
);
5145
}
52-
return { projectSourcePath: projectRoot, zippedSourcePath: tmpFile };
46+
return tmpFile;
5347
}
5448

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

0 commit comments

Comments
 (0)