Skip to content

Commit a5ec7a0

Browse files
committed
Clean up
1 parent 607cc5a commit a5ec7a0

File tree

8 files changed

+53
-73
lines changed

8 files changed

+53
-73
lines changed

package-lock.json

Lines changed: 21 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@apphosting/build/e2e/run-local-build.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import promiseSpawn from "@npmcli/promise-spawn";
33
import { dirname, join, relative } from "path";
44
import { fileURLToPath } from "url";
55
import { parse as parseYaml } from "yaml";
6-
import { spawn } from "child_process";
76
import fsExtra from "fs-extra";
87
import { scenarios } from "./scenarios.ts";
98

109
const { readFileSync, mkdirp, rmdir } = fsExtra;
1110

1211
const __dirname = dirname(fileURLToPath(import.meta.url));
1312

14-
const errors: any[] = [];
13+
const errors: Error[] = [];
1514

1615
await rmdir(join(__dirname, "runs"), { recursive: true }).catch(() => undefined);
1716

@@ -58,7 +57,7 @@ for (const [scenarioName, scenario] of scenarios) {
5857
).version;
5958

6059
try {
61-
await promiseSpawn("node", [buildScript, ...scenario.inputs], {
60+
const result = await promiseSpawn("node", [buildScript, ...scenario.inputs], {
6261
cwd,
6362
stdioString: true,
6463
stdio: "pipe",
@@ -67,10 +66,9 @@ for (const [scenarioName, scenario] of scenarios) {
6766
...process.env,
6867
FRAMEWORK_VERSION: frameworkVersion,
6968
},
70-
}).then((result) => {
71-
// Write stdout and stderr to the log file
72-
fsExtra.writeFileSync(buildLogPath, result.stdout + result.stderr);
7369
});
70+
// Write stdout and stderr to the log file
71+
fsExtra.writeFileSync(buildLogPath, result.stdout + result.stderr);
7472

7573
try {
7674
// Determine which test files to run
@@ -96,9 +94,8 @@ for (const [scenarioName, scenario] of scenarios) {
9694
console.error(`Error in scenario ${scenarioName}:`, e);
9795
errors.push(e);
9896
}
99-
100-
if (errors.length) {
101-
console.error(errors);
102-
process.exit(1);
103-
}
97+
}
98+
if (errors.length) {
99+
console.error(errors);
100+
process.exit(1);
104101
}

packages/@apphosting/build/e2e/scenarios.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import pkg from "@apphosting/common";
22
const { OutputBundleConfig } = pkg;
33

44
interface Scenario {
5-
name: string; // Name of the scenario
65
inputs: string[];
76
expectedBundleYaml: OutputBundleConfig;
87
tests?: string[]; // List of test files to run

packages/@apphosting/build/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"url": "git+https://github.com/FirebaseExtended/firebase-framework-tools.git"
99
},
1010
"bin": {
11-
"build": "dist/bin/build.js",
12-
"apphosting-local-build": "dist/bin/localbuild.js"
11+
"build": "dist/bin/build.js",
12+
"apphosting-local-build": "dist/bin/localbuild.js"
1313
},
1414
"author": {
1515
"name": "Firebase",
@@ -21,9 +21,9 @@
2121
"type": "module",
2222
"sideEffects": false,
2323
"scripts": {
24-
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*",
25-
"test": "npm run test:functional",
26-
"test:functional": "node --loader ts-node/esm ./e2e/run-local-build.ts"
24+
"build": "rm -rf dist && tsc && chmod +x ./dist/bin/*",
25+
"test": "npm run test:functional",
26+
"test:functional": "node --loader ts-node/esm ./e2e/run-local-build.ts"
2727
},
2828
"exports": {
2929
".": {
@@ -40,9 +40,11 @@
4040
"colorette": "^2.0.20",
4141
"commander": "^11.1.0",
4242
"npm-pick-manifest": "^9.0.0",
43-
"ts-node": "^10.9.1"
43+
"ts-node": "^10.9.1",
44+
"tsc": "^2.0.4"
4445
},
4546
"devDependencies": {
46-
"@types/commander": "*"
47+
"@types/commander": "*",
48+
"typescript": "^5.9.2"
4749
}
4850
}
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from "child_process";
1+
import promiseSpawn from "@npmcli/promise-spawn";
22
import { yellow, bgRed, bold } from "colorette";
33

44
export async function adapterBuild(projectRoot: string, framework: string) {
@@ -10,7 +10,12 @@ export async function adapterBuild(projectRoot: string, framework: string) {
1010
throw new Error(
1111
`Failed to fetch ${adapterName}: ${packumentResponse.status} ${packumentResponse.statusText}`,
1212
);
13-
const packument = await packumentResponse.json();
13+
let packument;
14+
try {
15+
packument = await packumentResponse.json();
16+
} catch (e) {
17+
throw new Error(`Failed to parse response from NPM registry for ${adapterName}.`);
18+
};
1419
const adapterVersion = packument?.["dist-tags"]?.["latest"];
1520
if (!adapterVersion) {
1621
throw new Error(`Could not find 'latest' dist-tag for ${adapterName}`);
@@ -20,20 +25,9 @@ export async function adapterBuild(projectRoot: string, framework: string) {
2025
console.log(" 🔥", bgRed(` ${adapterName}@${yellow(bold(adapterVersion))} `), "\n");
2126

2227
const buildCommand = `apphosting-adapter-${framework}-build`;
23-
await new Promise<void>((resolve, reject) => {
24-
const child = spawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
25-
cwd: projectRoot,
26-
shell: true,
27-
stdio: "inherit",
28-
});
29-
30-
child.on("error", reject);
31-
32-
child.on("exit", (code) => {
33-
if (code !== 0) {
34-
reject(new Error(`framework adapter build failed with error code ${code}.`));
35-
}
36-
resolve();
37-
});
28+
await promiseSpawn("npx", ["-y", "-p", `${adapterName}@${adapterVersion}`, buildCommand], {
29+
cwd: projectRoot,
30+
shell: true,
31+
stdio: "inherit",
3832
});
3933
}

packages/@apphosting/build/src/bin/localbuild.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#! /usr/bin/env node
2-
import { SupportedFrameworks, ApphostingConfig } from "@apphosting/common";
2+
import { SupportedFrameworks } from "@apphosting/common";
33
import { adapterBuild } from "../adapter-builds.js";
4-
import { parse as parseYaml } from "yaml";
5-
import fsExtra from "fs-extra";
6-
import { join } from "path";
74
import { program } from "commander";
85

9-
export const { readFileSync } = fsExtra;
10-
116
program
127
.argument("<projectRoot>", "path to the project's root directory")
138
.option("--framework <framework>")
@@ -17,7 +12,7 @@ program
1712
// TODO(#382): parse apphosting.yaml for environment variables / secrets needed during build time.
1813
if (opts.framework && SupportedFrameworks.includes(opts.framework)) {
1914
// TODO(#382): Skip this if there's a custom build command in apphosting.yaml.
20-
adapterBuild(projectRoot, opts.framework);
15+
await adapterBuild(projectRoot, opts.framework);
2116
}
2217

2318
// TODO(#382): Parse apphosting.yaml to set custom run command in bundle.yaml

packages/@apphosting/build/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"include": [
1010
"src/index.ts",
11-
"src/bin/*.ts"
11+
"src/bin/*.ts",
1212
],
1313
"exclude": [
1414
"src/*.spec.ts"

packages/@apphosting/common/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "node:fs";
33
import * as path from "node:path";
44

55
// List of apphosting supported frameworks.
6-
export const SupportedFrameworks = ["nextjs", "angular"];
6+
export const SupportedFrameworks = ["nextjs", "angular"] as const;
77

88
// **** OutputBundleConfig interfaces ****
99

0 commit comments

Comments
 (0)