wrangler 0.0.0-dee034b → 0.0.0-df6fea02

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 (220) hide show
  1. package/README.md +16 -2
  2. package/bin/wrangler.js +64 -21
  3. package/miniflare-dist/index.mjs +1492 -21
  4. package/package.json +103 -68
  5. package/src/__tests__/access.test.ts +25 -0
  6. package/src/__tests__/api-dev.test.ts +209 -0
  7. package/src/__tests__/api-devregistry.test.js +56 -0
  8. package/src/__tests__/api.test.ts +80 -0
  9. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  10. package/src/__tests__/config-cache.test.ts +6 -0
  11. package/src/__tests__/configuration.test.ts +783 -420
  12. package/src/__tests__/d1.test.ts +80 -0
  13. package/src/__tests__/delete.test.ts +263 -0
  14. package/src/__tests__/deployments.test.ts +91 -0
  15. package/src/__tests__/dev.test.tsx +446 -52
  16. package/src/__tests__/dialogs.test.tsx +40 -0
  17. package/src/__tests__/generate.test.ts +235 -0
  18. package/src/__tests__/get-host-from-url.test.ts +16 -0
  19. package/src/__tests__/helpers/mock-cfetch.ts +129 -7
  20. package/src/__tests__/helpers/mock-console.ts +11 -2
  21. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  22. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  23. package/src/__tests__/helpers/mock-kv.ts +1 -1
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +9 -3
  25. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  26. package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
  27. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  28. package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
  29. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  30. package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
  31. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  32. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  33. package/src/__tests__/helpers/msw/index.ts +21 -0
  34. package/src/__tests__/helpers/run-in-tmp.ts +22 -23
  35. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  36. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  37. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  38. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  39. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  40. package/src/__tests__/https-options.test.ts +51 -18
  41. package/src/__tests__/index.test.ts +137 -131
  42. package/src/__tests__/init.test.ts +1289 -366
  43. package/src/__tests__/jest.setup.ts +96 -1
  44. package/src/__tests__/kv.test.ts +515 -459
  45. package/src/__tests__/logout.test.ts +47 -0
  46. package/src/__tests__/metrics.test.ts +495 -0
  47. package/src/__tests__/middleware.scheduled.test.ts +135 -0
  48. package/src/__tests__/middleware.test.ts +726 -0
  49. package/src/__tests__/pages-deployment-tail.test.ts +884 -0
  50. package/src/__tests__/pages.test.ts +1316 -127
  51. package/src/__tests__/paths.test.ts +39 -0
  52. package/src/__tests__/publish.test.ts +2439 -1229
  53. package/src/__tests__/pubsub.test.ts +311 -97
  54. package/src/__tests__/queues.test.ts +522 -0
  55. package/src/__tests__/r2.test.ts +363 -203
  56. package/src/__tests__/secret.test.ts +236 -78
  57. package/src/__tests__/tail.test.ts +359 -150
  58. package/src/__tests__/test-old-node-version.js +31 -0
  59. package/src/__tests__/type-generation.test.ts +233 -0
  60. package/src/__tests__/user.test.ts +61 -75
  61. package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
  62. package/src/__tests__/validate-dev-props.test.ts +56 -0
  63. package/src/__tests__/version.test.ts +35 -0
  64. package/src/__tests__/whoami.test.tsx +115 -57
  65. package/src/__tests__/worker-namespace.test.ts +326 -0
  66. package/src/api/dev.ts +193 -22
  67. package/src/api/index.ts +1 -0
  68. package/src/bundle-reporter.tsx +41 -2
  69. package/src/bundle.ts +684 -73
  70. package/src/cfetch/index.ts +40 -1
  71. package/src/cfetch/internal.ts +143 -22
  72. package/src/cli.ts +4 -3
  73. package/src/config/config.ts +35 -3
  74. package/src/config/environment.ts +153 -6
  75. package/src/config/index.ts +137 -4
  76. package/src/config/validation-helpers.ts +19 -6
  77. package/src/config/validation.ts +470 -11
  78. package/src/config-cache.ts +72 -31
  79. package/src/create-worker-preview.ts +113 -30
  80. package/src/create-worker-upload-form.ts +90 -19
  81. package/src/d1/backups.tsx +223 -0
  82. package/src/d1/constants.ts +2 -0
  83. package/src/d1/create.tsx +63 -0
  84. package/src/d1/delete.tsx +56 -0
  85. package/src/d1/execute.tsx +352 -0
  86. package/src/d1/formatTimeAgo.ts +14 -0
  87. package/src/d1/index.ts +101 -0
  88. package/src/d1/list.tsx +48 -0
  89. package/src/d1/migrations/apply.tsx +187 -0
  90. package/src/d1/migrations/create.tsx +77 -0
  91. package/src/d1/migrations/helpers.ts +147 -0
  92. package/src/d1/migrations/index.tsx +3 -0
  93. package/src/d1/migrations/list.tsx +79 -0
  94. package/src/d1/migrations/options.ts +18 -0
  95. package/src/d1/options.ts +22 -0
  96. package/src/d1/types.tsx +24 -0
  97. package/src/d1/utils.ts +48 -0
  98. package/src/delete.ts +108 -0
  99. package/src/deployments.ts +77 -0
  100. package/src/deprecated/index.ts +438 -0
  101. package/src/dev/dev-vars.ts +11 -8
  102. package/src/dev/dev.tsx +262 -65
  103. package/src/dev/get-local-persistence-path.tsx +31 -0
  104. package/src/dev/local.tsx +757 -187
  105. package/src/dev/remote.tsx +424 -115
  106. package/src/dev/start-server.ts +535 -0
  107. package/src/dev/use-esbuild.ts +66 -12
  108. package/src/dev/validate-dev-props.ts +31 -0
  109. package/src/dev-registry.tsx +201 -0
  110. package/src/dev.tsx +630 -226
  111. package/src/dialogs.tsx +41 -8
  112. package/src/dispatch-namespace.ts +207 -0
  113. package/src/entry.ts +4 -3
  114. package/src/environment-variables.ts +17 -2
  115. package/src/git-client.ts +100 -7
  116. package/src/global-wrangler-config-path.ts +26 -0
  117. package/src/https-options.ts +8 -4
  118. package/src/index.tsx +304 -1459
  119. package/src/init.ts +573 -144
  120. package/src/inspect.ts +137 -32
  121. package/src/is-ci.ts +14 -0
  122. package/src/is-interactive.ts +16 -0
  123. package/src/{kv.ts → kv/helpers.ts} +26 -4
  124. package/src/kv/index.ts +596 -0
  125. package/src/logger.ts +25 -6
  126. package/src/metrics/index.ts +5 -0
  127. package/src/metrics/metrics-config.ts +239 -0
  128. package/src/metrics/metrics-dispatcher.ts +96 -0
  129. package/src/metrics/metrics-usage-headers.ts +24 -0
  130. package/src/metrics/send-event.ts +97 -0
  131. package/src/miniflare-cli/assets.ts +246 -0
  132. package/src/miniflare-cli/index.ts +181 -19
  133. package/src/module-collection.ts +12 -3
  134. package/src/package-manager.ts +45 -0
  135. package/src/pages/build.tsx +110 -42
  136. package/src/pages/constants.ts +11 -0
  137. package/src/pages/deployment-tails.tsx +284 -0
  138. package/src/pages/deployments.tsx +14 -31
  139. package/src/pages/dev.tsx +423 -674
  140. package/src/pages/errors.ts +66 -0
  141. package/src/pages/functions/buildPlugin.ts +86 -84
  142. package/src/pages/functions/buildWorker.ts +121 -106
  143. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  144. package/src/pages/functions/routes-consolidation.ts +73 -0
  145. package/src/pages/functions/routes-transformation.test.ts +282 -0
  146. package/src/pages/functions/routes-transformation.ts +115 -0
  147. package/src/pages/functions/routes-validation.test.ts +403 -0
  148. package/src/pages/functions/routes-validation.ts +202 -0
  149. package/src/pages/functions.tsx +82 -0
  150. package/src/pages/hash.tsx +13 -0
  151. package/src/pages/index.tsx +73 -55
  152. package/src/pages/projects.tsx +16 -4
  153. package/src/pages/prompt-select-project.tsx +31 -0
  154. package/src/pages/publish.tsx +185 -59
  155. package/src/pages/types.ts +1 -0
  156. package/src/pages/upload.tsx +132 -69
  157. package/src/pages/utils.ts +13 -2
  158. package/src/paths.ts +49 -4
  159. package/src/proxy.ts +375 -157
  160. package/src/publish/index.ts +270 -0
  161. package/src/{publish.ts → publish/publish.ts} +437 -167
  162. package/src/pubsub/pubsub-commands.tsx +512 -492
  163. package/src/queues/cli/commands/consumer/add.ts +71 -0
  164. package/src/queues/cli/commands/consumer/index.ts +22 -0
  165. package/src/queues/cli/commands/consumer/remove.ts +38 -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 +36 -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/helpers.ts +131 -0
  174. package/src/r2/index.ts +289 -0
  175. package/src/routes.ts +140 -0
  176. package/src/secret/index.ts +379 -0
  177. package/src/sites.tsx +8 -8
  178. package/src/tail/createTail.ts +379 -0
  179. package/src/tail/filters.ts +4 -6
  180. package/src/tail/index.ts +199 -284
  181. package/src/tail/printing.ts +43 -3
  182. package/src/type-generation.ts +181 -0
  183. package/src/user/access.ts +69 -0
  184. package/src/user/choose-account.tsx +22 -13
  185. package/src/user/user.tsx +121 -53
  186. package/src/utils/collectKeyValues.ts +14 -0
  187. package/src/whoami.tsx +82 -3
  188. package/src/worker.ts +73 -7
  189. package/src/yargs-types.ts +24 -0
  190. package/src/zones.ts +124 -9
  191. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  192. package/templates/d1-beta-facade.js +205 -0
  193. package/templates/first-party-worker-module-facade.ts +18 -0
  194. package/templates/format-dev-errors.ts +32 -0
  195. package/templates/init-tests/test-jest-new-worker.js +25 -0
  196. package/templates/init-tests/test-vitest-new-worker.js +26 -0
  197. package/templates/middleware/common.ts +62 -0
  198. package/templates/middleware/loader-modules.ts +84 -0
  199. package/templates/middleware/loader-sw.ts +227 -0
  200. package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
  201. package/templates/middleware/middleware-pretty-error.ts +40 -0
  202. package/templates/middleware/middleware-scheduled.ts +15 -0
  203. package/templates/new-worker.js +1 -1
  204. package/templates/pages-dev-pipeline.ts +28 -0
  205. package/templates/pages-dev-util.ts +52 -0
  206. package/templates/pages-shim.ts +9 -0
  207. package/templates/pages-template-plugin.ts +20 -4
  208. package/templates/pages-template-worker.ts +37 -9
  209. package/templates/serve-static-assets.ts +63 -0
  210. package/templates/service-bindings-module-facade.js +54 -0
  211. package/templates/service-bindings-sw-facade.js +42 -0
  212. package/templates/tsconfig.json +4 -3
  213. package/wrangler-dist/cli.d.ts +908 -0
  214. package/wrangler-dist/cli.js +137644 -99734
  215. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  216. package/src/generate.ts +0 -33
  217. package/src/miniflare-cli/enum-keys.ts +0 -17
  218. package/src/preview.ts +0 -31
  219. package/src/r2.ts +0 -50
  220. package/templates/static-asset-facade.js +0 -43
