Skip to content

Commit

Permalink
Bump to TypeScript 5 and fix bundled TypeScript output (#635)
Browse files Browse the repository at this point in the history
* Bump to `[email protected]` and `@microsoft/[email protected]`

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`.
  • Loading branch information
mrbbot committed Nov 1, 2023
1 parent 78092bd commit 256af56
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 36 deletions.
1 change: 0 additions & 1 deletion packages/miniflare/src/plugins/kv/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export async function sitesGatewayGet(
typeof e === "object" &&
e !== null &&
"code" in e &&
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
e.code === "ENOENT"
) {
return;
Expand Down
2 changes: 0 additions & 2 deletions packages/miniflare/src/plugins/queues/gateway.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import assert from "assert";
import crypto from "crypto";
import v8 from "v8";
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
// That doesn't matter to `esbuild`, which will apply format conversion.
import { stringify } from "devalue";
import { Colorize, bold, green, grey, red, reset, yellow } from "kleur/colors";
import { z } from "zod";
Expand Down
2 changes: 0 additions & 2 deletions packages/miniflare/src/plugins/queues/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
// That doesn't matter to `esbuild`, which will apply format conversion.
import { stringify } from "devalue";
import semiver from "semiver";
import { z } from "zod";
Expand Down
2 changes: 0 additions & 2 deletions packages/miniflare/src/plugins/queues/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-expect-error "devalue" is ESM-only, but we're bundling for CommonJS here.
// That doesn't matter to `esbuild`, which will apply format conversion.
import { parse } from "devalue";
import { z } from "zod";
import { Headers, Response } from "../../http";
Expand Down
20 changes: 1 addition & 19 deletions packages/miniflare/src/plugins/r2/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
NoSuchUpload,
PreconditionFailed,
} from "./errors";
import { R2Object, R2ObjectBody } from "./r2Object";
import { R2Object, R2ObjectBody, R2Objects } from "./r2Object";
import {
MultipartPartRow,
MultipartUploadRow,
Expand Down Expand Up @@ -111,24 +111,6 @@ class DigestingStream<
}
}

export interface R2Objects {
// An array of objects matching the list request.
objects: R2Object[];
// If true, indicates there are more results to be retrieved for the current
// list request.
truncated: boolean;
// A token that can be passed to future list calls to resume listing from that
// point.
// Only present if truncated is true.
cursor?: string;
// If a delimiter has been specified, contains all prefixes between the
// specified prefix and the next occurrence of the delimiter. For example, if
// no prefix is provided and the delimiter is "/", "foo/bar/baz" would return
// "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same
// structure and delimiter, "foo/bar" would be returned as a delimited prefix.
delimitedPrefixes: string[];
}

const validate = new Validator();

function generateVersion() {
Expand Down
19 changes: 18 additions & 1 deletion packages/miniflare/src/plugins/r2/r2Object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Blob } from "buffer";
import { ReadableStream, TransformStream } from "stream/web";
import type { R2StringChecksums } from "@cloudflare/workers-types/experimental";
import { HEX_REGEXP } from "../../shared";
import { R2Objects } from "./gateway";
import { ObjectRow, R2HeadResponse, R2HttpFields, R2Range } from "./schemas";

export interface EncodedMetadata {
Expand Down Expand Up @@ -101,3 +100,21 @@ export class R2ObjectBody extends R2Object {
};
}
}

export interface R2Objects {
// An array of objects matching the list request.
objects: R2Object[];
// If true, indicates there are more results to be retrieved for the current
// list request.
truncated: boolean;
// A token that can be passed to future list calls to resume listing from that
// point.
// Only present if truncated is true.
cursor?: string;
// If a delimiter has been specified, contains all prefixes between the
// specified prefix and the next occurrence of the delimiter. For example, if
// no prefix is provided and the delimiter is "/", "foo/bar/baz" would return
// "foo" as a delimited prefix. If "foo/" was passed as a prefix with the same
// structure and delimiter, "foo/bar" would be returned as a delimited prefix.
delimitedPrefixes: string[];
}
4 changes: 2 additions & 2 deletions packages/miniflare/src/plugins/r2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
decodePersist,
} from "../shared";
import { InternalError, InvalidMetadata } from "./errors";
import { R2Gateway, R2Objects } from "./gateway";
import { EncodedMetadata, R2Object, R2ObjectBody } from "./r2Object";
import { R2Gateway } from "./gateway";
import { EncodedMetadata, R2Object, R2ObjectBody, R2Objects } from "./r2Object";
import { R2BindingRequestSchema } from "./schemas";

async function decodeMetadata(req: Request) {
Expand Down
2 changes: 0 additions & 2 deletions packages/miniflare/src/storage/blob/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export class FileBlobStore implements BlobStore {
typeof e === "object" &&
e !== null &&
"code" in e &&
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
e.code === "ENOENT"
) {
return null;
Expand Down Expand Up @@ -181,7 +180,6 @@ export class FileBlobStore implements BlobStore {
typeof e === "object" &&
e !== null &&
"code" in e &&
// @ts-expect-error `e.code` should be `unknown`, fixed in TypeScript 4.9
e.code === "ENOENT"
) {
return;
Expand Down
4 changes: 0 additions & 4 deletions packages/miniflare/src/workers/core/entry.worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// @ts-expect-error "devalue" is ESM-only, so TypeScript requires us to use the
// `*.mts` extension, or set `"type": "module"` in our `package.json`. We can't
// do the first as ambient types from `@cloudflare/workers-types` don't seem to
// work, and the second would affect all consumers of `miniflare`.
import { unflatten } from "devalue";
import { CoreBindings, CoreHeaders, LogLevel } from "./constants";
import { structuredSerializableRevivers } from "./devalue";
Expand Down
2 changes: 1 addition & 1 deletion packages/miniflare/src/workers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target": "esnext",
"lib": ["esnext"],
"strict": true,
"moduleResolution": "node16",
"moduleResolution": "bundler",
"isolatedModules": true,
"noEmit": true,
"types": ["@cloudflare/workers-types/experimental"]
Expand Down

0 comments on commit 256af56

Please sign in to comment.