Skip to content

Commit 20c246e

Browse files
authored
Merge branch 'main' into nextjsadaptor-refactor-tests
2 parents ee3a4bc + b9a17ba commit 20c246e

File tree

13 files changed

+117
-67
lines changed

13 files changed

+117
-67
lines changed

.github/workflows/test.yml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,35 @@ jobs:
9696
- name: Test
9797
run: npm run test
9898

99-
# Break the branch protection test into a seperate step, so we can manage the matrix more easily
99+
lint:
100+
runs-on: ubuntu-latest
101+
name: Lint
102+
steps:
103+
- uses: actions/checkout@v4
104+
- name: Setup node
105+
uses: actions/setup-node@v3
106+
with:
107+
node-version: ${{ matrix.node }}
108+
check-latest: true
109+
- name: node_modules cache
110+
id: node_modules_cache
111+
uses: actions/cache@v3
112+
with:
113+
path: ./node_modules
114+
key: ${{ runner.os }}-20-${{ hashFiles('package-lock.json') }}
115+
restore-keys: |
116+
${{ runner.os }}-20-
117+
- name: Install deps
118+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
119+
run: npm ci
120+
- name: Test
121+
run: npm run lint:quiet
122+
123+
# Break the branch protection test into a separate step, so we can manage the matrix more easily
100124
test_and_contribute:
101125
runs-on: ubuntu-latest
102126
name: Branch protection
103-
needs: ['test']
127+
needs: ['test', 'lint']
104128
steps:
105129
- run: true
106130