package/README.md CHANGED
@@ -39,11 +39,25 @@ npm run deploy
39
39
  $ npm install wrangler --save-dev
40
40
  ```
41
41
 
42
+ ## Configuration:
43
+
44
+ Wrangler is configured via a `wrangler.toml` file in the project root. When utilizing the `wrangler init` command, a `wrangler.toml` file will be created for you.
45
+
46
+ example:
47
+
48
+ ```toml
49
+ main = "./src/index.ts" # init w/ TypeScript
50
+ name = "my-worker"
51
+ compatibility_date = "YYY-MM-DD"
52
+ ```
53
+
54
+ for more detailed information about configuration, see the [documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration)
55
+
42
56
  ## Commands
43
57
 
44
58
  ### `wrangler init [name]`
45
59
 
46
- Creates a Worker project. For details on configuration keys and values, refer to the [documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration).
60
+ Creates a Worker project. For details on configuration keys and values, refer to the [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#init).
47
61
 
48
62
  ### `wrangler dev`
49
63
 
@@ -67,4 +81,4 @@ For more commands and options, refer to the [documentation](https://developers.c
67
81
 
68
82
  ## Documentation
69
83
 
70
- For the latest Wrangler documentation, [click here](https://6b05b6e1.cloudflare-docs-7ou.pages.dev/workers/wrangler/).
84
+ For the latest Wrangler documentation, [click here](https://developers.cloudflare.com/workers/wrangler/).
package/bin/wrangler.js CHANGED
@@ -3,9 +3,12 @@ const { spawn } = require("child_process");
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const os = require("os");
6
- const semiver = require("semiver");
7
6
 
8
- const MIN_NODE_VERSION = "16.7.0";
7
+ const MIN_NODE_VERSION = "16.13.0";
8
+ const debug =
9
+ process.env["WRANGLER_LOG"] === "debug"
10
+ ? (...args) => console.log(...args)
11
+ : () => {};
9
12
 
10
13
  let wranglerProcess;
11
14
 
@@ -17,8 +20,8 @@ function runWrangler() {
17
20
  // Note Volta and nvm are also recommended in the official docs:
18
21
  // https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
19
22
  console.error(
20
- `Wrangler requires at least Node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}.
21
- You should use the latest Node.js version if possible, as Cloudflare Workers use a very up-to-date version of V8.
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
+
22
25
  Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.`
23
26
  );
24
27
  process.exitCode = 1;
@@ -32,7 +35,7 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
32
35
  // - maybe we can generate a certificate that concatenates with ours?
33
36
  //
34
37
  // I do think it'll be rare that someone wants to add a cert AND
35
- // use cloudflare WARP, but let's wait till the situation actually
38
+ // use Cloudflare WARP, but let's wait till the situation actually
36
39
  // arises before we do anything about it
37
40
  } else {
38
41
  const osTempDir = os.tmpdir();
@@ -52,9 +55,6 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
52
55
  return spawn(
53
56
  process.execPath,
54
57
  [
55
- ...(semiver(process.versions.node, "18.0.0") >= 0
56
- ? ["--no-experimental-fetch"] // TODO: remove this when https://github.com/cloudflare/wrangler2/issues/834 is properly fixed
57
- : []),
58
58
  "--no-warnings",
59
59
  "--experimental-vm-modules",
60
60
  ...process.execArgv,
@@ -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,20 +93,25 @@ function runDelegatedWrangler() {
87
93
  } = JSON.parse(fs.readFileSync(packageJsonPath));
88
94
  const resolvedBinaryPath = path.resolve(packageJsonPath, "..", binaryPath);
89
95
 
90
- console.log(
91
- `Delegating to locally-installed version of wrangler @ v${version}`
92
- );
96
+ debug(`Delegating to locally-installed version of wrangler @ v${version}`);
97
+
93
98
  // this call to `spawn` is simpler because the delegated version will do all
94
99
  // of the other work.
95
100
  return spawn(
96
101
  process.execPath,
97
102
  [resolvedBinaryPath, ...process.argv.slice(2)],
98
103
  {
99
- stdio: "inherit",
104
+ stdio: ["inherit", "inherit", "inherit", "ipc"],
100
105
  }
101
- ).on("exit", (code) =>
102
- process.exit(code === undefined || code === null ? 0 : code)
103
- );
106
+ )
107
+ .on("exit", (code) =>
108
+ process.exit(code === undefined || code === null ? 0 : code)
109
+ )
110
+ .on("message", (message) => {
111
+ if (process.send) {
112
+ process.send(message);
113
+ }
114
+ });
104
115
  }
105
116
 
106
117
  /**
@@ -128,10 +139,42 @@ async function main() {
128
139
  }
129
140
 
130
141
  process.on("SIGINT", () => {
131
- wranglerProcess?.kill();
142
+ wranglerProcess && wranglerProcess.kill();
132
143
  });
133
144
  process.on("SIGTERM", () => {
134
- wranglerProcess?.kill();
145
+ wranglerProcess && wranglerProcess.kill();
135
146
  });
136
147
 
148
+ // semiver implementation via https://github.com/lukeed/semiver/blob/ae7eebe6053c96be63032b14fb0b68e2553fcac4/src/index.js
149
+
150
+ /**
151
+ MIT License
152
+
153
+ Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
154
+
155
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
156
+
157
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
158
+
159
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
160
+
161
+ */
162
+
163
+ var fn = new Intl.Collator(0, { numeric: 1 }).compare;
164
+
165
+ function semiver(a, b, bool) {
166
+ a = a.split(".");
167
+ b = b.split(".");
168
+
169
+ return (
170
+ fn(a[0], b[0]) ||
171
+ fn(a[1], b[1]) ||
172
+ ((b[2] = b.slice(2).join(".")),
173
+ (bool = /[.-]/.test((a[2] = a.slice(2).join(".")))),
174
+ bool == /[.-]/.test(b[2]) ? fn(a[2], b[2]) : bool ? -1 : 1)
175
+ );
176
+ }
177
+
178
+ // end semiver implementation
179
+
137
180
  void main();