wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa

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 (237) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +30 -10
  3. package/miniflare-dist/index.mjs +126 -74
  4. package/package.json +27 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +567 -86
  9. package/src/__tests__/d1/d1.test.ts +82 -0
  10. package/src/__tests__/d1/execute.test.ts +66 -0
  11. package/src/__tests__/d1/migrate.test.ts +157 -0
  12. package/src/__tests__/d1/splitter.test.ts +255 -0
  13. package/src/__tests__/delete.test.ts +91 -49
  14. package/src/__tests__/deployments.test.ts +330 -56
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +12 -10
  17. package/src/__tests__/guess-worker-format.test.ts +35 -0
  18. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  19. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  20. package/src/__tests__/helpers/mock-console.ts +6 -0
  21. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  22. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  24. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  25. package/src/__tests__/helpers/mock-kv.ts +29 -16
  26. package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
  27. package/src/__tests__/helpers/mock-process.ts +8 -13
  28. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  29. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  30. package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
  31. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  32. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +90 -72
  42. package/src/__tests__/init.test.ts +927 -631
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +47 -0
  47. package/src/__tests__/metrics.test.ts +94 -51
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +588 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +452 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +955 -0
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +1615 -852
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +238 -77
  63. package/src/__tests__/r2.test.ts +55 -57
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +267 -109
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +43 -26
  72. package/src/__tests__/user.test.ts +35 -72
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +168 -60
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +76 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +355 -0
  81. package/src/bundle.ts +263 -140
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +79 -24
  87. package/src/config/index.ts +99 -38
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -19
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +60 -22
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/constants.ts +2 -0
  94. package/src/d1/create.tsx +44 -30
  95. package/src/d1/{delete.tsx → delete.ts} +11 -14
  96. package/src/d1/execute.tsx +209 -151
  97. package/src/d1/index.ts +31 -7
  98. package/src/d1/list.tsx +22 -10
  99. package/src/d1/migrations/apply.tsx +212 -0
  100. package/src/d1/migrations/create.tsx +79 -0
  101. package/src/d1/migrations/helpers.ts +172 -0
  102. package/src/d1/migrations/index.ts +3 -0
  103. package/src/d1/migrations/list.tsx +95 -0
  104. package/src/d1/migrations/options.ts +23 -0
  105. package/src/d1/options.ts +12 -2
  106. package/src/d1/splitter.ts +161 -0
  107. package/src/d1/{types.tsx → types.ts} +11 -0
  108. package/src/d1/utils.ts +12 -2
  109. package/src/delete.ts +8 -16
  110. package/src/deployments.ts +340 -46
  111. package/src/deprecated/index.ts +8 -302
  112. package/src/dev/dev.tsx +57 -44
  113. package/src/dev/local.tsx +294 -91
  114. package/src/dev/remote.tsx +32 -3
  115. package/src/dev/start-server.ts +89 -68
  116. package/src/dev/use-esbuild.ts +17 -18
  117. package/src/dev/validate-dev-props.ts +9 -0
  118. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  119. package/src/dev.tsx +178 -118
  120. package/src/dialogs.ts +136 -0
  121. package/src/dispatch-namespace.ts +21 -17
  122. package/src/docs/index.ts +97 -0
  123. package/src/entry.ts +19 -11
  124. package/src/environment-variables/factory.ts +88 -0
  125. package/src/environment-variables/misc-variables.ts +30 -0
  126. package/src/generate/index.ts +298 -0
  127. package/src/git-client.ts +15 -4
  128. package/src/{index.tsx → index.ts} +137 -63
  129. package/src/init.ts +249 -187
  130. package/src/inspect.ts +16 -1
  131. package/src/jest.d.ts +4 -0
  132. package/src/kv/index.ts +15 -17
  133. package/src/logger.ts +32 -5
  134. package/src/metrics/metrics-config.ts +3 -3
  135. package/src/metrics/send-event.ts +6 -1
  136. package/src/miniflare-cli/assets.ts +64 -28
  137. package/src/miniflare-cli/index.ts +4 -7
  138. package/src/miniflare-cli/tsconfig.json +9 -0
  139. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  140. package/src/miniflare-cli/types.ts +11 -0
  141. package/src/module-collection.ts +91 -25
  142. package/src/mtls-certificate/cli.ts +155 -0
  143. package/src/pages/build.ts +410 -0
  144. package/src/pages/buildFunctions.ts +140 -0
  145. package/src/pages/deployment-tails.ts +281 -0
  146. package/src/pages/deployments.tsx +11 -33
  147. package/src/pages/{dev.tsx → dev.ts} +147 -124
  148. package/src/pages/errors.ts +1 -0
  149. package/src/pages/functions/buildPlugin.ts +72 -69
  150. package/src/pages/functions/buildWorker.ts +249 -114
  151. package/src/pages/functions/tsconfig.json +8 -0
  152. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  153. package/src/pages/{functions.tsx → functions.ts} +8 -4
  154. package/src/pages/{index.tsx → index.ts} +11 -3
  155. package/src/pages/projects.tsx +12 -22
  156. package/src/pages/prompt-select-project.tsx +31 -0
  157. package/src/pages/publish.tsx +45 -214
  158. package/src/pages/types.ts +6 -9
  159. package/src/pages/upload.tsx +58 -14
  160. package/src/pages/utils.ts +14 -3
  161. package/src/parse.ts +23 -1
  162. package/src/paths.ts +1 -1
  163. package/src/proxy.ts +5 -0
  164. package/src/publish/index.ts +20 -16
  165. package/src/publish/publish.ts +72 -47
  166. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  167. package/src/queues/cli/commands/consumer/add.ts +24 -24
  168. package/src/queues/cli/commands/consumer/index.ts +3 -6
  169. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  170. package/src/queues/cli/commands/create.ts +8 -8
  171. package/src/queues/cli/commands/delete.ts +8 -8
  172. package/src/queues/cli/commands/index.ts +6 -4
  173. package/src/queues/cli/commands/list.ts +8 -8
  174. package/src/queues/client.ts +1 -0
  175. package/src/queues/utils.ts +18 -0
  176. package/src/r2/constants.ts +4 -0
  177. package/src/r2/helpers.ts +1 -0
  178. package/src/r2/index.ts +40 -28
  179. package/src/secret/index.ts +14 -17
  180. package/src/{sites.tsx → sites.ts} +1 -1
  181. package/src/tail/createTail.ts +94 -3
  182. package/src/tail/filters.ts +1 -1
  183. package/src/tail/index.ts +8 -11
  184. package/src/tail/printing.ts +15 -0
  185. package/src/traverse-module-graph.ts +53 -0
  186. package/src/tsconfig-sanity.ts +16 -0
  187. package/src/type-generation.ts +79 -57
  188. package/src/user/access.ts +0 -1
  189. package/src/user/auth-variables.ts +113 -0
  190. package/src/user/choose-account.tsx +1 -31
  191. package/src/user/index.ts +0 -1
  192. package/src/user/{user.tsx → user.ts} +123 -82
  193. package/src/utils/render.ts +93 -0
  194. package/src/{whoami.tsx → whoami.ts} +37 -71
  195. package/src/worker.ts +35 -3
  196. package/src/yargs-types.ts +22 -5
  197. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  198. package/templates/__tests__/tsconfig.json +8 -0
  199. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  200. package/templates/checked-fetch.js +9 -3
  201. package/templates/d1-beta-facade.js +95 -25
  202. package/templates/facade.d.ts +14 -0
  203. package/templates/first-party-worker-module-facade.ts +4 -3
  204. package/templates/format-dev-errors.ts +8 -6
  205. package/templates/gitignore +1 -0
  206. package/templates/init-tests/test-jest-new-worker.js +3 -5
  207. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  208. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  209. package/templates/middleware/loader-modules.ts +2 -2
  210. package/templates/middleware/loader-sw.ts +51 -31
  211. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  212. package/templates/new-worker.ts +3 -0
  213. package/templates/pages-dev-pipeline.ts +4 -1
  214. package/templates/pages-shim.ts +4 -1
  215. package/templates/pages-template-plugin.ts +19 -10
  216. package/templates/serve-static-assets.ts +17 -14
  217. package/templates/service-bindings-module-facade.js +1 -0
  218. package/templates/tsconfig-sanity.ts +11 -0
  219. package/templates/tsconfig.init.json +105 -0
  220. package/templates/tsconfig.json +5 -103
  221. package/templates/tsconfig.tsbuildinfo +1 -0
  222. package/wrangler-dist/cli.d.ts +826 -77
  223. package/wrangler-dist/cli.js +130734 -140838
  224. package/wrangler-dist/wasm-sync.wasm +0 -0
  225. package/src/__tests__/api-devregistry.test.js +0 -57
  226. package/src/__tests__/d1.test.ts +0 -72
  227. package/src/__tests__/dialogs.test.tsx +0 -40
  228. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  229. package/src/__tests__/pages.test.ts +0 -2223
  230. package/src/dialogs.tsx +0 -163
  231. package/src/environment-variables.ts +0 -50
  232. package/src/pages/build.tsx +0 -238
  233. package/src/user/env-vars.ts +0 -46
  234. package/templates/experimental-local-cache-stubs.js +0 -27
  235. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  236. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  237. /package/src/pages/{hash.tsx → hash.ts} +0 -0
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  <h1 align="center"> ⛅️ wrangler </h1>
2
2
  <section align="center" id="shieldio-badges">
