wrangler 2.6.1 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/bin/wrangler.js +9 -1
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +12 -10
  4. package/src/__tests__/api-dev.test.ts +65 -36
  5. package/src/__tests__/api-devregistry.test.js +14 -6
  6. package/src/__tests__/configuration.test.ts +2 -31
  7. package/src/__tests__/{d1.test.ts → d1/d1.test.ts} +48 -5
  8. package/src/__tests__/d1/splitter.test.ts +255 -0
  9. package/src/__tests__/delete.test.ts +5 -2
  10. package/src/__tests__/deployments.test.ts +20 -6
  11. package/src/__tests__/dev.test.tsx +52 -19
  12. package/src/__tests__/generate.test.ts +7 -4
  13. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  14. package/src/__tests__/helpers/mock-cfetch.ts +2 -57
  15. package/src/__tests__/helpers/mock-dialogs.ts +70 -86
  16. package/src/__tests__/helpers/mock-oauth-flow.ts +64 -49
  17. package/src/__tests__/helpers/mock-process.ts +8 -13
  18. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  19. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  20. package/src/__tests__/index.test.ts +46 -42
  21. package/src/__tests__/init.test.ts +782 -522
  22. package/src/__tests__/jest.setup.ts +20 -24
  23. package/src/__tests__/kv.test.ts +286 -173
  24. package/src/__tests__/logout.test.ts +1 -1
  25. package/src/__tests__/metrics.test.ts +5 -7
  26. package/src/__tests__/middleware.scheduled.test.ts +40 -30
  27. package/src/__tests__/middleware.test.ts +144 -120
  28. package/src/__tests__/pages.test.ts +1618 -1161
  29. package/src/__tests__/publish.test.ts +174 -125
  30. package/src/__tests__/r2.test.ts +2 -2
  31. package/src/__tests__/secret.test.ts +183 -126
  32. package/src/__tests__/tail.test.ts +6 -0
  33. package/src/__tests__/tsconfig-sanity.ts +12 -0
  34. package/src/__tests__/tsconfig.json +8 -0
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  36. package/src/__tests__/whoami.test.tsx +1 -96
  37. package/src/api/dev.ts +78 -41
  38. package/src/api/index.ts +1 -1
  39. package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  40. package/src/cfetch/index.ts +0 -2
  41. package/src/cfetch/internal.ts +16 -18
  42. package/src/cli.ts +2 -2
  43. package/src/config/index.ts +2 -1
  44. package/src/config/validation.ts +1 -2
  45. package/src/create-worker-upload-form.ts +2 -2
  46. package/src/d1/{delete.tsx → delete.ts} +0 -0
  47. package/src/d1/execute.tsx +8 -37
  48. package/src/d1/migrations/apply.tsx +32 -19
  49. package/src/d1/migrations/{index.tsx → index.ts} +0 -0
  50. package/src/d1/splitter.ts +161 -0
  51. package/src/d1/{types.tsx → types.ts} +0 -0
  52. package/src/delete.ts +3 -8
  53. package/src/deployments.ts +6 -0
  54. package/src/deprecated/index.ts +2 -295
  55. package/src/dev/dev.tsx +2 -2
  56. package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  57. package/src/dev/local.tsx +16 -4
  58. package/src/dev/remote.tsx +28 -1
  59. package/src/dev/start-server.ts +19 -11
  60. package/src/dev/use-esbuild.ts +1 -1
  61. package/src/{dev-registry.tsx → dev-registry.ts} +0 -0
  62. package/src/dev.tsx +35 -11
  63. package/src/dialogs.ts +136 -0
  64. package/src/dispatch-namespace.ts +1 -1
  65. package/src/docs/index.ts +97 -0
  66. package/src/environment-variables/factory.ts +88 -0
  67. package/src/environment-variables/misc-variables.ts +30 -0
  68. package/src/generate/index.ts +300 -0
  69. package/src/{index.tsx → index.ts} +16 -10
  70. package/src/init.ts +106 -60
  71. package/src/jest.d.ts +4 -0
  72. package/src/logger.ts +15 -3
  73. package/src/metrics/metrics-config.ts +1 -1
  74. package/src/metrics/send-event.ts +2 -1
  75. package/src/miniflare-cli/assets.ts +4 -0
  76. package/src/miniflare-cli/index.ts +1 -5
  77. package/src/miniflare-cli/tsconfig.json +9 -0
  78. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  79. package/src/miniflare-cli/types.ts +11 -0
  80. package/src/pages/{build.tsx → build.ts} +0 -0
  81. package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +0 -0
  82. package/src/pages/{dev.tsx → dev.ts} +53 -55
  83. package/src/pages/functions/buildWorker.ts +1 -1
  84. package/src/pages/functions/tsconfig.json +8 -0
  85. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  86. package/src/pages/{functions.tsx → functions.ts} +0 -0
  87. package/src/pages/{hash.tsx → hash.ts} +0 -0
  88. package/src/pages/{index.tsx → index.ts} +0 -0
  89. package/src/pages/projects.tsx +3 -5
  90. package/src/pages/publish.tsx +16 -5
  91. package/src/pages/upload.tsx +27 -6
  92. package/src/publish/publish.ts +9 -7
  93. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +1 -1
  94. package/src/secret/index.ts +1 -1
  95. package/src/{sites.tsx → sites.ts} +0 -0
  96. package/src/tail/index.ts +2 -3
  97. package/src/tsconfig-sanity.ts +16 -0
  98. package/src/user/access.ts +0 -1
  99. package/src/user/auth-variables.ts +113 -0
  100. package/src/user/choose-account.tsx +1 -31
  101. package/src/user/index.ts +0 -1
  102. package/src/user/{user.tsx → user.ts} +107 -73
  103. package/src/{whoami.tsx → whoami.ts} +37 -71
  104. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  105. package/templates/__tests__/tsconfig.json +8 -0
  106. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  107. package/templates/d1-beta-facade.js +36 -0
  108. package/templates/facade.d.ts +14 -0
  109. package/templates/first-party-worker-module-facade.ts +4 -3
  110. package/templates/format-dev-errors.ts +7 -6
  111. package/templates/init-tests/test-jest-new-worker.js +3 -5
  112. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  113. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  114. package/templates/middleware/loader-modules.ts +0 -2
  115. package/templates/middleware/loader-sw.ts +6 -0
  116. package/templates/pages-dev-pipeline.ts +4 -1
  117. package/templates/pages-shim.ts +4 -1
  118. package/templates/pages-template-plugin.ts +12 -7
  119. package/templates/serve-static-assets.ts +16 -14
  120. package/templates/tsconfig-sanity.ts +11 -0
  121. package/templates/tsconfig.init.json +106 -0
  122. package/templates/tsconfig.json +5 -103
  123. package/templates/tsconfig.tsbuildinfo +1 -0
  124. package/wrangler-dist/cli.d.ts +58 -60
  125. package/wrangler-dist/cli.js +34498 -55459
  126. package/wrangler-dist/wasm-sync.wasm +0 -0
  127. package/src/__tests__/dialogs.test.tsx +0 -40
  128. package/src/dialogs.tsx +0 -168
  129. package/src/environment-variables.ts +0 -50
  130. package/src/user/env-vars.ts +0 -46