CODEOWNERS

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
/packages/adapter-*/ @Yuangwang
2-
/packages/firebase-frameworks/ @jamesdaniels
1+
# Global reviewers
2+
# TODO add group for global reviewers
3+
* @jamesdaniels @leoortizz @Yuangwang @sjjj986
4+
5+
# App Hosting Platform Adapters code
6+
# TODO add group for App Hosting
7+
/packages/@apphosting/adapter-*/ @Yuangwang @sjjj986
8+
9+
# Web Frameworks code
10+
/packages/@apphosting/build/ @FirebaseExtended/firebase-full-time-employees @FirebaseExtended/monogram
11+
/packages/@apphosting/create/ @FirebaseExtended/firebase-full-time-employees @FirebaseExtended/monogram
12+
/packages/@apphosting/discover/ @FirebaseExtended/firebase-full-time-employees @FirebaseExtended/monogram
13+
/packages/firebase-frameworks/ @FirebaseExtended/firebase-full-time-employees @FirebaseExtended/monogram

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"test": "./scripts/test.js",
77
"publish": "./scripts/publish.js",
88
"lint": "eslint packages/* scripts/*",
9+
"lint:quiet": "eslint packages/* scripts/* --quiet",
910
"lint:fix": "eslint packages/* scripts/* --fix"
1011
},
1112
"workspaces": [

packages/@apphosting/adapter-angular/src/bin/create.spec.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,34 @@ const { readJson } = fsExtra;
77
const readPackageJson = readJson("package.json");
88
const importCreateJs = import("@apphosting/adapter-angular/dist/bin/create.js");
99

10-
describe("peer dependencies", async () => {
11-
12-
let expectedAngularRange: string;
13-
let exepctedDevKitArchitectRange: string;
14-
15-
before(async () => {
16-
const packageJson = await readPackageJson;
17-
const version = parse(packageJson.version);
18-
if (!version) throw "couldn't parse package.json version";
19-
expectedAngularRange = `~${version.major}.${version.minor}.0`;
20-
exepctedDevKitArchitectRange = `~0.${version.major}${version.minor < 10 ? '0' : ''}${version.minor}.0`;
21-
});
22-
23-
it("expected @angular/cli version requirement to match", async () => {
24-
const { ANGULAR_CLI_VERSION } = await importCreateJs;
25-
assert.equal(expectedAngularRange, ANGULAR_CLI_VERSION);
26-
});
27-
28-
it("expected @angular-devkit/architect version requirement to match", async () => {
29-
const packageJson = await readPackageJson;
30-
const devKitArchitectRange = packageJson.peerDependencies["@angular-devkit/architect"];
31-
assert.equal(exepctedDevKitArchitectRange, devKitArchitectRange);
32-
});
33-
34-
it("expected @angular-devkit/core version requirement to match", async () => {
35-
const packageJson = await readPackageJson;
36-
const devKitCoreRange = packageJson.peerDependencies["@angular-devkit/core"];
37-
assert.equal(expectedAngularRange, devKitCoreRange);
38-
});
10+
describe("peer dependencies", () => {
11+
let expectedAngularRange: string;
12+
let exepctedDevKitArchitectRange: string;
13+
14+
before(async () => {
15+
const packageJson = await readPackageJson;
16+
const version = parse(packageJson.version);
17+
if (!version) throw new Error("couldn't parse package.json version");
18+
expectedAngularRange = `~${version.major}.${version.minor}.0`;
19+
exepctedDevKitArchitectRange = `~0.${version.major}${version.minor < 10 ? "0" : ""}${
20+
version.minor
21+
}.0`;
22+
});
23+
24+
it("expected @angular/cli version requirement to match", async () => {
25+
const { ANGULAR_CLI_VERSION } = await importCreateJs;
26+
assert.equal(expectedAngularRange, ANGULAR_CLI_VERSION);
27+
});
28+
29+
it("expected @angular-devkit/architect version requirement to match", async () => {
30+
const packageJson = await readPackageJson;
31+
const devKitArchitectRange = packageJson.peerDependencies["@angular-devkit/architect"];
32+
assert.equal(exepctedDevKitArchitectRange, devKitArchitectRange);
33+
});
34+
35+
it("expected @angular-devkit/core version requirement to match", async () => {
36+
const packageJson = await readPackageJson;
37+
const devKitCoreRange = packageJson.peerDependencies["@angular-devkit/core"];
38+
assert.equal(expectedAngularRange, devKitCoreRange);
39+
});
3940
});

packages/@apphosting/adapter-nextjs/src/bin/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ const outputBundleOptions = populateOutputBundleOptions(cwd);
1111
const { distDir } = await loadConfig(cwd);
1212
const nextBuildDirectory = join(cwd, distDir);
1313

14-
await generateOutputBundle(cwd, outputBundleOptions, nextBuildDirectory);
14+
await generateOutputBundle(cwd, outputBundleOptions, nextBuildDirectory);

packages/@apphosting/adapter-nextjs/src/bin/create.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const { readJson } = fsExtra;
77
const readPackageJson = readJson("package.json");
88
const importCreateJs = import("@apphosting/adapter-nextjs/dist/bin/create.js");
99

10-
describe("peer dependencies", async () => {
10+
describe("peer dependencies", () => {
1111
let expectedNextJSRange: string;
1212

1313
before(async () => {
1414
const packageJson = await readPackageJson;
1515
const version = parse(packageJson.version);
16-
if (!version) throw "couldn't parse package.json version";
16+
if (!version) throw new Error("couldn't parse package.json version");
1717
expectedNextJSRange = `~${version.major}.${version.minor}.0`;
1818
});
1919

packages/@apphosting/adapter-nextjs/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { join, relative, normalize } from "path";
1010

1111
import type { RoutesManifest } from "./interfaces.js";
1212
// fs-extra is CJS, readJson can't be imported using shorthand
13-
export const { move, exists, writeFile, readJSON } = fsExtra;
13+
export const { move, exists, writeFile, readJson } = fsExtra;
1414

1515
export async function loadConfig(cwd: string) {
1616
// dynamically load NextJS so this can be used in an NPX context
@@ -21,7 +21,7 @@ export async function loadConfig(cwd: string) {
2121
}
2222

2323
export async function readRoutesManifest(distDir: string): Promise<RoutesManifest> {
24-
return await readJSON(join(distDir, ROUTES_MANIFEST));
24+
return await readJson(join(distDir, ROUTES_MANIFEST));
2525
}
2626

2727
export const isMain = (meta: ImportMeta) => {

packages/@apphosting/create/src/bin/create.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ import { spawn } from "child_process";
33
import { program } from "commander";
44

55
program
6-
.option('--framework <string>')
7-
.argument('<directory>', "path to the project's root directory")
8-
.action(async (directory, { framework }: { framework?: string }) => {
6+
.option("--framework <string>")
7+
.argument("<directory>", "path to the project's root directory")
8+
.action((directory, { framework }: { framework?: string }) => {
99
if (!framework) {
10-
throw new Error("Framework selecter not implemented. Must provide an option to --framework <string>");
10+
throw new Error(
11+
"Framework selecter not implemented. Must provide an option to --framework <string>",
12+
);
1113
}
1214
const adapterName = `@apphosting/adapter-${framework}`;
1315
const buildCommand = `apphosting-adapter-${framework}-create`;
14-
spawn('npx', ['-y', '-p', adapterName, buildCommand, directory], { shell: true, stdio: 'inherit' });
16+
spawn("npx", ["-y", "-p", adapterName, buildCommand, directory], {
17+
shell: true,
18+
stdio: "inherit",
19+
});
1520
});
1621

1722
program.parse();

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ type DiscoveredFramework = {
6161
bundledWith?: Array<(typeof PLATFORMS)[number][4][number][0]>;
6262
};
6363

64-
export async function discover(path: string, githubRepo?: string, githubToken?: string) {
64+
export async function discover(directory: string, githubRepo?: string, githubToken?: string) {
6565
if (githubRepo && !githubToken) throw new Error("needs token");
6666

67-
const { join } = await (githubRepo ? import("node:path") : import("node:path/posix"));
67+
const path = await (githubRepo ? import("node:path") : import("node:path/posix"));
6868

6969
const { readFile, pathExists, readJson } = githubRepo
7070
? {
@@ -115,12 +115,14 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
115115
await Promise.all(
116116
PLATFORMS.map(
117117
async ([platform, files, defaultPackageManager, packageManagers, frameworkDefinitions]) => {
118-
const filesExist = await Promise.all(files.map((it) => pathExists(join(path, it))));
118+
const filesExist = await Promise.all(
119+
files.map((it) => pathExists(path.join(directory, it))),
120+
);
119121
if (files.length && !filesExist.some((it) => it)) return;
120122
const discoverFrameworks = (fallback = false) => {
121123
return async ([packageManager, possibleLockfiles]: (typeof packageManagers)[number]) => {
122124
const possibleLockfilesExist = await Promise.all(
123-
possibleLockfiles.map((it) => pathExists(join(path, it))),
125+
possibleLockfiles.map((it) => pathExists(path.join(directory, it))),
124126
);
125127
const [lockfile] = possibleLockfilesExist
126128
.map((exists, index) => (exists ? possibleLockfiles[index] : undefined))
@@ -131,7 +133,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
131133
if (platform === "nodejs") {
132134
// TODO handle workspaces
133135
if (lockfile === "package-lock.json" || lockfile === "npm-shrinkwrap.json") {
134-
const packageJSON = await readJson(join(path, lockfile));
136+
const packageJSON = await readJson(path.join(directory, lockfile));
135137
packages = new Map(
136138
Object.keys(packageJSON.packages).map((pkg) => {
137139
const name = pkg.replace(/^node_modules\//, "");
@@ -140,7 +142,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
140142
}),
141143
);
142144
} else if (lockfile === "yarn.lock") {
143-
const file = await readFile(join(path, lockfile));
145+
const file = await readFile(path.join(directory, lockfile));
144146
const yarnLock = YarnLockfile.parse(file.toString());
145147
if (yarnLock.type !== "success") throw new Error(`unable to read ${lockfile}`);
146148
packages = new Map(
@@ -151,7 +153,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
151153
}),
152154
);
153155
} else if (lockfile === "pnpm-lock.yaml") {
154-
const file = await readFile(join(path, lockfile));
156+
const file = await readFile(path.join(directory, lockfile));
155157
const pnpmLock = parseYaml(file.toString());
156158
packages = new Map(
157159
Object.keys(pnpmLock.packages).map((pkg) => {
@@ -164,9 +166,11 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
164166
} else if (platform === "python") {
165167
if (packageManager === "pip") {
166168
const requirementsFile = "requirements.txt";
167-
const requirementsFileExists = await pathExists(join(path, requirementsFile));
169+
const requirementsFileExists = await pathExists(
170+
path.join(directory, requirementsFile),
171+
);
168172
if (!requirementsFileExists) return false;
169-
const file = await readFile(join(path, requirementsFile));
173+
const file = await readFile(path.join(directory, requirementsFile));
170174
packages = new Map(
171175
file
172176
.toString()
@@ -176,7 +180,7 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
176180
}),
177181
);
178182
} else if (lockfile === "Pipfile.lock") {
179-
const pipfileLock = await readJson(join(path, lockfile));
183+
const pipfileLock = await readJson(path.join(directory, lockfile));
180184
// TODO include develop too?
181185
packages = new Map(
182186
Object.keys(pipfileLock.default).map((name) => {
@@ -186,11 +190,11 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
186190
}),
187191
);
188192
} else if (lockfile === "poetry.lock") {
189-
const poetryLock = await readFile(join(path, lockfile));
193+
const poetryLock = await readFile(path.join(directory, lockfile));
190194
packages = new Map(
191195
toml
192196
.parse(poetryLock.toString())
193-
.package?.map((it: any) => [it.name, it.version]),
197+
.package?.map((it: { name: string; version: string }) => [it.name, it.version]),
194198
);
195199
}
196200
}
@@ -200,9 +204,9 @@ export async function discover(path: string, githubRepo?: string, githubToken?:
200204
if (!requiredPackagePresent) continue;
201205
const requiredFileExist =
202206
requiredFiles.length === 0 ||
203-
(await Promise.all(requiredFiles.map((it) => pathExists(join(path, it))))).some(
204-
(it) => it,
205-
);
207+
(
208+
await Promise.all(requiredFiles.map((it) => pathExists(path.join(directory, it))))
209+
).some((it) => it);
206210
if (!requiredFileExist) continue;
207211
const [packageName] = requiredPackages;
208212
if (packageName)

packages/firebase-frameworks/src/firebase-aware.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const mintCookie = async (req: Request, res: Response) => {
3434
} else {
3535
const cookie = await adminAuth
3636
.createSessionCookie(idToken!, { expiresIn: COOKIE_MAX_AGE })
37-
.catch((e: any) => {
37+
.catch((e: Error) => {
3838
console.error(e.message);
3939
});
4040
if (cookie) {
@@ -55,18 +55,19 @@ const handleAuth = async (req: Request, res: Response) => {
5555
if (!__session) return;
5656
const decodedIdToken = await adminAuth
5757
.verifySessionCookie(__session)
58-
.catch((e: any) => console.error(e.message));
58+
.catch((e: Error) => console.error(e.message));
5959
if (!decodedIdToken) return;
6060
const { uid } = decodedIdToken;
6161
let app = firebaseAppsLRU.get(uid);
6262
if (!app) {
6363
const isRevoked = !(await adminAuth
6464
.verifySessionCookie(__session, true)
65-
.catch((e: any) => console.error(e.message)));
65+
.catch((e: Error) => console.error(e.message)));
6666
if (isRevoked) return;
6767
const random = Math.random().toString(36).split(".")[1];
6868
const appName = `authenticated-context:${uid}:${random}`;
6969
// Force JS SDK autoinit with the undefined
70+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7071
app = initializeApp(undefined as any, appName);
7172
firebaseAppsLRU.set(uid, app);
7273
}
@@ -75,7 +76,7 @@ const handleAuth = async (req: Request, res: Response) => {
7576
// TODO(jamesdaniels) get custom claims
7677
const customToken = await adminAuth
7778
.createCustomToken(uid)
78-
.catch((e: any) => console.error(e.message));
79+
.catch((e: Error) => console.error(e.message));
7980
if (!customToken) return;
8081
await signInWithCustomToken(auth, customToken);
8182
}

0 commit comments

Comments
 (0)