Skip to content

Commit bcaaec6

Browse files
authored
chore: improve tsconfig strictness and ci workflows (#62)
1 parent c995640 commit bcaaec6

File tree

12 files changed

+114
-46
lines changed

12 files changed

+114
-46
lines changed

.github/workflows/checks.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
name: Code checks
2+
23
on:
34
push:
45
branches: [main]
56
pull_request:
67
branches: [main]
8+
79
jobs:
8-
test:
9-
timeout-minutes: 60
10+
checks:
11+
name: ${{ matrix.script }}
1012
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
script: ["prettier:check", "lint:check", "ts:check", "test"]
1117
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-node@v4
18+
- name: Check out code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v4
1423
with:
15-
node-version: lts/*
24+
version: 9
25+
26+
- name: Setup Node.js environment
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: "pnpm"
31+
1632
- name: Install dependencies
17-
run: npm install -g pnpm && pnpm install
18-
- name: Run code checks
19-
run: pnpm code:checks
33+
run: pnpm install --frozen-lockfile
34+
35+
- name: ${{ matrix.script }}
36+
run: pnpm run ${{ matrix.script }}

.github/workflows/playwright.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
name: Playwright Tests
2+
23
on:
34
push:
45
branches: [main]
56
pull_request:
67
branches: [main]
8+
79
jobs:
810
test:
9-
timeout-minutes: 60
11+
timeout-minutes: 30
1012
runs-on: ubuntu-latest
1113
steps:
12-
- uses: actions/checkout@v4
13-
- uses: actions/setup-node@v4
14+
- name: Check out code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup pnpm
18+
uses: pnpm/action-setup@v4
1419
with:
15-
node-version: lts/*
20+
version: 9
21+
22+
- name: Setup Node.js environment
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 20
26+
cache: "pnpm"
27+
1628
- name: Install dependencies
17-
run: npm install -g pnpm && pnpm install
18-
- name: build all workers
29+
run: |
30+
pnpm install --frozen-lockfile
31+
pnpm run install-playwright
32+
33+
- name: Build all workers
1934
run: pnpm -r build:worker
20-
- name: Install Playwright browsers
21-
run: pnpm run install-playwright
35+
2236
- name: Run playwright tests
2337
run: pnpm e2e
38+
2439
- name: Run playwright dev tests
2540
run: pnpm e2e:dev

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"prettier:fix": "prettier --write .",
1313
"lint:check": "pnpm -r lint:check",
1414
"lint:fix": "pnpm -r lint:fix",
15-
"code:checks": "pnpm lint:check && pnpm lint:check",
15+
"ts:check": "pnpm -r ts:check",
16+
"test": "pnpm -r test",
17+
"code:checks": "pnpm prettier:check && pnpm lint:check && pnpm ts:check",
1618
"code:fixes": "pnpm prettier:fix && pnpm lint:fix",
1719
"postinstall": "pnpm --filter cloudflare build",
1820
"install-playwright": "playwright install --with-deps",

packages/cloudflare/env.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
declare global {
2+
namespace NodeJS {
3+
interface ProcessEnv {
4+
ASSETS: Fetcher;
5+
__NEXT_PRIVATE_STANDALONE_CONFIG?: string;
6+
SKIP_NEXT_APP_BUILD?: string;
7+
[key: string]: string | Fetcher;
8+
}
9+
}
10+
}
11+
12+
export {};

packages/cloudflare/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build:watch": "tsup --watch src",
88
"lint:check": "eslint",
99
"lint:fix": "eslint --fix",
10+
"ts:check": "tsc --noEmit",
1011
"test": "vitest --run",
1112
"test:watch": "vitest"
1213
},
@@ -41,6 +42,7 @@
4142
"devDependencies": {
4243
"@cloudflare/workers-types": "catalog:",
4344
"@eslint/js": "catalog:",
45+
"@tsconfig/strictest": "catalog:",
4446
"@types/node": "catalog:",
4547
"esbuild": "catalog:",
4648
"eslint": "catalog:",

packages/cloudflare/src/api/get-cloudflare-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type CloudflareContext<
1616
/**
1717
* the request's [cf properties](https://developers.cloudflare.com/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties)
1818
*/
19-
cf: CfProperties;
19+
cf: CfProperties | undefined;
2020
/**
2121
* the current [execution context](https://developers.cloudflare.com/workers/runtime-apis/context)
2222
*/

packages/cloudflare/src/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function getInstallChunkDeclaration(sourceFile: ts.SourceFile): ts.VariableDecla
5555

5656
// the function we're looking for accesses its parameter three times, and it
5757
// accesses its `modules`, `ids` and `runtime` properties (in this order)
58-
const parameterName = functionParameters[0].getText();
58+
const parameterName = functionParameters[0]!.getText();
5959
const functionParameterAccessedProperties = arrowFunctionBodyBlock
6060
.getDescendantsOfKind(ts.SyntaxKind.PropertyAccessExpression)
6161
.filter(

packages/cloudflare/src/cli/build/patches/to-investigate/wrangler-deps.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs, { writeFileSync } from "node:fs";
1+
import { readFileSync, statSync, writeFileSync } from "node:fs";
22
import { Config } from "../../../config";
33
import path from "node:path";
44

@@ -15,11 +15,12 @@ export function patchWranglerDeps(config: Config) {
1515
// "critters" = "./.next/standalone/node_modules/cf/templates/shims/empty.ts"
1616
const pagesRuntimeFile = path.join(distPath, "compiled", "next-server", "pages.runtime.prod.js");
1717

18-
const patchedPagesRuntime = fs
19-
.readFileSync(pagesRuntimeFile, "utf-8")
20-
.replace(`e.exports=require("critters")`, `e.exports={}`);
18+
const patchedPagesRuntime = readFileSync(pagesRuntimeFile, "utf-8").replace(
19+
`e.exports=require("critters")`,
20+
`e.exports={}`
21+
);
2122

22-
fs.writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
23+
writeFileSync(pagesRuntimeFile, patchedPagesRuntime);
2324

2425
// Patch .next/standalone/node_modules/next/dist/server/lib/trace/tracer.js
2526
//
@@ -33,11 +34,12 @@ export function patchWranglerDeps(config: Config) {
3334
// #"@opentelemetry/api" = "./.next/standalone/node_modules/cf/templates/shims/throw.ts"
3435
const tracerFile = path.join(distPath, "server", "lib", "trace", "tracer.js");
3536

36-
const pacthedTracer = fs
37-
.readFileSync(tracerFile, "utf-8")
38-
.replaceAll(/\w+\s*=\s*require\([^/]*opentelemetry.*\)/g, `throw new Error("@opentelemetry/api")`);
37+
const patchedTracer = readFileSync(tracerFile, "utf-8").replaceAll(
38+
/\w+\s*=\s*require\([^/]*opentelemetry.*\)/g,
39+
`throw new Error("@opentelemetry/api")`
40+
);
3941

40-
writeFileSync(tracerFile, pacthedTracer);
42+
writeFileSync(tracerFile, patchedTracer);
4143
}
4244

4345
/**
@@ -56,7 +58,7 @@ function getDistPath(config: Config): string {
5658
for (const root of [config.paths.standaloneApp, config.paths.standaloneRoot]) {
5759
try {
5860
const distPath = path.join(root, "node_modules", "next", "dist");
59-
if (fs.statSync(distPath).isDirectory()) return distPath;
61+
if (statSync(distPath).isDirectory()) return distPath;
6062
} catch {
6163
/* empty */
6264
}

packages/cloudflare/src/cli/templates/worker.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { ExportedHandler, Fetcher } from "@cloudflare/workers-types";
12
import { NodeNextRequest, NodeNextResponse } from "next/dist/server/base-http/node";
23
import { AsyncLocalStorage } from "node:async_hooks";
3-
import { type CloudflareContext } from "../../api";
4+
import type { CloudflareContext } from "../../api";
45
import type { IncomingMessage } from "node:http";
56
import { MockedResponse } from "next/dist/server/lib/mock-request";
67
import type { NextConfig } from "next";
7-
import { type NodeRequestHandler } from "next/dist/server/next-server";
8+
import type { NodeRequestHandler } from "next/dist/server/next-server";
89
import Stream from "node:stream";
910

1011
const NON_BODY_RESPONSES = new Set([101, 204, 205, 304]);
@@ -30,8 +31,7 @@ const nextConfig: NextConfig = JSON.parse(process.env.__NEXT_PRIVATE_STANDALONE_
3031
let requestHandler: NodeRequestHandler | null = null;
3132

3233
export default {
33-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34-
async fetch(request: Request & { cf: IncomingRequestCfProperties }, env: any, ctx: any) {
34+
async fetch(request, env, ctx) {
3535
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, async () => {
3636
if (requestHandler == null) {
3737
globalThis.process.env = { ...globalThis.process.env, ...env };
@@ -42,7 +42,7 @@ export default {
4242
.default as typeof import("next/dist/server/next-server").default;
4343

4444
requestHandler = new NextNodeServer({
45-
conf: { ...nextConfig, env },
45+
conf: nextConfig,
4646
customServer: false,
4747
dev: false,
4848
dir: "",
@@ -58,18 +58,17 @@ export default {
5858
if (imageUrl.startsWith("/")) {
5959
return env.ASSETS.fetch(new URL(imageUrl, request.url));
6060
}
61-
// @ts-ignore
62-
return fetch(imageUrl, { cf: { cacheEverything: true } } as unknown);
61+
return fetch(imageUrl, { cf: { cacheEverything: true } });
6362
}
6463

6564
const { req, res, webResponse } = getWrappedStreams(request, ctx);
6665

67-
ctx.waitUntil(requestHandler!(new NodeNextRequest(req), new NodeNextResponse(res)));
66+
ctx.waitUntil(Promise.resolve(requestHandler(new NodeNextRequest(req), new NodeNextResponse(res))));
6867

6968
return await webResponse();
7069
});
7170
},
72-
};
71+
} as ExportedHandler<{ ASSETS: Fetcher }>;
7372

7473
function getWrappedStreams(request: Request, ctx: ExecutionContext) {
7574
const url = new URL(request.url);

packages/cloudflare/tsconfig.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "@tsconfig/strictest/tsconfig.json",
24
"compilerOptions": {
35
"target": "ESNext",
46
"module": "ESNext",
7+
"lib": ["ESNext"],
58
"moduleResolution": "Bundler",
6-
"esModuleInterop": true,
9+
10+
"types": ["@cloudflare/workers-types"],
11+
712
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"skipLibCheck": true,
10-
"types": ["@cloudflare/workers-types"]
11-
}
13+
"noImplicitReturns": false,
14+
"exactOptionalPropertyTypes": false
15+
},
16+
"include": ["**/*.ts"],
17+
"exclude": ["dist"]
1218
}

0 commit comments

Comments
 (0)