@@ -1,6 +1,4 @@
1
- import { Text, render } from "ink";
2
- import Table from "ink-table";
3
- import React, { Fragment } from "react";
1
+ import chalk from "chalk";
4
2
  import { fetchListResult, fetchResult } from "./cfetch";
5
3
  import { logger } from "./logger";
6
4
  import { getAPIToken, getAuthFromEnv, getScopes } from "./user";
@@ -8,82 +6,50 @@ import { getAPIToken, getAuthFromEnv, getScopes } from "./user";
8
6
  export async function whoami() {
9
7
  logger.log("Getting User settings...");
10
8
  const user = await getUserInfo();
11
- const { unmount } = render(<WhoAmI user={user}></WhoAmI>);
12
- unmount();
13
- }
14
-
15
- export function WhoAmI({ user }: { user: UserInfo | undefined }) {
16
- return user ? (
17
- <>
18
- <Email tokenType={user.authType} email={user.email}></Email>
19
- <Accounts accounts={user.accounts}></Accounts>
20
- <Permissions
21
- tokenType={user.authType}
22
- tokenPermissions={user.tokenPermissions}
23
- />
24
- </>
25
- ) : (
26
- <Text>You are not authenticated. Please run `wrangler login`.</Text>
27
- );
28
- }
9
+ if (user === undefined) {
10
+ return void logger.log(
11
+ "You are not authenticated. Please run `wrangler login`."
12
+ );
13
+ }
29
14
 
