wrangler 0.0.0-ab52f771 → 0.0.0-abcff41e

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 (227) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +29 -9
  3. package/miniflare-dist/index.mjs +128 -74
  4. package/package.json +20 -16
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +64 -35
  7. package/src/__tests__/api-devregistry.test.js +12 -4
  8. package/src/__tests__/configuration.test.ts +392 -23
  9. package/src/__tests__/d1/d1.test.ts +82 -0
  10. package/src/__tests__/d1/execute.test.ts +64 -0
  11. package/src/__tests__/d1/migrate.test.ts +155 -0
  12. package/src/__tests__/d1/splitter.test.ts +255 -0
  13. package/src/__tests__/delete.test.ts +85 -49
  14. package/src/__tests__/deployments.test.ts +70 -32
  15. package/src/__tests__/dev.test.tsx +278 -48
  16. package/src/__tests__/generate.test.ts +11 -8
  17. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  18. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  19. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  20. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  23. package/src/__tests__/helpers/mock-kv.ts +29 -16
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
  25. package/src/__tests__/helpers/mock-process.ts +8 -13
  26. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  27. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  28. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  29. package/src/__tests__/helpers/msw/handlers/deployments.ts +63 -50
  30. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  31. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  32. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  33. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  34. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  35. package/src/__tests__/helpers/msw/handlers/zones.ts +20 -0
  36. package/src/__tests__/helpers/msw/index.ts +34 -1
  37. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  38. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  39. package/src/__tests__/index.test.ts +108 -87
  40. package/src/__tests__/init.test.ts +878 -530
  41. package/src/__tests__/jest.setup.ts +26 -42
  42. package/src/__tests__/kv.test.ts +685 -561
  43. package/src/__tests__/logout.test.ts +47 -0
  44. package/src/__tests__/metrics.test.ts +94 -51
  45. package/src/__tests__/middleware.scheduled.test.ts +40 -30
  46. package/src/__tests__/middleware.test.ts +209 -120
  47. package/src/__tests__/mtls-certificates.test.ts +585 -0
  48. package/src/__tests__/pages/deployment-list.test.ts +78 -0
  49. package/src/__tests__/pages/functions-build.test.ts +402 -0
  50. package/src/__tests__/pages/pages.test.ts +81 -0
  51. package/src/__tests__/pages/project-create.test.ts +63 -0
  52. package/src/__tests__/pages/project-list.test.ts +108 -0
  53. package/src/__tests__/pages/project-upload.test.ts +481 -0
  54. package/src/__tests__/pages/publish.test.ts +2745 -0
  55. package/src/__tests__/pages-deployment-tail.test.ts +955 -0
  56. package/src/__tests__/parse.test.ts +106 -0
  57. package/src/__tests__/publish.test.ts +2137 -1108
  58. package/src/__tests__/pubsub.test.ts +223 -97
  59. package/src/__tests__/queues.test.ts +529 -0
  60. package/src/__tests__/r2.test.ts +92 -89
  61. package/src/__tests__/secret.test.ts +179 -130
  62. package/src/__tests__/tail.test.ts +267 -109
  63. package/src/__tests__/tsconfig-sanity.ts +12 -0
  64. package/src/__tests__/tsconfig.json +8 -0
  65. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  66. package/src/__tests__/type-generation.test.ts +42 -26
  67. package/src/__tests__/user.test.ts +34 -71
  68. package/src/__tests__/whoami.test.tsx +8 -114
  69. package/src/__tests__/worker-namespace.test.ts +89 -71
  70. package/src/api/dev.ts +162 -42
  71. package/src/api/index.ts +10 -1
  72. package/src/api/mtls-certificate.ts +148 -0
  73. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  74. package/src/api/pages/index.ts +5 -0
  75. package/src/api/pages/publish.tsx +368 -0
  76. package/src/bundle-reporter.ts +68 -0
  77. package/src/bundle.ts +282 -162
  78. package/src/cfetch/index.ts +0 -2
  79. package/src/cfetch/internal.ts +16 -21
  80. package/src/cli.ts +4 -5
  81. package/src/config/config.ts +14 -7
  82. package/src/config/environment.ts +93 -12
  83. package/src/config/index.ts +109 -27
  84. package/src/config/validation.ts +272 -4
  85. package/src/create-worker-preview.ts +10 -3
  86. package/src/create-worker-upload-form.ts +42 -9
  87. package/src/d1/backups.tsx +33 -30
  88. package/src/d1/constants.ts +2 -0
  89. package/src/d1/create.tsx +24 -14
  90. package/src/d1/{delete.tsx → delete.ts} +11 -14
  91. package/src/d1/execute.tsx +236 -176
  92. package/src/d1/index.ts +31 -6
  93. package/src/d1/list.tsx +21 -9
  94. package/src/d1/migrations/apply.tsx +206 -0
  95. package/src/d1/migrations/create.tsx +76 -0
  96. package/src/d1/migrations/helpers.ts +172 -0
  97. package/src/d1/migrations/index.ts +3 -0
  98. package/src/d1/migrations/list.tsx +92 -0
  99. package/src/d1/migrations/options.ts +23 -0
  100. package/src/d1/options.ts +12 -2
  101. package/src/d1/splitter.ts +161 -0
  102. package/src/d1/{types.tsx → types.ts} +11 -0
  103. package/src/d1/utils.ts +12 -2
  104. package/src/delete.ts +11 -22
  105. package/src/deployments.ts +116 -0
  106. package/src/deprecated/index.ts +11 -320
  107. package/src/dev/dev-vars.ts +11 -8
  108. package/src/dev/dev.tsx +65 -40
  109. package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  110. package/src/dev/local.tsx +316 -84
  111. package/src/dev/remote.tsx +34 -3
  112. package/src/dev/start-server.ts +85 -53
  113. package/src/dev/use-esbuild.ts +18 -10
  114. package/src/{dev-registry.tsx → dev-registry.ts} +0 -0
  115. package/src/dev.tsx +160 -111
  116. package/src/dialogs.ts +136 -0
  117. package/src/dispatch-namespace.ts +23 -18
  118. package/src/docs/index.ts +97 -0
  119. package/src/entry.ts +1 -2
  120. package/src/environment-variables/factory.ts +88 -0
  121. package/src/environment-variables/misc-variables.ts +30 -0
  122. package/src/generate/index.ts +298 -0
  123. package/src/git-client.ts +15 -4
  124. package/src/{index.tsx → index.ts} +121 -84
  125. package/src/init.ts +116 -64
  126. package/src/inspect.ts +21 -1
  127. package/src/is-interactive.ts +4 -0
  128. package/src/jest.d.ts +4 -0
  129. package/src/kv/index.ts +15 -66
  130. package/src/logger.ts +27 -3
  131. package/src/metrics/metrics-config.ts +3 -3
  132. package/src/metrics/send-event.ts +5 -1
  133. package/src/miniflare-cli/assets.ts +64 -29
  134. package/src/miniflare-cli/index.ts +3 -6
  135. package/src/miniflare-cli/tsconfig.json +9 -0
  136. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  137. package/src/miniflare-cli/types.ts +11 -0
  138. package/src/mtls-certificate/cli.ts +155 -0
  139. package/src/pages/build.ts +232 -0
  140. package/src/pages/buildFunctions.ts +130 -0
  141. package/src/pages/constants.ts +2 -0
  142. package/src/pages/deployment-tails.ts +281 -0
  143. package/src/pages/deployments.tsx +9 -29
  144. package/src/pages/{dev.tsx → dev.ts} +143 -120
  145. package/src/pages/functions/buildPlugin.ts +68 -88
  146. package/src/pages/functions/buildWorker.ts +241 -109
  147. package/src/pages/functions/tsconfig.json +8 -0
  148. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  149. package/src/pages/{functions.tsx → functions.ts} +8 -4
  150. package/src/pages/{hash.tsx → hash.ts} +0 -0
  151. package/src/pages/{index.tsx → index.ts} +11 -3
  152. package/src/pages/projects.tsx +10 -17
  153. package/src/pages/prompt-select-project.tsx +31 -0
  154. package/src/pages/publish.tsx +54 -214
  155. package/src/pages/types.ts +6 -9
  156. package/src/pages/upload.tsx +76 -25
  157. package/src/pages/utils.ts +14 -3
  158. package/src/parse.ts +23 -1
  159. package/src/proxy.ts +43 -6
  160. package/src/publish/index.ts +27 -20
  161. package/src/publish/publish.ts +190 -38
  162. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +20 -20
  163. package/src/queues/cli/commands/consumer/add.ts +65 -0
  164. package/src/queues/cli/commands/consumer/index.ts +19 -0
  165. package/src/queues/cli/commands/consumer/remove.ts +31 -0
  166. package/src/queues/cli/commands/create.ts +25 -0
  167. package/src/queues/cli/commands/delete.ts +26 -0
  168. package/src/queues/cli/commands/index.ts +35 -0
  169. package/src/queues/cli/commands/list.ts +25 -0
  170. package/src/queues/client.ts +135 -0
  171. package/src/queues/utils.ts +18 -0
  172. package/src/r2/constants.ts +4 -0
  173. package/src/r2/index.ts +40 -28
  174. package/src/secret/index.ts +21 -49
  175. package/src/{sites.tsx → sites.ts} +1 -1
  176. package/src/tail/createTail.ts +94 -3
  177. package/src/tail/filters.ts +1 -1
  178. package/src/tail/index.ts +10 -16
  179. package/src/tail/printing.ts +15 -0
  180. package/src/tsconfig-sanity.ts +16 -0
  181. package/src/type-generation.ts +78 -56
  182. package/src/user/access.ts +68 -0
  183. package/src/user/auth-variables.ts +113 -0
  184. package/src/user/choose-account.tsx +1 -31
  185. package/src/user/index.ts +0 -1
  186. package/src/user/{user.tsx → user.ts} +122 -81
  187. package/src/{whoami.tsx → whoami.ts} +37 -71
  188. package/src/worker.ts +24 -1
  189. package/src/yargs-types.ts +33 -3
  190. package/src/zones.ts +31 -5
  191. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  192. package/templates/__tests__/tsconfig.json +8 -0
  193. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  194. package/templates/checked-fetch.js +9 -3
  195. package/templates/d1-beta-facade.js +90 -23
  196. package/templates/facade.d.ts +14 -0
  197. package/templates/first-party-worker-module-facade.ts +4 -3
  198. package/templates/format-dev-errors.ts +8 -6
  199. package/templates/init-tests/test-jest-new-worker.js +3 -5
  200. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  201. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  202. package/templates/middleware/loader-modules.ts +2 -2
  203. package/templates/middleware/loader-sw.ts +51 -31
  204. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  205. package/templates/new-worker.ts +3 -0
  206. package/templates/pages-dev-pipeline.ts +4 -1
  207. package/templates/pages-shim.ts +4 -1
  208. package/templates/pages-template-plugin.ts +12 -7
  209. package/templates/serve-static-assets.ts +17 -14
  210. package/templates/service-bindings-module-facade.js +1 -0
  211. package/templates/tsconfig-sanity.ts +11 -0
  212. package/templates/tsconfig.init.json +106 -0
  213. package/templates/tsconfig.json +5 -103
  214. package/templates/tsconfig.tsbuildinfo +1 -0
  215. package/wrangler-dist/cli.d.ts +333 -68
  216. package/wrangler-dist/cli.js +53196 -69350
  217. package/wrangler-dist/wasm-sync.wasm +0 -0
  218. package/src/__tests__/d1.test.ts +0 -70
  219. package/src/__tests__/dialogs.test.tsx +0 -40
  220. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  221. package/src/__tests__/pages.test.ts +0 -2111
  222. package/src/bundle-reporter.tsx +0 -29
  223. package/src/dialogs.tsx +0 -163
  224. package/src/environment-variables.ts +0 -50
  225. package/src/pages/build.tsx +0 -238
  226. package/src/user/env-vars.ts +0 -46
  227. package/templates/experimental-local-cache-stubs.js +0 -27
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
@@ -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;
@@ -5592,6 +5635,7 @@ function createMetadataObject({
5592
5635
  headers,
5593
5636
  webAnalyticsToken,
5594
5637
  deploymentId,
5638
+ failOpen,
5595
5639
  logger = (_message) => {
5596
5640
  }
5597
5641
  }) {
@@ -5599,7 +5643,8 @@ function createMetadataObject({
5599
5643
  ...constructRedirects({ redirects, logger }),
5600
5644
  ...constructHeaders({ headers, logger }),
5601
5645
  ...constructWebAnalytics({ webAnalyticsToken, logger }),
5602
- deploymentId
5646
+ deploymentId,
5647
+ failOpen
5603
5648
  };
5604
5649
  }
5605
5650
  function constructRedirects({
@@ -5630,7 +5675,11 @@ function constructRedirects({
5630
5675
  for (const rule of redirects.rules) {
5631
5676
  if (!rule.from.match(SPLAT_REGEX) && !rule.from.match(PLACEHOLDER_REGEX)) {
5632
5677
  if (canCreateStaticRule) {
5633
- 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
+ };
5634
5683
  continue;
5635
5684
  } else {
5636
5685
  logger(
@@ -5949,7 +5998,7 @@ function parseRedirects(input) {
5949
5998
  invalid.push({
5950
5999
  line,
5951
6000
  lineNumber: i + 1,
5952
- 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}.`
5953
6002
  });
5954
6003
  continue;
5955
6004
  }
@@ -5962,6 +6011,19 @@ function parseRedirects(input) {
5962
6011
  continue;
5963
6012
  }
5964
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
+ }
5965
6027
  rules.push({ from, to, status, lineNumber: i + 1 });
5966
6028
  }
5967
6029
  return {
@@ -5972,14 +6034,9 @@ function parseRedirects(input) {
5972
6034
 
5973
6035
  // src/miniflare-cli/assets.ts
5974
6036
  var import_mime = __toESM(require_mime());
5975
- import { fetch as miniflareFetch2 } from "@miniflare/core";
5976
- import {
5977
- Response as MiniflareResponse2,
5978
- Request as MiniflareRequest2
5979
- } from "@miniflare/core";
5980
6037
  import { watch } from "chokidar";
5981
6038
 
5982
- // src/pages/hash.tsx
6039
+ // src/pages/hash.ts
5983
6040
  import { readFileSync as readFileSync4 } from "node:fs";
5984
6041
  import { extname as extname2 } from "node:path";
5985
6042
  import { hash as blake3hash } from "blake3-wasm";
@@ -5992,28 +6049,34 @@ var hashFile = (filepath) => {
5992
6049
 
5993
6050
  // src/miniflare-cli/assets.ts
5994
6051
  async function generateASSETSBinding(options) {
5995
- 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;
5996
6057
  return async function(miniflareRequest) {
5997
6058
  if (options.proxyPort) {
5998
6059
  try {
5999
6060
  const url = new URL(miniflareRequest.url);
6000
6061
  url.host = `localhost:${options.proxyPort}`;
6001
- 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);
6002
6068
  } catch (thrown) {
6003
6069
  options.log.error(new Error(`Could not proxy request: ${thrown}`));
6004
- return new MiniflareResponse2(
6005
- `[wrangler] Could not proxy request: ${thrown}`,
6006
- {
6007
- status: 502
6008
- }
6009
- );
6070
+ return new Response2(`[wrangler] Could not proxy request: ${thrown}`, {
6071
+ status: 502
6072
+ });
6010
6073
  }
6011
6074
  } else {
6012
6075
  try {
6013
6076
  return await assetsFetch(miniflareRequest);
6014
6077
  } catch (thrown) {
6015
6078
  options.log.error(new Error(`Could not serve static asset: ${thrown}`));
6016
- return new MiniflareResponse2(
6079
+ return new Response2(
6017
6080
  `[wrangler] Could not serve static asset: ${thrown}`,
6018
6081
  { status: 502 }
6019
6082
  );
@@ -6021,8 +6084,11 @@ async function generateASSETSBinding(options) {
6021
6084
  }
6022
6085
  };
6023
6086
  }
6024
- async function generateAssetsFetch(directory, log) {
6025
- 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;
6026
6092
  const { generateHandler: generateHandler2, parseQualityWeightedList: parseQualityWeightedList2 } = await Promise.resolve().then(() => (init_handler(), handler_exports));
6027
6093
  const headersFile = join(directory, "_headers");
6028
6094
  const redirectsFile = join(directory, "_redirects");
@@ -6103,7 +6169,7 @@ async function generateAssetsFetch(directory, log) {
6103
6169
  const filepath = assetKeyEntryMap.get(assetKey);
6104
6170
  if (!filepath) {
6105
6171
  throw new Error(
6106
- "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."
6107
6173
  );
6108
6174
  }
6109
6175
  const body = readFileSync5(filepath);
@@ -6116,7 +6182,7 @@ async function generateAssetsFetch(directory, log) {
6116
6182
  });
6117
6183
  };
6118
6184
  return async (input, init) => {
6119
- const request = new MiniflareRequest2(input, init);
6185
+ const request = new Request(input, init);
6120
6186
  return await generateResponse(request);
6121
6187
  };
6122
6188
  }
@@ -6184,12 +6250,12 @@ async function main() {
6184
6250
  namespace.get = (id) => {
6185
6251
  const stub = new DurableObjectStub(factory, id);
6186
6252
  stub.fetch = (...reqArgs) => {
6187
- const requestFromArgs = new MiniflareRequest3(...reqArgs);
6253
+ const requestFromArgs = new MiniflareRequest(...reqArgs);
6188
6254
  const url = new URL(requestFromArgs.url);
6189
6255
  url.host = host;
6190
6256
  if (port !== void 0)
6191
6257
  url.port = port.toString();
6192
- const request = new MiniflareRequest3(
6258
+ const request = new MiniflareRequest(
6193
6259
  url.toString(),
6194
6260
  requestFromArgs
6195
6261
  );
@@ -6222,7 +6288,8 @@ async function main() {
6222
6288
  const options = {
6223
6289
  log: config.log,
6224
6290
  proxyPort: opts.proxyPort,
6225
- directory: opts.directory
6291
+ directory: opts.directory,
6292
+ tre: false
6226
6293
  };
6227
6294
  config.serviceBindings = {
6228
6295
  ...config.serviceBindings,
@@ -6248,7 +6315,7 @@ async function main() {
6248
6315
  }`,
6249
6316
  serviceBindings: {
6250
6317
  DO: async (request) => {
6251
- request = new MiniflareRequest3(request);
6318
+ request = new MiniflareRequest(request);
6252
6319
  const name = request.headers.get("x-miniflare-durable-object-name");
6253
6320
  const idString = request.headers.get(
6254
6321
  "x-miniflare-durable-object-id"
@@ -6256,7 +6323,7 @@ async function main() {
6256
6323
  request.headers.delete("x-miniflare-durable-object-name");
6257
6324
  request.headers.delete("x-miniflare-durable-object-id");
6258
6325
  if (!name || !idString) {
6259
- return new MiniflareResponse3(
6326
+ return new MiniflareResponse(
6260
6327
  "[durable-object-proxy-err] Missing `x-miniflare-durable-object-name` or `x-miniflare-durable-object-id` headers.",
6261
6328
  { status: 400 }
6262
6329
  );
@@ -6264,14 +6331,14 @@ async function main() {
6264
6331
  const namespace = await mf?.getDurableObjectNamespace(name);
6265
6332
  const id = namespace?.idFromString(idString);
6266
6333
  if (!id) {
6267
- return new MiniflareResponse3(
6334
+ return new MiniflareResponse(
6268
6335
  "[durable-object-proxy-err] Could not generate an ID. Possibly due to a mismatched DO name and ID?",
6269
6336
  { status: 500 }
6270
6337
  );
6271
6338
  }
6272
6339
  const stub = namespace?.get(id);
6273
6340
  if (!stub) {
6274
- return new MiniflareResponse3(
6341
+ return new MiniflareResponse(
6275
6342
  "[durable-object-proxy-err] Could not generate a stub. Possibly due to a mismatched DO name and ID?",
6276
6343
  { status: 500 }
6277
6344
  );
@@ -6286,7 +6353,7 @@ async function main() {
6286
6353
  }
6287
6354
  process.send && process.send(
6288
6355
  JSON.stringify({
6289
- mfPort,
6356
+ port: mfPort,
6290
6357
  ready: true,
6291
6358
  durableObjectsPort: durableObjectsMfPort
6292
6359
  })
@@ -6299,16 +6366,3 @@ async function main() {
6299
6366
  }
6300
6367
  }
6301
6368
  await main();
6302
- /**
6303
- * @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
6304
- * CJS and ESM environments.
6305
- *
6306
- * @license
6307
- * Copyright (c) 2016, Contributors
6308
- * SPDX-License-Identifier: ISC
6309
- */
6310
- /**
6311
- * @license
6312
- * Copyright (c) 2016, Contributors
6313
- * SPDX-License-Identifier: ISC
6314
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-ab52f771",
3
+ "version": "0.0.0-abcff41e",
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,7 +57,7 @@
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",
@@ -100,13 +100,13 @@
100
100
  "@cloudflare/kv-asset-handler": "^0.2.0",
101
101
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
102
102
  "@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",
103
+ "@miniflare/core": "2.12.0",
104
+ "@miniflare/d1": "2.12.0",
105
+ "@miniflare/durable-objects": "2.12.0",
106
106
  "blake3-wasm": "^2.1.5",
107
107
  "chokidar": "^3.5.3",
108
- "esbuild": "0.14.51",
109
- "miniflare": "2.10.0",
108
+ "esbuild": "0.16.3",
109
+ "miniflare": "2.12.0",
110
110
  "nanoid": "^3.3.3",
111
111
  "path-to-regexp": "^6.2.0",
112
112
  "selfsigned": "^2.0.1",
@@ -114,11 +114,11 @@
114
114
  "xxhash-wasm": "^1.0.1"
115
115
  },
116
116
  "devDependencies": {
117
- "@databases/split-sql-query": "^1.0.3",
118
- "@databases/sql": "^3.2.0",
117
+ "@cloudflare/types": "^6.18.4",
118
+ "@cloudflare/workers-types": "^4.20221111.1",
119
119
  "@iarna/toml": "^3.0.0",
120
120
  "@microsoft/api-extractor": "^7.28.3",
121
- "@miniflare/tre": "3.0.0-next.2",
121
+ "@miniflare/tre": "^3.0.0-next.8",
122
122
  "@types/better-sqlite3": "^7.6.0",
123
123
  "@types/busboy": "^1.5.0",
124
124
  "@types/command-exists": "^1.2.0",
@@ -135,6 +135,8 @@
135
135
  "@types/yargs": "^17.0.10",
136
136
  "@webcontainer/env": "^1.0.1",
137
137
  "body-parser": "^1.20.0",
138
+ "chalk": "^2.4.2",
139
+ "cli-table3": "^0.6.3",
138
140
  "clipboardy": "^3.0.0",
139
141
  "cmd-shim": "^4.1.0",
140
142
  "command-exists": "^1.2.9",
@@ -160,7 +162,8 @@
160
162
  "jest-fetch-mock": "^3.0.3",
161
163
  "jest-websocket-mock": "^2.3.0",
162
164
  "mime": "^3.0.0",
163
- "msw": "^0.47.1",
165
+ "minimatch": "^5.1.0",
166
+ "msw": "^0.49.1",
164
167
  "npx-import": "^1.1.3",
165
168
  "open": "^8.4.0",
166
169
  "p-queue": "^7.2.0",
@@ -176,11 +179,12 @@
176
179
  "timeago.js": "^4.0.2",
177
180
  "tmp-promise": "^3.0.3",
178
181
  "ts-dedent": "^2.2.0",
179
- "undici": "^5.11.0",
182
+ "undici": "5.11.0",
180
183
  "update-check": "^1.5.4",
181
184
  "ws": "^8.5.0",
182
185
  "xdg-app-paths": "^7.3.0",
183
- "yargs": "^17.4.1"
186
+ "yargs": "^17.4.1",
187
+ "yoga-layout": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz"
184
188
  },
185
189
  "optionalDependencies": {
186
190
  "fsevents": "~2.3.2"
@@ -0,0 +1,25 @@
1
+ import { domainUsesAccess, getAccessToken } from "../user/access";
2
+ import { msw, mswAccessHandlers } from "./helpers/msw";
3
+
4
+ describe("access", () => {
5
+ beforeEach(() => {
6
+ msw.use(...mswAccessHandlers);
7
+ });
8
+
9
+ describe("basic", () => {
10
+ it("should correctly detect an access protected domain", async () => {
11
+ expect(await domainUsesAccess("access-protected.com")).toBeTruthy();
12
+ expect(await domainUsesAccess("not-access-protected.com")).toBeFalsy();
13
+ });
14
+ it("should not fail without cloudflared installed", async () => {
15
+ expect(await getAccessToken("not-access-protected.com")).toBeFalsy();
16
+ });
17
+ it("should error without cloudflared installed on an access protected domain", async () => {
18
+ await expect(getAccessToken("access-protected.com")).rejects.toEqual(
19
+ new Error(
20
+ "To use Wrangler with Cloudflare Access, please install `cloudflared` from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"
21
+ )
22
+ );
23
+ });
24
+ });
25
+ });