3
3
  <a href="https://www.npmjs.com/package/wrangler"><img alt="npm" src="https://img.shields.io/npm/dw/wrangler?style=flat-square"></a>
4
- <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/wrangler2?style=flat-square">
5
- <img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/wrangler2/main?style=flat-square">
4
+ <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/workers-sdk?style=flat-square">
5
+ <img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/workers-sdk/main?style=flat-square">
6
6
  <a href="https://discord.gg/CloudflareDev"><img alt="Discord" src="https://img.shields.io/discord/595317990191398933?color=%23F48120&style=flat-square"></a>
7
7
  </section>
8
8
 
9
- > This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler.
9
+ > This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler-legacy.
10
10
 
11
11
  `wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
12
12
 
package/bin/wrangler.js CHANGED
@@ -20,7 +20,7 @@ function runWrangler() {
20
20
  // Note Volta and nvm are also recommended in the official docs:
21
21
  // https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
22
22
  console.error(
23
- `Wrangler requires at least node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of node.js.
23
+ `Wrangler requires at least Node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of Node.js.
24
24
 
25
25
  Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.`
26
26
  );
@@ -62,15 +62,21 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
62
62
  ...process.argv.slice(2),
63
63
  ],
64
64
  {
65
- stdio: "inherit",
65
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
66
66
  env: {
67
67
  ...process.env,
68
68
  NODE_EXTRA_CA_CERTS: pathToCACerts,
69
69
  },
70
70
  }
