Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Oct 25, 2024
1 parent 98dc636 commit d0a6035
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 137 deletions.
7 changes: 0 additions & 7 deletions fixtures/node-app-pages/functions/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import path from "path";
import Stripe from "stripe";
// `@cloudflare/workers-types` conflicts with `@types/node`, so we can't include
// it in the `tsconfig.json` `types` array
import type { Response as WorkerResponse } from "@cloudflare/workers-types";

declare global {
const Response: typeof WorkerResponse;
}

export const onRequest = () => {
// make sure path actually works
Expand Down
3 changes: 2 additions & 1 deletion fixtures/node-app-pages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"target": "ES2020",
"module": "CommonJS",
"lib": ["ES2020"],
"types": [],
"types": ["@cloudflare/workers-types/experimental"],
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"noEmit": true
}
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/types/streams.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module "stream/web" {
interface ReadableStreamBYOBRequest {
readonly view: Uint8Array | null;
readonly view: ArrayBufferView | null;
respond(bytesWritten: number): void;
respondWithNewView(view: ArrayBufferView): void;
}
Expand All @@ -15,7 +15,7 @@ declare module "stream/web" {
cancel(reason?: any): Promise<void>;
read<T extends ArrayBufferView>(
view: T
): Promise<ReadableStreamDefaultReadResult<T>>;
): Promise<ReadableStreamDefaultReader<T>>;
releaseLock(): void;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/pages-shared/environment-polyfills/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { polyfill } from ".";

export default async () => {
const { HTMLRewriter } = await import("@miniflare/html-rewriter");
// @ts-expect-error We should properly clean up the Miniflare v2 v3 mixing in this package at some point
const mf = await import("miniflare");
polyfill({
fetch: mf.fetch,
Expand Down
19 changes: 1 addition & 18 deletions packages/pages-shared/environment-polyfills/types.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
import {
Headers as WorkerHeaders,
HTMLRewriter as WorkerHTMLRewriter,
Request as WorkerRequest,
Response as WorkerResponse,
} from "@cloudflare/workers-types/experimental";
import type {
CacheStorage as WorkerCacheStorage,
fetch as workerFetch,
ReadableStream as WorkerReadableStream,
} from "@cloudflare/workers-types/experimental";

declare global {
const fetch: typeof workerFetch;
class Headers extends WorkerHeaders {}
class Request extends WorkerRequest {}
class Response extends WorkerResponse {}

// Not polyfilled
type ReadableStream = WorkerReadableStream;
type CacheStorage = WorkerCacheStorage;
class HTMLRewriter extends WorkerHTMLRewriter {}
}
import type { fetch as workerFetch } from "@cloudflare/workers-types/experimental";

export type PolyfilledRuntimeEnvironment = {
fetch: typeof fetch;
Expand Down
3 changes: 0 additions & 3 deletions packages/pages-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
"test": "vitest run",
"test:ci": "vitest run"
},
"dependencies": {
"miniflare": "workspace:*"
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20241022.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/pages-shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@cloudflare/workers-tsconfig/tsconfig.json",
"compilerOptions": {
"module": "CommonJS"
"module": "CommonJS",
"types": ["@cloudflare/workers-types/experimental"]
},
"include": ["**/*.ts"],
"exclude": []
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/__tests__/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ vi.mock("undici", async (importOriginal) => {
* - MSW makes it difficult to use custom interceptors, and _really_ wants you to use globalThis.fetch. In particular, it doesn't support intercepting undici.fetch
* Because Wrangler supports Node v16, we have to use undici's fetch directly rather than using globalThis.fetch. We'd also like to intercept requests with MSW
* Therefore, we mock undici in tests to replace the imported fetch with globalThis.fetch (which MSW will replace with a mocked version—hence the getter, so that we always get the up to date mocked version)
* We're able to delegate to globalThis.fetch in our tests because we run our test in Node v16
* We're able to delegate to globalThis.fetch in our tests because we run our test in Node v18
*/
get fetch() {
// @ts-expect-error Here be dragons (see above)
// Here be dragons (see above)
return globalThis.fetch;
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class ConfigController extends Controller<ConfigControllerEventMap> {
const fileConfig = readConfig(input.config, {
env: input.env,
"dispatch-namespace": undefined,
"legacy-env": !input.legacy?.enableServiceEnvironments ?? true,
"legacy-env": !input.legacy?.enableServiceEnvironments,
remote: input.dev?.remote,
upstreamProtocol:
input.dev?.origin?.secure === undefined
Expand Down
4 changes: 0 additions & 4 deletions packages/wrangler/src/tsconfig-sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ const _handler: ExportedHandler = {};
// @ts-expect-error `@cloudflare/workers-types` should NOT be included
new HTMLRewriter();

// @ts-expect-error `fetch` should NOT be included as our minimum supported
// Node version is 16.13.0 which does not include `fetch` on the global scope
void fetch("http://localhost/");

export {};
Loading

0 comments on commit d0a6035

Please sign in to comment.