30
- function Email(props: { tokenType: string; email: string | undefined }) {
31
- return props.email === undefined ? (
32
- <Text>
33
- 👋 You are logged in with an {props.tokenType}. Unable to retrieve email
34
- for this user. Are you missing the `User-&gt;User Details-&gt;Read`
35
- permission?
36
- </Text>
37
- ) : (
38
- <Text>
39
- 👋 You are logged in with an {props.tokenType}, associated with the email
40
- &apos;{props.email}&apos;!
41
- </Text>
15
+ if (user.email !== undefined) {
16
+ logger.log(
17
+ `👋 You are logged in with an ${
18
+ user.authType
19
+ }, associated with the email ${chalk.blue(user.email)}!`
20
+ );
21
+ } else {
22
+ logger.log(
23
+ `👋 You are logged in with an ${user.authType}. Unable to retrieve email for this user. Are you missing the \`User->User Details->Read\` permission?`
24
+ );
25
+ }
26
+ logger.table(
27
+ user.accounts.map((account) => ({
28
+ "Account Name": account.name,
29
+ "Account ID": account.id,
30
+ }))
42
31
  );
43
- }
44
-
45
- function Accounts(props: { accounts: AccountInfo[] }) {
46
- const accounts = props.accounts.map((account) => ({
47
- "Account Name": account.name,
48
- "Account ID": account.id,
49
- }));
50
- return <Table data={accounts}></Table>;
51
- }
52
-
53
- function Permissions(props: {
54
- tokenPermissions: string[] | undefined;
55
- tokenType: string;
56
- }) {
57
32
  const permissions =
58
- props.tokenPermissions?.map((scope) => scope.split(":")) || [];
59
- return props.tokenType === "OAuth Token" ? (
60
- props.tokenPermissions ? (
61
- <>
62
- <Text>
63
- 🔓 Token Permissions: If scopes are missing, you may need to logout
64
- and re-login.
65
- </Text>
66
- <Text>Scope (Access)</Text>
67
- {permissions.map(([scope, access], index) => (
68
- <Fragment key={`${scope}${index}`}>
69
- <Text>
70
- - {scope} {access && `(${access})`}
71
- </Text>
72
- </Fragment>
73
- ))}
74
- </>
75
- ) : null
76
- ) : (
77
- <Text>
78
- 🔓 To see token permissions visit
79
- https://dash.cloudflare.com/profile/api-tokens
80
- </Text>
33
+ user.tokenPermissions?.map((scope) => scope.split(":")) ?? [];
34
+
35
+ if (user.authType !== "OAuth Token") {
36
+ return void logger.log(
37
+ `🔓 To see token permissions visit https://dash.cloudflare.com/profile/api-tokens`
38
+ );
39
+ }
40
+ logger.log(
41
+ `🔓 Token Permissions: If scopes are missing, you may need to logout and re-login.`
81
42
  );
43
+ logger.log(`Scope (Access)`);
44
+ for (const [scope, access] of permissions) {
45
+ logger.log(`- ${scope} ${access ? `(${access})` : ``}`);
46
+ }
82
47
  }
83
48
 
49
+ type AuthType = "Global API Key" | "API Token" | "OAuth Token";
84
50
  export interface UserInfo {
85
51
  apiToken: string;
86
- authType: string;
52
+ authType: AuthType;
87
53
  email: string | undefined;
88
54
  accounts: AccountInfo[];
89
55
  tokenPermissions: string[] | undefined;
@@ -0,0 +1,12 @@
1
+ // `@types/node` should be included
2
+ Buffer.from("test");
3
+
4
+ // `@types/jest` should be included
5
+ test("test");
6
+
7
+ // @ts-expect-error `@cloudflare/workers-types` should NOT be included
8
+ const _handler: ExportedHandler = {};
9
+ // @ts-expect-error `@cloudflare/workers-types` should NOT be included
10
+ new HTMLRewriter();
11
+
12
+ export {};
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["node", "jest"]
5
+ },
6
+ "include": ["**/*.ts"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../../../node_modules/typescript/lib/lib.es5.d.ts","../../../../node_modules/typescript/lib/lib.es2015.d.ts","../../../../node_modules/typescript/lib/lib.es2016.d.ts","../../../../node_modules/typescript/lib/lib.es2017.d.ts","../../../../node_modules/typescript/lib/lib.es2018.d.ts","../../../../node_modules/typescript/lib/lib.es2019.d.ts","../../../../node_modules/typescript/lib/lib.es2020.d.ts","../../../../node_modules/typescript/lib/lib.es2021.d.ts","../../../../node_modules/typescript/lib/lib.es2022.d.ts","../../../../node_modules/typescript/lib/lib.esnext.d.ts","../../../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../pages-dev-util.ts","./pages-dev-util.test.ts","./tsconfig-sanity.ts","../../../../node_modules/@types/node/assert.d.ts","../../../../node_modules/@types/node/assert/strict.d.ts","../../../../node_modules/@types/node/globals.d.ts","../../../../node_modules/@types/node/async_hooks.d.ts","../../../../node_modules/@types/node/buffer.d.ts","../../../../node_modules/@types/node/child_process.d.ts","../../../../node_modules/@types/node/cluster.d.ts","../../../../node_modules/@types/node/console.d.ts","../../../../node_modules/@types/node/constants.d.ts","../../../../node_modules/@types/node/crypto.d.ts","../../../../node_modules/@types/node/dgram.d.ts","../../../../node_modules/@types/node/diagnostics_channel.d.ts","../../../../node_modules/@types/node/dns.d.ts","../../../../node_modules/@types/node/dns/promises.d.ts","../../../../node_modules/@types/node/domain.d.ts","../../../../node_modules/@types/node/events.d.ts","../../../../node_modules/@types/node/fs.d.ts","../../../../node_modules/@types/node/fs/promises.d.ts","../../../../node_modules/@types/node/http.d.ts","../../../../node_modules/@types/node/http2.d.ts","../../../../node_modules/@types/node/https.d.ts","../../../../node_modules/@types/node/inspector.d.ts","../../../../node_modules/@types/node/module.d.ts","../../../../node_modules/@types/node/net.d.ts","../../../../node_modules/@types/node/os.d.ts","../../../../node_modules/@types/node/path.d.ts","../../../../node_modules/@types/node/perf_hooks.d.ts","../../../../node_modules/@types/node/process.d.ts","../../../../node_modules/@types/node/punycode.d.ts","../../../../node_modules/@types/node/querystring.d.ts","../../../../node_modules/@types/node/readline.d.ts","../../../../node_modules/@types/node/repl.d.ts","../../../../node_modules/@types/node/stream.d.ts","../../../../node_modules/@types/node/stream/promises.d.ts","../../../../node_modules/@types/node/stream/consumers.d.ts","../../../../node_modules/@types/node/stream/web.d.ts","../../../../node_modules/@types/node/string_decoder.d.ts","../../../../node_modules/@types/node/timers.d.ts","../../../../node_modules/@types/node/timers/promises.d.ts","../../../../node_modules/@types/node/tls.d.ts","../../../../node_modules/@types/node/trace_events.d.ts","../../../../node_modules/@types/node/tty.d.ts","../../../../node_modules/@types/node/url.d.ts","../../../../node_modules/@types/node/util.d.ts","../../../../node_modules/@types/node/v8.d.ts","../../../../node_modules/@types/node/vm.d.ts","../../../../node_modules/@types/node/wasi.d.ts","../../../../node_modules/@types/node/worker_threads.d.ts","../../../../node_modules/@types/node/zlib.d.ts","../../../../node_modules/@types/node/globals.global.d.ts","../../../../node_modules/@types/node/index.d.ts","../../../../node_modules/@types/jest/node_modules/chalk/index.d.ts","../../../../node_modules/@sinclair/typebox/typebox.d.ts","../../../../node_modules/@jest/schemas/build/index.d.ts","../../../../node_modules/@types/jest/node_modules/pretty-format/build/index.d.ts","../../../../node_modules/@types/jest/node_modules/jest-diff/build/index.d.ts","../../../../node_modules/@types/jest/node_modules/jest-matcher-utils/build/index.d.ts","../../../../node_modules/@types/jest/index.d.ts"],"fileInfos":[{"version":"f20c05dbfe50a208301d2a1da37b9931bce0466eb5a1f4fe240971b4ecc82b67","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9","746d62152361558ea6d6115cf0da4dd10ede041d14882ede3568bce5dc4b4f1f","d11a03592451da2d1065e09e61f4e2a9bf68f780f4f6623c18b57816a9679d17","aea179452def8a6152f98f63b191b84e7cbd69b0e248c91e61fb2e52328abe8c",{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"55f400eec64d17e888e278f4def2f254b41b89515d3b88ad75d5e05f019daddd","affectsGlobalScope":true},{"version":"181f1784c6c10b751631b24ce60c7f78b20665db4550b335be179217bacc0d5f","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"775d9c9fd150d5de79e0450f35bc8b8f94ae64e3eb5da12725ff2a649dccc777","affectsGlobalScope":true},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true},{"version":"6c55633c733c8378db65ac3da7a767c3cf2cf3057f0565a9124a16a3a2019e87","affectsGlobalScope":true},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true},{"version":"34c839eaaa6d78c8674ae2c37af2236dee6831b13db7b4ef4df3ec889a04d4f2","affectsGlobalScope":true},{"version":"34478567f8a80171f88f2f30808beb7da15eac0538ae91282dd33dce928d98ed","affectsGlobalScope":true},{"version":"ab7d58e6161a550ff92e5aff755dc37fe896245348332cd5f1e1203479fe0ed1","affectsGlobalScope":true},{"version":"6bda95ea27a59a276e46043b7065b55bd4b316c25e70e29b572958fa77565d43","affectsGlobalScope":true},{"version":"aedb8de1abb2ff1095c153854a6df7deae4a5709c37297f9d6e9948b6806fa66","affectsGlobalScope":true},{"version":"a4da0551fd39b90ca7ce5f68fb55d4dc0c1396d589b612e1902f68ee090aaada","affectsGlobalScope":true},{"version":"11ffe3c281f375fff9ffdde8bbec7669b4dd671905509079f866f2354a788064","affectsGlobalScope":true},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true},"0704bdc9e66ede7a2183c419efdbb5f22c195952231e6c0b9cba526df2e8e2a4","5e22f932d1687df8312894052ab0596c3206342cab47a30052908ff6bb37af34","8d4e3c29ce13a2cfc9d60930ae3d109d858f1db924d796c2a58c4f0b56a23c2b","0d5a2ee1fdfa82740e0103389b9efd6bfe145a20018a2da3c02b89666181f4d9","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"92d63add669d18ebc349efbacd88966d6f2ccdddfb1b880b2db98ae3aa7bf7c4","affectsGlobalScope":true},"ccc94049a9841fe47abe5baef6be9a38fc6228807974ae675fb15dc22531b4be",{"version":"9acfe4d1ff027015151ce81d60797b04b52bffe97ad8310bb0ec2e8fd61e1303","affectsGlobalScope":true},"95843d5cfafced8f3f8a5ce57d2335f0bcd361b9483587d12a25e4bd403b8216","afc6e96061af46bcff47246158caee7e056f5288783f2d83d6858cd25be1c565",{"version":"34f5bcac12b36d70304b73de5f5aab3bb91bd9919f984be80579ebcad03a624e","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","2f520601649a893e6a49a8851ebfcf4be8ce090dc1281c2a08a871cb04e8251f","f50c975ab7b50e25a69e3d8a3773894125b44e9698924105f23b812bf7488baf","2b8c764f856a1dd0a9a2bf23e5efddbff157de8138b0754010be561ae5fcaa90","76650408392bf49a8fbf3e2b6b302712a92d76af77b06e2da1cc8077359c4409","0af3121e68297b2247dd331c0d24dba599e50736a7517a5622d5591aae4a3122","6972fca26f6e9bd56197568d4379f99071a90766e06b4fcb5920a0130a9202be",{"version":"4a2628e95962c8ab756121faa3ac2ed348112ff7a87b5c286dd2cc3326546b4c","affectsGlobalScope":true},"80793b2277f31baa199234daed806fff0fb11491d1ebd3357e520c3558063f00","a049a59a02009fc023684fcfaf0ac526fe36c35dcc5d2b7d620c1750ba11b083","196fee5541bfd59699dab615fee2ae7a6f5fe0a6337bcbbfd656ebf1ae329a63","160cc6e3d06938535bc887754afe5798c22d81ce83a9792ebfe2371a70f2ffc2","4b9a003b5c556c96784132945bb41c655ea11273b1917f5c8d0c154dd5fd20dd","a458dc78104cc80048ac24fdc02fe6dce254838094c2f25641b3f954d9721241",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"eecd493fc62c4dba3d988e2d7dff63299bf12ab49f5c9021dfef8dcc1ff2089e","abc1c425b2ad6720433f40f1877abfa4223f0f3dd486c9c28c492179ca183cb6","945a841f9a591197154c85386bc5a1467d42d325104bb36db51bc566bbb240be","10c39ce1df102994b47d4bc0c71aa9a6aea76f4651a5ec51914431f50bc883a1",{"version":"8207e7e6db9aa5fc7e61c8f17ba74cf9c115d26f51f91ee93f790815a7ea9dfb","affectsGlobalScope":true},"9f1069b9e2c051737b1f9b4f1baf50e4a63385a6a89c32235549ae87fc3d5492","ee18f2da7a037c6ceeb112a084e485aead9ea166980bf433474559eac1b46553","29c2706fa0cc49a2bd90c83234da33d08bb9554ecec675e91c1f85087f5a5324","0acbf26bf958f9e80c1ffa587b74749d2697b75b484062d36e103c137c562bc3","d7838022c7dab596357a9604b9c6adffe37dc34085ce0779c958ce9545bd7139","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"a7971f9fb2a32ec7788ec6cda9d7a33c02023dfe9a62db2030ad1359649d8050","c33a6ea7147af60d8e98f1ac127047f4b0d4e2ce28b8f08ff3de07ca7cc00637",{"version":"b42b47e17b8ece2424ae8039feb944c2e3ba4b262986aebd582e51efbdca93dc","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","2408611d9b4146e35d1dbd1f443ccd8e187c74614a54b80300728277529dbf11","998a3de5237518c0b3ac00a11b3b4417affb008aa20aedee52f3fdae3cb86151","ad41008ffe077206e1811fc873f4d9005b5fd7f6ab52bb6118fef600815a5cb4",{"version":"daa2956e185fbca0591cb8cbe075c115301cbac7863092103f2aed6078dfb612","affectsGlobalScope":true},"badae0df9a8016ac36994b0a0e7b82ba6aaa3528e175a8c3cb161e4683eec03e","c3db860bcaaaeb3bbc23f353bbda1f8ab82756c8d5e973bebb3953cb09ea68f2","235a53595bd20b0b0eeb1a29cb2887c67c48375e92f03749b2488fbd46d0b1a0","bc09393cd4cd13f69cf1366d4236fbae5359bb550f0de4e15767e9a91d63dfb1","9c266243b01545e11d2733a55ad02b4c00ecdbda99c561cd1674f96e89cdc958","c71155c05fc76ff948a4759abc1cb9feec036509f500174bc18dad4c7827a60c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"1503a452a67127e5c2da794d1c7c44344d5038373aae16c9b03ac964db159edd","0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","d982cdd2610155b3cbcbfa62ccabcf2d2b739f821518ef113348d160ef0010d9","ffcc5500e77223169833fc6eb59b3a507944a1f89574e0a1276b0ea7fc22c4a4","22f13de9e2fe5f0f4724797abd3d34a1cdd6e47ef81fc4933fea3b8bf4ad524b","e3ba509d3dce019b3190ceb2f3fc88e2610ab717122dabd91a9efaa37804040d","cda0cb09b995489b7f4c57f168cd31b83dcbaa7aad49612734fb3c9c73f6e4f2",{"version":"1de1ad6a1929317171d8cfcd55bb2732257680c1bf89bcd53e1d46a4d8dbda22","affectsGlobalScope":true}],"options":{"allowSyntheticDefaultImports":true,"alwaysStrict":false,"esModuleInterop":true,"jsx":2,"module":1,"skipLibCheck":true,"strict":true,"target":99},"fileIdsList":[[100,109],[100],[100,111,113],[100,111],[100,108,112],[100,110],[57,100],[60,100],[61,66,100],[62,72,73,80,89,99,100],[62,63,72,80,100],[64,100],[65,66,73,81,100],[66,89,96,100],[67,69,72,80,100],[68,100],[69,70,100],[71,72,100],[72,100],[72,73,74,89,99,100],[72,73,74,89,100],[75,80,89,99,100],[72,73,75,76,80,89,96,99,100],[75,77,89,96,99,100],[57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106],[72,78,100],[79,99,100],[69,72,80,89,100],[81,100],[82,100],[60,83,100],[84,98,100,104],[85,100],[86,100],[72,87,100],[87,88,100,102],[72,89,90,91,100],[89,91,100],[89,90,100],[92,100],[93,100],[72,94,95,100],[94,95,100],[66,80,96,100],[97,100],[80,98,100],[61,75,86,99,100],[66,100],[89,100,101],[100,102],[100,103],[61,66,72,74,83,89,99,100,102,104],[89,100,105],[54,100]],"referencedMap":[[110,1],[109,2],[114,3],[108,2],[112,4],[113,5],[111,6],[57,7],[58,7],[60,8],[61,9],[62,10],[63,11],[64,12],[65,13],[66,14],[67,15],[68,16],[69,17],[70,17],[71,18],[72,19],[73,20],[74,21],[59,2],[106,2],[75,22],[76,23],[77,24],[107,25],[78,26],[79,27],[80,28],[81,29],[82,30],[83,31],[84,32],[85,33],[86,34],[87,35],[88,36],[89,37],[91,38],[90,39],[92,40],[93,41],[94,42],[95,43],[96,44],[97,45],[98,46],[99,47],[100,48],[101,49],[102,50],[103,51],[104,52],[105,53],[12,2],[11,2],[2,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[3,2],[4,2],[24,2],[21,2],[22,2],[23,2],[25,2],[26,2],[27,2],[5,2],[28,2],[29,2],[30,2],[31,2],[6,2],[32,2],[33,2],[34,2],[35,2],[7,2],[36,2],[41,2],[42,2],[37,2],[38,2],[39,2],[40,2],[8,2],[46,2],[43,2],[44,2],[45,2],[47,2],[9,2],[48,2],[49,2],[50,2],[51,2],[52,2],[1,2],[10,2],[53,2],[55,54],[56,2],[54,2]],"exportedModulesMap":[[110,1],[109,2],[114,3],[108,2],[112,4],[113,5],[111,6],[57,7],[58,7],[60,8],[61,9],[62,10],[63,11],[64,12],[65,13],[66,14],[67,15],[68,16],[69,17],[70,17],[71,18],[72,19],[73,20],[74,21],[59,2],[106,2],[75,22],[76,23],[77,24],[107,25],[78,26],[79,27],[80,28],[81,29],[82,30],[83,31],[84,32],[85,33],[86,34],[87,35],[88,36],[89,37],[91,38],[90,39],[92,40],[93,41],[94,42],[95,43],[96,44],[97,45],[98,46],[99,47],[100,48],[101,49],[102,50],[103,51],[104,52],[105,53],[12,2],[11,2],[2,2],[13,2],[14,2],[15,2],[16,2],[17,2],[18,2],[19,2],[20,2],[3,2],[4,2],[24,2],[21,2],[22,2],[23,2],[25,2],[26,2],[27,2],[5,2],[28,2],[29,2],[30,2],[31,2],[6,2],[32,2],[33,2],[34,2],[35,2],[7,2],[36,2],[41,2],[42,2],[37,2],[38,2],[39,2],[40,2],[8,2],[46,2],[43,2],[44,2],[45,2],[47,2],[9,2],[48,2],[49,2],[50,2],[51,2],[52,2],[1,2],[10,2],[53,2],[55,54],[56,2],[54,2]],"semanticDiagnosticsPerFile":[110,109,114,108,112,113,111,57,58,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,59,106,75,76,77,107,78,79,80,81,82,83,84,85,86,87,88,89,91,90,92,93,94,95,96,97,98,99,100,101,102,103,104,105,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,32,33,34,35,7,36,41,42,37,38,39,40,8,46,43,44,45,47,9,48,49,50,51,52,1,10,53,55,56,54],"affectedFilesPendingEmit":[[110,1],[109,1],[114,1],[108,1],[112,1],[113,1],[111,1],[57,1],[58,1],[60,1],[61,1],[62,1],[63,1],[64,1],[65,1],[66,1],[67,1],[68,1],[69,1],[70,1],[71,1],[72,1],[73,1],[74,1],[59,1],[106,1],[75,1],[76,1],[77,1],[107,1],[78,1],[79,1],[80,1],[81,1],[82,1],[83,1],[84,1],[85,1],[86,1],[87,1],[88,1],[89,1],[91,1],[90,1],[92,1],[93,1],[94,1],[95,1],[96,1],[97,1],[98,1],[99,1],[100,1],[101,1],[102,1],[103,1],[104,1],[105,1],[2,1],[3,1],[4,1],[5,1],[6,1],[7,1],[8,1],[9,1],[10,1],[55,1],[56,1],[54,1]]},"version":"4.8.4"}
@@ -110,6 +110,42 @@ var D1PreparedStatement = class {
110
110
  this.params = values || [];
111
111
  }
112
112
  bind(...values) {
113
+ for (var r in values) {
114
+ switch (typeof values[r]) {
115
+ case "number":
116
+ case "string":
117
+ break;
118
+ case "object":
119
+ if (values[r] == null) break;
120
+ if (
121
+ Array.isArray(values[r]) &&
122
+ values[r]
123
+ .map((b) => {
124
+ return typeof b == "number" && b >= 0 && b < 256 ? 1 : 0;
125
+ })
126
+ .indexOf(0) == -1
127
+ )
128
+ break;
129
+ if (values[r] instanceof ArrayBuffer) {
130
+ values[r] = Array.from(new Uint8Array(values[r]));
131
+ break;
132
+ }
133
+ if (ArrayBuffer.isView(values[r])) {
134
+ values[r] = Array.from(values[r]);
135
+ break;
136
+ }
137
+ default:
138
+ throw new Error("D1_TYPE_ERROR", {
139
+ cause: new Error(
140
+ "Type '" +
141
+ typeof values[r] +
142
+ "' not supported for value '" +
143
+ values[r] +
144
+ "'"
145
+ ),
146
+ });
147
+ }
148
+ }
113
149
  return new D1PreparedStatement(this.database, this.statement, values);
114
150
  }
115
151
  async first(colName) {
@@ -0,0 +1,14 @@
1
+ declare module "__ENTRY_POINT__" {
2
+ import type { Middleware } from "./middleware/common";
3
+ const worker: ExportedHandler & { middleware?: Middleware[] };
4
+ export default worker;
5
+ }
6
+
7
+ declare module "__KV_ASSET_HANDLER__" {
8
+ export * from "@cloudflare/kv-asset-handler";
9
+ }
10
+
11
+ declare module "__STATIC_CONTENT_MANIFEST" {
12
+ const manifest: string;
13
+ export default manifest;
14
+ }
@@ -1,6 +1,4 @@
1
- // @ts-ignore entry point will get replaced
2
1
  import worker from "__ENTRY_POINT__";
3
- // @ts-ignore entry point will get replaced
4
2
  export * from "__ENTRY_POINT__";
5
3
 
6
4
  type Env = {
@@ -11,8 +9,11 @@ type Env = {
11
9
  * Setup globals/vars as required
12
10
  */
13
11
 
14
- export default {
12
+ export default <ExportedHandler>{
15
13
  async fetch(request: Request, env: Env, ctx: ExecutionContext) {
14
+ if (worker.fetch === undefined) {
15
+ throw new TypeError("Entry point missing `fetch` handler");
16
+ }
16
17
  return worker.fetch(request, env, ctx);
17
18
  },
18
19
  };
@@ -1,13 +1,14 @@
1
- // @ts-expect-error We'll swap in the entry point during build
2
- import Worker from "__ENTRY_POINT__";
1
+ import worker from "__ENTRY_POINT__";
3
2
 
4
- // @ts-expect-error
5
3
  export * from "__ENTRY_POINT__";
6
4
 
7
- export default {
8
- async fetch(req: Request, env: unknown, ctx: ExecutionContext) {
5
+ export default <ExportedHandler>{
6
+ async fetch(req, env, ctx) {
7
+ if (worker.fetch === undefined) {
8
+ throw new TypeError("Entry point missing `fetch` handler");
9
+ }
9
10
  try {
10
- return await Worker.fetch(req, env, ctx);
11
+ return await worker.fetch(req, env, ctx);
11
12
  } catch (err) {
12
13
  return new Response(
13
14
  `<!DOCTYPE html>
@@ -4,11 +4,9 @@ describe("Worker", () => {
4
4
  let worker;
5
5
 
6
6
  beforeAll(async () => {
7
- worker = await unstable_dev(
8
- "src/index.js",
9
- {},
10
- { disableExperimentalWarning: true }
11
- );
7
+ worker = await unstable_dev("src/index.js", {
8
+ experimental: { disableExperimentalWarning: true },
9
+ });
12
10
  });
13
11
 
14
12
  afterAll(async () => {
@@ -5,11 +5,9 @@ describe("Worker", () => {
5
5
  let worker;
6
6
 
7
7
  beforeAll(async () => {
8
- worker = await unstable_dev(
9
- "src/index.js",
10
- {},
11
- { disableExperimentalWarning: true }
12
- );
8
+ worker = await unstable_dev("src/index.js", {
9
+ experimental: { disableExperimentalWarning: true },
10
+ });
13
11
  });
14
12
 
15
13
  afterAll(async () => {
@@ -0,0 +1,25 @@
1
+ import { unstable_dev } from "wrangler";
2
+ import type { UnstableDevWorker } from "wrangler";
3
+ import { describe, expect, it, beforeAll, afterAll } from "vitest";
4
+
5
+ describe("Worker", () => {
6
+ let worker: UnstableDevWorker;
7
+
8
+ beforeAll(async () => {
9
+ worker = await unstable_dev("src/index.ts", {
10
+ experimental: { disableExperimentalWarning: true },
11
+ });
12
+ });
13
+
14
+ afterAll(async () => {
15
+ await worker.stop();
16
+ });
17
+
18
+ it("should return Hello World", async () => {
19
+ const resp = await worker.fetch();
20
+ if (resp) {
21
+ const text = await resp.text();
22
+ expect(text).toMatchInlineSnapshot(`"Hello World!"`);
23
+ }
24
+ });
25
+ });
@@ -11,11 +11,9 @@ import {
11
11
  __facade_register__,
12
12
  } from "./common";
13
13
 
14
- // @ts-expect-error We'll swap in the entry point during build
15
14
  import worker from "__ENTRY_POINT__";
16
15
 
17
16
  // We need to preserve all of the exports from the worker
18
- // @ts-expect-error We'll swap in the entry point during build
19
17
  export * from "__ENTRY_POINT__";
20
18
 
21
19
  class __Facade_ScheduledController__ implements ScheduledController {
@@ -183,6 +183,8 @@ __facade__originalAddEventListener__("fetch", (event) => {
183
183
  });
184
184
 
185
185
  __FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);
186
+ // @ts-expect-error `waitUntil` types are currently broken, blocked on
187
+ // https://github.com/cloudflare/workerd/pull/191
186
188
  event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
187
189
  }
188
190
  };
@@ -195,6 +197,8 @@ __facade__originalAddEventListener__("fetch", (event) => {
195
197
 
196
198
  __FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);
197
199
  facadeEvent[__facade_dispatched__] = true;
200
+ // @ts-expect-error `waitUntil` types are currently broken, blocked on
201
+ // https://github.com/cloudflare/workerd/pull/191
198
202
  event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
199
203
 
200
204
  const response = facadeEvent[__facade_response__];
@@ -223,5 +227,7 @@ __facade__originalAddEventListener__("scheduled", (event) => {
223
227
  });
224
228
 
225
229
  __FACADE_EVENT_TARGET__.dispatchEvent(facadeEvent);
230
+ // @ts-expect-error `waitUntil` types are currently broken, blocked on
231
+ // https://github.com/cloudflare/workerd/pull/191
226
232
  event.waitUntil(Promise.all(facadeEvent[__facade_waitUntil__]));
227
233
  });
@@ -7,7 +7,7 @@ import { isRoutingRuleMatch } from "./pages-dev-util";
7
7
  // @ts-ignore routes are injected
8
8
  const routes = __ROUTES__;
9
9
 
10
- export default {
10
+ export default <ExportedHandler<{ ASSETS: Fetcher }>>{
11
11
  fetch(request, env, context) {
12
12
  const { pathname } = new URL(request.url);
13
13
 
@@ -19,6 +19,9 @@ export default {
19
19
 
20
20
  for (const include of routes.include) {
21
21
  if (isRoutingRuleMatch(pathname, include)) {
22
+ if (worker.fetch === undefined) {
23
+ throw new TypeError("Entry point missing `fetch` handler");
24
+ }
22
25
  return worker.fetch(request, env, context);
23
26
  }
24
27
  }
@@ -1,8 +1,11 @@
1
1
  // This Worker is used as a default when no Pages Functions are present.
2
2
  // It proxies the request directly on to the asset server binding.
3
3
 
4
- export default {
4
+ export default <ExportedHandler<{ ASSETS: Fetcher }>>{
5
5
  async fetch(request, env, context) {
6
+ // @ts-expect-error due to a bug in `@cloudflare/workers-types`, the `cf`
7
+ // types from the `request` parameter and `RequestInit` are incompatible.
8
+ // We'll get this fixed very soon.
6
9
  const response = await env.ASSETS.fetch(request.url, request);
7
10
  return new Response(response.body, response);
8
11
  },
@@ -119,14 +119,15 @@ function* executeRequest(request: Request, relativePathname: string) {
119
119
  }
120
120
  }
121
121
 
122
- export default function (pluginArgs) {
122
+ export default function (pluginArgs: unknown) {
123
123
  const onRequest: PagesPluginFunction = async (workerContext) => {
124
124
  let { request } = workerContext;
125
125
  const { env, next, data } = workerContext;
126
126
 
127
127
  const url = new URL(request.url);
128
+ // TODO: Replace this with something actually legible.
128
129
  const relativePathname = `/${
129
- url.pathname.split(workerContext.functionPath)[1] || ""
130
+ url.pathname.replace(workerContext.functionPath, "") || ""
130
131
  }`.replace(/^\/\//, "/");
131
132
 
132
133
  const handlerIterator = executeRequest(request, relativePathname);
@@ -154,11 +155,7 @@ export default function (pluginArgs) {
154
155
 
155
156
  const response = await handler(context);
156
157
 
157
- // https://fetch.spec.whatwg.org/#null-body-status
158
- return new Response(
159
- [101, 204, 205, 304].includes(response.status) ? null : response.body,
160
- { ...response, headers: new Headers(response.headers) }
161
- );
158
+ return cloneResponse(response);
162
159
  } else {
163
160
  return next();
164
161
  }
@@ -169,3 +166,11 @@ export default function (pluginArgs) {
169
166
 
170
167
  return onRequest;
171
168
  }
169
+
170
+ // This makes a Response mutable
171
+ const cloneResponse = (response: Response) =>
172
+ // https://fetch.spec.whatwg.org/#null-body-status
173
+ new Response(
174
+ [101, 204, 205, 304].includes(response.status) ? null : response.body,
175
+ response
176
+ );
@@ -1,31 +1,33 @@
1
- // @ts-expect-error
2
1
  import worker from "__ENTRY_POINT__";
3
2
  import {
4
3
  getAssetFromKV,
5
4
  NotFoundError,
6
5
  MethodNotAllowedError,
7
- // @ts-expect-error
6
+ serveSinglePageApp,
8
7
  } from "__KV_ASSET_HANDLER__";
9
- // @ts-expect-error
8
+ import type { Options, CacheControl } from "__KV_ASSET_HANDLER__";
10
9
  import manifest from "__STATIC_CONTENT_MANIFEST";
11
10
  import type * as kvAssetHandler from "@cloudflare/kv-asset-handler";
12
11
 
13
12
  const ASSET_MANIFEST = JSON.parse(manifest);
14
13
 
15
- // @ts-expect-error
16
14
  export * from "__ENTRY_POINT__";
17
15
 
18
- export default {
19
- async fetch(
20
- request: Request,
21
- env: { __STATIC_CONTENT: string },
22
- ctx: ExecutionContext
23
- ) {
24
- let options = {
16
+ // Injected as `esbuild` `define`s
17
+ declare global {
18
+ const __CACHE_CONTROL_OPTIONS__: Partial<CacheControl>;
19
+ const __SERVE_SINGLE_PAGE_APP__: boolean;
20
+ }
21
+
22
+ export default <ExportedHandler<{ __STATIC_CONTENT: KVNamespace }>>{
23
+ async fetch(request, env, ctx) {
24
+ let options: Partial<Options> = {
25
25
  ASSET_MANIFEST,
26
26
  ASSET_NAMESPACE: env.__STATIC_CONTENT,
27
27
  cacheControl: __CACHE_CONTROL_OPTIONS__,
28
- serveSinglePageApp: __SERVE_SINGLE_PAGE_APP__,
28
+ mapRequestToAsset: __SERVE_SINGLE_PAGE_APP__
29
+ ? serveSinglePageApp
30
+ : undefined,
29
31
  };
30
32
 
31
33
  try {
@@ -34,7 +36,7 @@ export default {
34
36
  )(
35
37
  {
36
38
  request,
37
- waitUntil(promise: Promise<unknown>) {
39
+ waitUntil(promise) {
38
40
  return ctx.waitUntil(promise);
39
41
  },
40
42
  },
@@ -54,7 +56,7 @@ export default {
54
56
  } catch (e) {
55
57
  if (e instanceof NotFoundError || e instanceof MethodNotAllowedError) {
56
58
  // if a known error is thrown then serve from actual worker
57
- return await worker.fetch(request, env, ctx);
59
+ return await worker.fetch?.(request, env, ctx);
58
60
  }
59
61
  // otherwise it's a real error, so throw it
60
62
  throw e;
@@ -0,0 +1,11 @@
1
+ // @ts-nocheck `@types/node` should NOT be included
2
+ Buffer.from("test");
3
+
4
+ // @ts-expect-error `@types/jest` should NOT be included
5
+ test("test");
6
+
7
+ // `@cloudflare/workers-types` should be included
8
+ const _handler: ExportedHandler = {};
9
+ new HTMLRewriter();
10
+
11
+ export {};