71
- ).on("exit", (code) =>
72
- process.exit(code === undefined || code === null ? 0 : code)
73
- );
71
+ )
72
+ .on("exit", (code) =>
73
+ process.exit(code === undefined || code === null ? 0 : code)
74
+ )
75
+ .on("message", (message) => {
76
+ if (process.send) {
77
+ process.send(message);
78
+ }
79
+ });
74
80
  }
75
81
 
76
82
  /**
@@ -87,7 +93,15 @@ function runDelegatedWrangler() {
87
93
  } = JSON.parse(fs.readFileSync(packageJsonPath));
88
94
  const resolvedBinaryPath = path.resolve(packageJsonPath, "..", binaryPath);
89
95
 
90
- debug(`Delegating to locally-installed version of wrangler @ v${version}`);
96
+ // Make sure the user knows we're delegating to a different installation
97
+ const currentPackageJsonPath = path.resolve(__dirname, "..", "package.json");
98
+ const currentPackage = JSON.parse(fs.readFileSync(currentPackageJsonPath));
99
+ const argv = process.argv.slice(2).join(" ");
100
+ console.log(
101
+ `Delegating to locally-installed wrangler@${version} over global wrangler@${currentPackage.version}...
102
+ Run \`npx wrangler ${argv}\` to use the local version directly.
103
+ `
104
+ );
91
105
 
92
106
  // this call to `spawn` is simpler because the delegated version will do all
93
107
  // of the other work.
@@ -95,11 +109,17 @@ function runDelegatedWrangler() {
95
109
  process.execPath,
96
110
  [resolvedBinaryPath, ...process.argv.slice(2)],
97
111
  {
98
- stdio: "inherit",
112
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
99
113
  }
100
- ).on("exit", (code) =>
101
- process.exit(code === undefined || code === null ? 0 : code)
102
- );
114
+ )
115
+ .on("exit", (code) =>
116
+ process.exit(code === undefined || code === null ? 0 : code)
117
+ )
118
+ .on("message", (message) => {
119
+ if (process.send) {
120
+ process.send(message);
121
+ }
122
+ });
103
123
  }
104
124
 
105
125
  /**
@@ -128,23 +128,45 @@ var init_environment_polyfills = __esm({
128
128
  }
129
129
  });
130
130
 
131
+ // ../pages-shared/environment-polyfills/miniflare-tre.ts
132
+ var miniflare_tre_exports = {};
133
+ __export(miniflare_tre_exports, {
134
+ default: () => miniflare_tre_default
135
+ });
136
+ var miniflare_tre_default;
137
+ var init_miniflare_tre = __esm({
138
+ "../pages-shared/environment-polyfills/miniflare-tre.ts"() {
139
+ init_environment_polyfills();
140
+ miniflare_tre_default = async () => {
141
+ const mf = await import("@miniflare/tre");
142
+ polyfill({
143
+ fetch: mf.fetch,
144
+ Headers: mf.Headers,
145
+ Request: mf.Request,
146
+ Response: mf.Response
147
+ });
148
+ };
149
+ }
150
+ });
151
+
131
152
  // ../pages-shared/environment-polyfills/miniflare.ts
132
153
  var miniflare_exports = {};
133
- import {
134
- fetch as miniflareFetch,
135
- Headers as MiniflareHeaders,
136
- Request as MiniflareRequest,
137
- Response as MiniflareResponse
138
- } from "@miniflare/core";
154
+ __export(miniflare_exports, {
155
+ default: () => miniflare_default
156
+ });
157
+ var miniflare_default;
139
158
  var init_miniflare = __esm({
140
159
  "../pages-shared/environment-polyfills/miniflare.ts"() {
141
160
  init_environment_polyfills();
142
- polyfill({
143
- fetch: miniflareFetch,
144
- Headers: MiniflareHeaders,
145
- Request: MiniflareRequest,
146
- Response: MiniflareResponse
147
- });
161
+ miniflare_default = async () => {
162
+ const mf = await import("@miniflare/core");
163
+ polyfill({
164
+ fetch: mf.fetch,
165
+ Headers: mf.Headers,
166
+ Request: mf.Request,
167
+ Response: mf.Response
168
+ });
169
+ };
148
170
  }
149
171
  });
150
172
 
@@ -329,6 +351,15 @@ var init_rulesEngine = __esm({
329
351
  }
330
352
  });
331
353
 
354
+ // ../pages-shared/asset-server/url.ts
355
+ function stringifyURLToRootRelativePathname(url) {
356
+ return `${url.pathname}${url.search}${url.hash}`;
357
+ }
358
+ var init_url = __esm({
359
+ "../pages-shared/asset-server/url.ts"() {
360
+ }
361
+ });
362
+
332
363
  // ../pages-shared/asset-server/handler.ts
333
364
  var handler_exports = {};
334
365
  __export(handler_exports, {
@@ -339,6 +370,7 @@ __export(handler_exports, {
339
370
  HEADERS_VERSION_V1: () => HEADERS_VERSION_V1,
340
371
  REDIRECTS_VERSION: () => REDIRECTS_VERSION2,
341
372
  generateHandler: () => generateHandler,
373
+ getResponseFromMatch: () => getResponseFromMatch,
342
374
  normaliseHeaders: () => normaliseHeaders,
343
375
  parseQualityWeightedList: () => parseQualityWeightedList
344
376
  });
@@ -409,21 +441,10 @@ async function generateHandler({
409
441
  async function generateResponse() {
410
442
  const match = staticRedirectsMatcher() || generateRedirectsMatcher()({ request })[0];
411
443
  if (match) {
412
- const { status, to } = match;
413
- const destination = new URL(to, request.url);
414
- const location = destination.origin === new URL(request.url).origin ? `${destination.pathname}${destination.search || search}${destination.hash}` : `${destination.href}${destination.search ? "" : search}${destination.hash}`;
415
- switch (status) {
416
- case 301:
417
- return new MovedPermanentlyResponse(location);
418
- case 303:
419
- return new SeeOtherResponse(location);
420
- case 307:
421
- return new TemporaryRedirectResponse(location);
422
- case 308:
423
- return new PermanentRedirectResponse(location);
424
- case 302:
425
- default:
426
- return new FoundResponse(location);
444
+ if (match.status === 200) {
445
+ pathname = new URL(match.to, request.url).pathname;
446
+ } else {
447
+ return getResponseFromMatch(match, url);
427
448
  }
428
449
  }
429
450
  if (!request.method.match(/^(get|head)$/i)) {
@@ -652,7 +673,7 @@ async function generateHandler({
652
673
  return new HTMLRewriter().on("body", {
653
674
  element(e) {
654
675
  e.append(
655
- `<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'><\/script><!-- Cloudflare Pages Analytics -->`,
676
+ `<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'></script><!-- Cloudflare Pages Analytics -->`,
656
677
  { html: true }
657
678
  );
658
679
  }
@@ -703,6 +724,27 @@ async function generateHandler({
703
724
  );
704
725
  }
705
726
  }
727
+ function getResponseFromMatch({
728
+ status,
729
+ to
730
+ }, requestUrl) {
731
+ const destination = new URL(to, requestUrl);
732
+ destination.search = destination.search || requestUrl.search;
733
+ const location = destination.origin === requestUrl.origin ? stringifyURLToRootRelativePathname(destination) : destination.toString();
734
+ switch (status) {
735
+ case 301:
736
+ return new MovedPermanentlyResponse(location);
737
+ case 303:
738
+ return new SeeOtherResponse(location);
739
+ case 307:
740
+ return new TemporaryRedirectResponse(location);
741
+ case 308:
742
+ return new PermanentRedirectResponse(location);
743
+ case 302:
744
+ default:
745
+ return new FoundResponse(location);
746
+ }
747
+ }
706
748
  function parseQualityWeightedList(list = "") {
707
749
  const items = {};
708
750
  list.replace(/\s/g, "").split(",").forEach((el) => {
@@ -728,6 +770,7 @@ var init_handler = __esm({
728
770
  "../pages-shared/asset-server/handler.ts"() {
729
771
  init_responses();
730
772
  init_rulesEngine();
773
+ init_url();
731
774
  ASSET_PRESERVATION_CACHE = "assetPreservationCache";
732
775
  CACHE_CONTROL_PRESERVATION = "public, s-maxage=604800";
733
776
  CACHE_CONTROL_BROWSER = "public, max-age=0, must-revalidate";
@@ -749,8 +792,8 @@ import {
749
792
  Log as MiniflareLog,
750
793
  LogLevel as MiniflareLogLevel,
751
794
  Miniflare,
752
- Request as MiniflareRequest3,
753
- Response as MiniflareResponse3
795
+ Request as MiniflareRequest,
796
+ Response as MiniflareResponse
754
797
  } from "miniflare";
755
798
 
756
799
  // ../../node_modules/yargs/lib/platform-shims/esm.mjs
@@ -5576,7 +5619,7 @@ import { join } from "node:path";
5576
5619
  var REDIRECTS_VERSION = 1;
5577
5620
  var HEADERS_VERSION = 2;
5578
5621
  var ANALYTICS_VERSION = 1;
5579
- var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
5622
+ var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([200, 301, 302, 303, 307, 308]);
5580
5623
  var HEADER_SEPARATOR = ":";
5581
5624
  var MAX_LINE_LENGTH = 2e3;
5582
5625
  var MAX_HEADER_RULES = 100;
@@ -5632,7 +5675,11 @@ function constructRedirects({
5632
5675
  for (const rule of redirects.rules) {
5633
5676
  if (!rule.from.match(SPLAT_REGEX) && !rule.from.match(PLACEHOLDER_REGEX)) {
5634
5677
  if (canCreateStaticRule) {
5635
- staticRedirects[rule.from] = { status: rule.status, to: rule.to };
5678
+ staticRedirects[rule.from] = {
5679
+ status: rule.status,
5680
+ to: rule.to,
5681
+ lineNumber: rule.lineNumber
5682
+ };
5636
5683
  continue;
5637
5684
  } else {
5638
5685
  logger(
@@ -5951,7 +5998,7 @@ function parseRedirects(input) {
5951
5998
  invalid.push({
5952
5999
  line,
5953
6000
  lineNumber: i + 1,
5954
- message: `Valid status codes are 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
6001
+ message: `Valid status codes are 200, 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
5955
6002
  });
5956
6003
  continue;
5957
6004
  }
@@ -5964,6 +6011,19 @@ function parseRedirects(input) {
5964
6011
  continue;
5965
6012
  }
5966
6013
  seen_paths.add(from);
6014
+ if (status === 200) {
6015
+ const [proxyTo, error] = validateUrl(to, true, true, true);
6016
+ if (error) {
6017
+ invalid.push({
6018
+ line,
6019
+ lineNumber: i + 1,
6020
+ message: `Proxy (200) redirects can only point to relative paths. Got ${to}`
6021
+ });
6022
+ continue;
6023
+ }
6024
+ rules.push({ from, to: proxyTo, status, lineNumber: i + 1 });
6025
+ continue;
6026
+ }
5967
6027
  rules.push({ from, to, status, lineNumber: i + 1 });
5968
6028
  }
5969
6029
  return {
@@ -5974,14 +6034,9 @@ function parseRedirects(input) {
5974
6034
 
5975
6035
  // src/miniflare-cli/assets.ts
5976
6036
  var import_mime = __toESM(require_mime());
5977
- import { fetch as miniflareFetch2 } from "@miniflare/core";
5978
- import {
5979
- Response as MiniflareResponse2,
5980
- Request as MiniflareRequest2
5981
- } from "@miniflare/core";
5982
6037
  import { watch } from "chokidar";
5983
6038
 
5984
- // src/pages/hash.tsx
6039
+ // src/pages/hash.ts
5985
6040
  import { readFileSync as readFileSync4 } from "node:fs";
5986
6041
  import { extname as extname2 } from "node:path";
5987
6042
  import { hash as blake3hash } from "blake3-wasm";
@@ -5994,28 +6049,34 @@ var hashFile = (filepath) => {
5994
6049
 
5995
6050
  // src/miniflare-cli/assets.ts
5996
6051
  async function generateASSETSBinding(options) {
5997
- const assetsFetch = options.directory !== void 0 ? await generateAssetsFetch(options.directory, options.log) : invalidAssetsFetch;
6052
+ const assetsFetch = options.directory !== void 0 ? await generateAssetsFetch(options.directory, options.log, options.tre) : invalidAssetsFetch;
6053
+ const miniflare = options.tre ? await import("@miniflare/tre") : await import("@miniflare/core");
6054
+ const Request = miniflare.Request;
6055
+ const Response2 = miniflare.Response;
6056
+ const fetch2 = options.tre ? miniflare.fetch : (await import("@miniflare/web-sockets")).upgradingFetch;
5998
6057
  return async function(miniflareRequest) {
5999
6058
  if (options.proxyPort) {
6000
6059
  try {
6001
6060
  const url = new URL(miniflareRequest.url);
6002
6061
  url.host = `localhost:${options.proxyPort}`;
6003
- return await miniflareFetch2(url, miniflareRequest);
6062
+ const proxyRequest = new Request(url, miniflareRequest);
6063
+ if (proxyRequest.headers.get("Upgrade") === "websocket") {
6064
+ proxyRequest.headers.delete("Sec-WebSocket-Accept");
6065
+ proxyRequest.headers.delete("Sec-WebSocket-Key");
6066
+ }
6067
+ return await fetch2(proxyRequest);
6004
6068
  } catch (thrown) {
6005
6069
  options.log.error(new Error(`Could not proxy request: ${thrown}`));
6006
- return new MiniflareResponse2(
6007
- `[wrangler] Could not proxy request: ${thrown}`,
6008
- {
6009
- status: 502
6010
- }
6011
- );
6070
+ return new Response2(`[wrangler] Could not proxy request: ${thrown}`, {
6071
+ status: 502
6072
+ });
6012
6073
  }
6013
6074
  } else {
6014
6075
  try {
6015
6076
  return await assetsFetch(miniflareRequest);
6016
6077
  } catch (thrown) {
6017
6078
  options.log.error(new Error(`Could not serve static asset: ${thrown}`));
6018
- return new MiniflareResponse2(
6079
+ return new Response2(
6019
6080
  `[wrangler] Could not serve static asset: ${thrown}`,
6020
6081
  { status: 502 }
6021
6082
  );
@@ -6023,8 +6084,11 @@ async function generateASSETSBinding(options) {
6023
6084
  }
6024
6085
  };
6025
6086
  }
6026
- async function generateAssetsFetch(directory, log) {
6027
- await Promise.resolve().then(() => (init_miniflare(), miniflare_exports));
6087
+ async function generateAssetsFetch(directory, log, tre) {
6088
+ const polyfill2 = tre ? (await Promise.resolve().then(() => (init_miniflare_tre(), miniflare_tre_exports))).default : (await Promise.resolve().then(() => (init_miniflare(), miniflare_exports))).default;
6089
+ await polyfill2();
6090
+ const miniflare = tre ? await import("@miniflare/tre") : await import("@miniflare/core");
6091
+ const Request = miniflare.Request;
6028
6092
  const { generateHandler: generateHandler2, parseQualityWeightedList: parseQualityWeightedList2 } = await Promise.resolve().then(() => (init_handler(), handler_exports));
6029
6093
  const headersFile = join(directory, "_headers");
6030
6094
  const redirectsFile = join(directory, "_redirects");
@@ -6105,7 +6169,7 @@ async function generateAssetsFetch(directory, log) {
6105
6169
  const filepath = assetKeyEntryMap.get(assetKey);
6106
6170
  if (!filepath) {
6107
6171
  throw new Error(
6108
- "Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/wrangler2/issues/new/choose) with reproduction steps."
6172
+ "Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/workers-sdk/issues/new/choose) with reproduction steps."
6109
6173
  );
6110
6174
  }
6111
6175
  const body = readFileSync5(filepath);
@@ -6118,7 +6182,7 @@ async function generateAssetsFetch(directory, log) {
6118
6182
  });
6119
6183
  };
6120
6184
  return async (input, init) => {
6121
- const request = new MiniflareRequest2(input, init);
6185
+ const request = new Request(input, init);
6122
6186
  return await generateResponse(request);
6123
6187
  };
6124
6188
  }
@@ -6166,7 +6230,7 @@ async function main() {
6166
6230
  if (logLevelString === "LOG")
6167
6231
  logLevelString = "INFO";
6168
6232
  const logLevel = MiniflareLogLevel[logLevelString];
6169
- config.log = logLevel === MiniflareLogLevel.NONE ? new MiniflareNoOpLog() : new MiniflareLog(logLevel, config.logOptions);
6233
+ config.log = logLevel === MiniflareLogLevel.NONE ? new MiniflareNoOpLog() : new MiniflareLog(logLevel);
6170
6234
  if (logLevel === MiniflareLogLevel.DEBUG) {
6171
6235
  console.log("MINIFLARE OPTIONS:\n", JSON.stringify(config, null, 2));
6172
6236
  }
@@ -6186,12 +6250,12 @@ async function main() {
6186
6250
  namespace.get = (id) => {
6187
6251
  const stub = new DurableObjectStub(factory, id);
6188
6252
  stub.fetch = (...reqArgs) => {
6189
- const requestFromArgs = new MiniflareRequest3(...reqArgs);
6253
+ const requestFromArgs = new MiniflareRequest(...reqArgs);
6190
6254
  const url = new URL(requestFromArgs.url);
6191
6255
  url.host = host;
6192
6256
  if (port !== void 0)
6193
6257
  url.port = port.toString();
6194
- const request = new MiniflareRequest3(
6258
+ const request = new MiniflareRequest(
6195
6259
  url.toString(),
6196
6260
  requestFromArgs
6197
6261
  );
@@ -6224,7 +6288,8 @@ async function main() {
6224
6288
  const options = {
6225
6289
  log: config.log,
6226
6290
  proxyPort: opts.proxyPort,
6227
- directory: opts.directory
6291
+ directory: opts.directory,
6292
+ tre: false
6228
6293
  };
6229
6294
  config.serviceBindings = {
6230
6295
  ...config.serviceBindings,
@@ -6250,7 +6315,7 @@ async function main() {
6250
6315
  }`,
6251
6316
  serviceBindings: {
6252
6317
  DO: async (request) => {
6253
- request = new MiniflareRequest3(request);
6318
+ request = new MiniflareRequest(request);
6254
6319
  const name = request.headers.get("x-miniflare-durable-object-name");
6255
6320
  const idString = request.headers.get(
6256
6321
  "x-miniflare-durable-object-id"
@@ -6258,7 +6323,7 @@ async function main() {
6258
6323
  request.headers.delete("x-miniflare-durable-object-name");
6259
6324
  request.headers.delete("x-miniflare-durable-object-id");
6260
6325
  if (!name || !idString) {
6261
- return new MiniflareResponse3(
6326
+ return new MiniflareResponse(
6262
6327
  "[durable-object-proxy-err] Missing `x-miniflare-durable-object-name` or `x-miniflare-durable-object-id` headers.",
6263
6328
  { status: 400 }
6264
6329
  );
@@ -6266,14 +6331,14 @@ async function main() {
6266
6331
  const namespace = await mf?.getDurableObjectNamespace(name);
6267
6332
  const id = namespace?.idFromString(idString);
6268
6333
  if (!id) {
6269
- return new MiniflareResponse3(
6334
+ return new MiniflareResponse(
6270
6335
  "[durable-object-proxy-err] Could not generate an ID. Possibly due to a mismatched DO name and ID?",
6271
6336
  { status: 500 }
6272
6337
  );
6273
6338
  }
6274
6339
  const stub = namespace?.get(id);
6275
6340
  if (!stub) {
6276
- return new MiniflareResponse3(
6341
+ return new MiniflareResponse(
6277
6342
  "[durable-object-proxy-err] Could not generate a stub. Possibly due to a mismatched DO name and ID?",
6278
6343
  { status: 500 }
6279
6344
  );
@@ -6288,7 +6353,7 @@ async function main() {
6288
6353
  }
6289
6354
  process.send && process.send(
6290
6355
  JSON.stringify({
6291
- mfPort,
6356
+ port: mfPort,
6292
6357
  ready: true,
6293
6358
  durableObjectsPort: durableObjectsMfPort
6294
6359
  })
@@ -6301,16 +6366,3 @@ async function main() {
6301
6366
  }
6302
6367
  }
6303
6368
  await main();
6304
- /**
6305
- * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
6306
- * CJS and ESM environments.
6307
- *
6308
- * @license
6309
- * Copyright (c) 2016, Contributors
6310
- * SPDX-License-Identifier: ISC
6311
- */
6312
- /**
6313
- * @license
6314
- * Copyright (c) 2016, Contributors
6315
- * SPDX-License-Identifier: ISC
6316
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-e7a0cd5b",
3
+ "version": "0.0.0-e7cf0caa",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -24,13 +24,13 @@
24
24
  "http",
25
25
  "cli"
26
26
  ],
27
- "homepage": "https://github.com/cloudflare/wrangler2#readme",
27
+ "homepage": "https://github.com/cloudflare/workers-sdk#readme",
28
28
  "bugs": {
29
- "url": "https://github.com/cloudflare/wrangler2/issues"
29
+ "url": "https://github.com/cloudflare/workers-sdk/issues"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "https://github.com/cloudflare/wrangler2.git",
33
+ "url": "https://github.com/cloudflare/workers-sdk.git",
34
34
  "directory": "packages/wrangler"
35
35
  },
36
36
  "license": "MIT OR Apache-2.0",
@@ -57,15 +57,17 @@
57
57
  "assert-git-version": "node -r esbuild-register scripts/assert-git-version.ts",
58
58
  "build": "npm run clean && npm run bundle && npm run emit-types",
59
59
  "bundle": "node -r esbuild-register scripts/bundle.ts",
60
- "check:type": "tsc",
60
+ "check:type": "node -r esbuild-register scripts/tsc-all.ts",
61
61
  "clean": "rimraf wrangler-dist miniflare-dist emitted-types",
62
62
  "dev": "npm run clean && concurrently -c black,blue --kill-others-on-fail false 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
63
63
  "emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
64
64
  "prepublishOnly": "SOURCEMAPS=false npm run build",
65
65
  "start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
66
- "test": "npm run assert-git-version && jest --silent=false --verbose=true",
66
+ "test": "npm run assert-git-version && jest",
67
67
  "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
68
- "test:ci": "npm run test -- --verbose=true --coverage"
68
+ "test:ci": "npm run test -- --coverage",
69
+ "test:debug": "npm run test -- --silent=false --verbose=true",
70
+ "test:e2e": "vitest --no-threads ./e2e"
69
71
  },
70
72
  "jest": {
71
73
  "coverageReporters": [
@@ -82,7 +84,7 @@
82
84
  "setupFilesAfterEnv": [
83
85
  "<rootDir>/src/__tests__/jest.setup.ts"
84
86
  ],
85
- "testRegex": ".*.(test|spec)\\.[jt]sx?$",
87
+ "testRegex": "src/__tests__/.*\\.(test|spec)\\.[jt]sx?$",
86
88
  "testTimeout": 30000,
87
89
  "transform": {
88
90
  "^.+\\.c?(t|j)sx?$": [
@@ -100,13 +102,13 @@
100
102
  "@cloudflare/kv-asset-handler": "^0.2.0",
101
103
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
102
104
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
103
- "@miniflare/core": "2.10.0",
104
- "@miniflare/d1": "2.10.0",
105
- "@miniflare/durable-objects": "2.10.0",
105
+ "@miniflare/core": "2.13.0",
106
+ "@miniflare/d1": "2.13.0",
107
+ "@miniflare/durable-objects": "2.13.0",
106
108
  "blake3-wasm": "^2.1.5",
107
109
  "chokidar": "^3.5.3",
108
- "esbuild": "0.14.51",
109
- "miniflare": "2.10.0",
110
+ "esbuild": "0.16.3",
111
+ "miniflare": "2.13.0",
110
112
  "nanoid": "^3.3.3",
111
113
  "path-to-regexp": "^6.2.0",
112
114
  "selfsigned": "^2.0.1",
@@ -114,11 +116,11 @@
114
116
  "xxhash-wasm": "^1.0.1"
115
117
  },
116
118
  "devDependencies": {
117
- "@databases/split-sql-query": "^1.0.3",
118
- "@databases/sql": "^3.2.0",
119
+ "@cloudflare/types": "^6.18.4",
120
+ "@cloudflare/workers-types": "^4.20221111.1",
119
121
  "@iarna/toml": "^3.0.0",
120
122
  "@microsoft/api-extractor": "^7.28.3",
121
- "@miniflare/tre": "3.0.0-next.2",
123
+ "@miniflare/tre": "3.0.0-next.12",
122
124
  "@types/better-sqlite3": "^7.6.0",
123
125
  "@types/busboy": "^1.5.0",
124
126
  "@types/command-exists": "^1.2.0",
@@ -135,6 +137,8 @@
135
137
  "@types/yargs": "^17.0.10",
136
138
  "@webcontainer/env": "^1.0.1",
137
139
  "body-parser": "^1.20.0",
140
+ "chalk": "^2.4.2",
141
+ "cli-table3": "^0.6.3",
138
142
  "clipboardy": "^3.0.0",
139
143
  "cmd-shim": "^4.1.0",
140
144
  "command-exists": "^1.2.9",
@@ -161,7 +165,7 @@
161
165
  "jest-websocket-mock": "^2.3.0",
162
166
  "mime": "^3.0.0",
163
167
  "minimatch": "^5.1.0",
164
- "msw": "^0.47.1",
168
+ "msw": "^0.49.1",
165
169
  "npx-import": "^1.1.3",
166
170
  "open": "^8.4.0",
167
171
  "p-queue": "^7.2.0",
@@ -172,16 +176,20 @@
172
176
  "remove-accents-esm": "^0.0.1",
173
177
  "semiver": "^1.1.0",
174
178
  "serve-static": "^1.15.0",
179
+ "shellac": "^0.7.3",
175
180
  "signal-exit": "^3.0.7",
181
+ "strip-ansi": "^7.0.1",
176
182
  "supports-color": "^9.2.2",
177
183
  "timeago.js": "^4.0.2",
178
184
  "tmp-promise": "^3.0.3",
179
185
  "ts-dedent": "^2.2.0",
180
- "undici": "^5.11.0",
186
+ "undici": "5.20.0",
181
187
  "update-check": "^1.5.4",
188
+ "vitest": "^0.29.2",
182
189
  "ws": "^8.5.0",
183
190
  "xdg-app-paths": "^7.3.0",
184
- "yargs": "^17.4.1"
191
+ "yargs": "^17.4.1",
192
+ "yoga-layout": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz"
185
193
  },
186
194
  "optionalDependencies": {
187
195
  "fsevents": "~2.3.2"