Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit b8c93f1

Browse files
authored
Bump to TypeScript 5 and fix bundled TypeScript output (#635)
* Bump to `typescript@5.0.4` and `@microsoft/api-extractor@7.63.3` TypeScript 5 includes lots of goodies, and allows us to remove a bunch of `@ts-expect-error`s. * Set `"moduleResolution": "bundler"` in `tsconfig.json` This loosens some resolution rules in accordance with how bundlers like `esbuild` resolve modules. This also allows us to remove a bunch of `@ts-expect-error`s. * Remove import cycle in `src/plugins/r2` This probably wasn't a problem, but generally it's not great to have cyclic dependencies. For future reference, this was found with `npx madge --circular --extensions ts packages/miniflare/src`.
1 parent f001a44 commit b8c93f1

File tree

13 files changed

+205
-185
lines changed

13 files changed

+205
-185
lines changed

package-lock.json

+180-146
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@ava/typescript": "^4.0.0",
35-
"@microsoft/api-extractor": "^7.33.6",
35+
"@microsoft/api-extractor": "^7.36.3",
3636
"@types/node": "^18.11.9",
3737
"@types/rimraf": "^3.0.2",
3838
"@types/which": "^2.0.1",
@@ -51,7 +51,7 @@
5151
"patch-package": "^6.4.7",
5252
"prettier": "^2.3.2",
5353
"rimraf": "^3.0.2",
54-
"typescript": "^4.8.4",
54+
"typescript": "~5.0.4",
5555
"which": "^2.0.2"
5656
},
5757
"engines": {

packages/miniflare/src/plugins/kv/sites.ts

-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ export async function sitesGatewayGet(
279279
typeof e === "object" &&
280280
e !== null &&
281281
"code" in e &&
282-
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
283282
e.code === "ENOENT"
284283
) {
285284
return;

packages/miniflare/src/plugins/queues/gateway.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import assert from "assert";
22
import crypto from "crypto";
33
import v8 from "v8";
4-
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
5-
// That doesn't matter to `esbuild`, which will apply format conversion.
64
import { stringify } from "devalue";
75
import { Colorize, bold, green, grey, red, reset, yellow } from "kleur/colors";
86
import { z } from "zod";

packages/miniflare/src/plugins/queues/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
2-
// That doesn't matter to `esbuild`, which will apply format conversion.
31
import { stringify } from "devalue";
42
import semiver from "semiver";
53
import { z } from "zod";

packages/miniflare/src/plugins/queues/router.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
2-
// That doesn't matter to `esbuild`, which will apply format conversion.
31
import { parse } from "devalue";
42
import { z } from "zod";
53
import { Headers, Response } from "../../http";

packages/miniflare/src/plugins/r2/gateway.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
NoSuchUpload,
2828
PreconditionFailed,
2929
} from "./errors";
30-
import { R2Object, R2ObjectBody } from "./r2Object";
30+
import { R2Object, R2ObjectBody, R2Objects } from "./r2Object";
3131
import {
3232
MultipartPartRow,
3333
MultipartUploadRow,
@@ -111,24 +111,6 @@ class DigestingStream<
111111
}
112112
}
113113

114-
export interface R2Objects {
115-
// An array of objects matching the list request.
116-
objects: R2Object[];
117-
// If true, indicates there are more results to be retrieved for the current
118-
// list request.
119-
truncated: boolean;
120-
// A token that can be passed to future list calls to resume listing from that
121-
// point.
122-
// Only present if truncated is true.
123-
cursor?: string;
124-
// If a delimiter has been specified, contains all prefixes between the
125-
// specified prefix and the next occurrence of the delimiter. For example, if
126-
// no prefix is provided and the delimiter is "/", "foo/bar/baz" would return
127-
// "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same
128-
// structure and delimiter, "foo/bar" would be returned as a delimited prefix.
129-
delimitedPrefixes: string[];
130-
}
131-
132114
const validate = new Validator();
133115

134116
function generateVersion() {

packages/miniflare/src/plugins/r2/r2Object.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Blob } from "buffer";
22
import { ReadableStream, TransformStream } from "stream/web";
33
import type { R2StringChecksums } from "@cloudflare/workers-types/experimental";
44
import { HEX_REGEXP } from "../../shared";
5-
import { R2Objects } from "./gateway";
65
import { ObjectRow, R2HeadResponse, R2HttpFields, R2Range } from "./schemas";
76

87
export interface EncodedMetadata {
@@ -101,3 +100,21 @@ export class R2ObjectBody extends R2Object {
101100
};
102101
}
103102
}
103+
104+
export interface R2Objects {
105+
// An array of objects matching the list request.
106+
objects: R2Object[];
107+
// If true, indicates there are more results to be retrieved for the current
108+
// list request.
109+
truncated: boolean;
110+
// A token that can be passed to future list calls to resume listing from that
111+
// point.
112+
// Only present if truncated is true.
113+
cursor?: string;
114+
// If a delimiter has been specified, contains all prefixes between the
115+
// specified prefix and the next occurrence of the delimiter. For example, if
116+
// no prefix is provided and the delimiter is "/", "foo/bar/baz" would return
117+
// "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same
118+
// structure and delimiter, "foo/bar" would be returned as a delimited prefix.
119+
delimitedPrefixes: string[];
120+
}

packages/miniflare/src/plugins/r2/router.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
decodePersist,
1111
} from "../shared";
1212
import { InternalError, InvalidMetadata } from "./errors";
13-
import { R2Gateway, R2Objects } from "./gateway";
14-
import { EncodedMetadata, R2Object, R2ObjectBody } from "./r2Object";
13+
import { R2Gateway } from "./gateway";
14+
import { EncodedMetadata, R2Object, R2ObjectBody, R2Objects } from "./r2Object";
1515
import { R2BindingRequestSchema } from "./schemas";
1616

1717
async function decodeMetadata(req: Request) {

packages/miniflare/src/storage/blob/store.ts

-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export class FileBlobStore implements BlobStore {
144144
typeof e === "object" &&
145145
e !== null &&
146146
"code" in e &&
147-
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
148147
e.code === "ENOENT"
149148
) {
150149
return null;
@@ -181,7 +180,6 @@ export class FileBlobStore implements BlobStore {
181180
typeof e === "object" &&
182181
e !== null &&
183182
"code" in e &&
184-
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
185183
e.code === "ENOENT"
186184
) {
187185
return;

packages/miniflare/src/workers/core/entry.worker.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// @ts-expect-error "devalue" is ESM-only, so TypeScript requires us to use the
2-
// `*.mts` extension, or set `"type": "module"` in our `package.json`. We can't
3-
// do the first as ambient types from `@cloudflare/workers-types` don't seem to
4-
// work, and the second would affect all consumers of `miniflare`.
51
import { unflatten } from "devalue";
62
import { CoreBindings, CoreHeaders, LogLevel } from "./constants";
73
import { structuredSerializableRevivers } from "./devalue";

packages/miniflare/src/workers/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"target": "esnext",
55
"lib": ["esnext"],
66
"strict": true,
7-
"moduleResolution": "node16",
7+
"moduleResolution": "bundler",
88
"isolatedModules": true,
99
"noEmit": true,
1010
"types": ["@cloudflare/workers-types/experimental"]

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"target": "esnext",
55
"lib": ["esnext"],
66
"strict": true,
7-
"moduleResolution": "node16",
7+
"moduleResolution": "bundler",
88
"esModuleInterop": true,
99
"isolatedModules": true,
1010
"experimentalDecorators": true,

0 commit comments

Comments
 (0)