wrangler 0.0.0-e3cab74 → 0.0.0-e492c10

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 (97) hide show
  1. package/README.md +27 -14
  2. package/bin/wrangler.js +13 -1
  3. package/miniflare-dist/index.mjs +4886 -0
  4. package/package.json +38 -27
  5. package/pages/functions/buildPlugin.ts +92 -0
  6. package/pages/functions/buildWorker.ts +80 -4
  7. package/pages/functions/filepath-routing.test.ts +136 -25
  8. package/pages/functions/filepath-routing.ts +14 -3
  9. package/pages/functions/routes.ts +6 -1
  10. package/pages/functions/template-plugin.ts +146 -0
  11. package/pages/functions/template-worker.ts +21 -8
  12. package/src/__tests__/config-cache.test.ts +36 -0
  13. package/src/__tests__/configuration.test.ts +1295 -355
  14. package/src/__tests__/dev.test.tsx +798 -84
  15. package/src/__tests__/guess-worker-format.test.ts +37 -18
  16. package/src/__tests__/helpers/mock-account-id.ts +22 -4
  17. package/src/__tests__/helpers/mock-cfetch.ts +8 -4
  18. package/src/__tests__/helpers/mock-console.ts +35 -10
  19. package/src/__tests__/helpers/mock-dialogs.ts +26 -1
  20. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  21. package/src/__tests__/helpers/mock-istty.ts +27 -0
  22. package/src/__tests__/helpers/mock-kv.ts +9 -16
  23. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  25. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  26. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  27. package/src/__tests__/https-options.test.ts +130 -0
  28. package/src/__tests__/index.test.ts +129 -753
  29. package/src/__tests__/init.test.ts +1516 -0
  30. package/src/__tests__/jest.setup.ts +28 -8
  31. package/src/__tests__/kv.test.ts +517 -216
  32. package/src/__tests__/logger.test.ts +115 -0
  33. package/src/__tests__/pages.test.ts +327 -0
  34. package/src/__tests__/parse.test.ts +4 -0
  35. package/src/__tests__/publish.test.ts +3400 -858
  36. package/src/__tests__/r2.test.ts +38 -26
  37. package/src/__tests__/route.test.ts +45 -0
  38. package/src/__tests__/secret.test.ts +193 -73
  39. package/src/__tests__/tail.test.ts +146 -20
  40. package/src/__tests__/user.test.ts +131 -0
  41. package/src/__tests__/whoami.test.tsx +26 -7
  42. package/src/bundle.ts +43 -7
  43. package/src/cfetch/internal.ts +9 -5
  44. package/src/cli.ts +5 -11
  45. package/src/config/README.md +7 -7
  46. package/src/config/config.ts +69 -100
  47. package/src/config/environment.ts +93 -4
  48. package/src/config/index.ts +15 -4
  49. package/src/config/validation-helpers.ts +228 -23
  50. package/src/config/validation.ts +562 -155
  51. package/src/config-cache.ts +45 -0
  52. package/src/{api/preview.ts → create-worker-preview.ts} +57 -29
  53. package/src/{api/form_data.ts → create-worker-upload-form.ts} +33 -10
  54. package/src/dev/dev-vars.ts +36 -0
  55. package/src/dev/dev.tsx +418 -0
  56. package/src/dev/local.tsx +312 -0
  57. package/src/dev/remote.tsx +213 -0
  58. package/src/dev/use-esbuild.ts +118 -0
  59. package/src/dialogs.tsx +16 -6
  60. package/src/entry.ts +222 -12
  61. package/src/environment-variables.ts +3 -1
  62. package/src/errors.ts +11 -0
  63. package/src/https-options.ts +123 -0
  64. package/src/index.tsx +1137 -766
  65. package/src/inspect.ts +25 -11
  66. package/src/intl-polyfill.d.ts +139 -0
  67. package/src/{kv.tsx → kv.ts} +97 -53
  68. package/src/logger.ts +66 -0
  69. package/src/miniflare-cli/README.md +30 -0
  70. package/src/miniflare-cli/enum-keys.ts +17 -0
  71. package/src/miniflare-cli/index.ts +41 -0
  72. package/src/miniflare-cli/request-context.ts +40 -0
  73. package/src/module-collection.ts +94 -6
  74. package/src/open-in-browser.ts +18 -5
  75. package/src/package-manager.ts +9 -8
  76. package/src/pages.tsx +892 -62
  77. package/src/parse.ts +4 -2
  78. package/src/proxy.ts +128 -55
  79. package/src/publish.ts +305 -204
  80. package/src/selfsigned.d.ts +29 -0
  81. package/src/sites.tsx +89 -37
  82. package/src/tail/index.ts +2 -2
  83. package/src/tail/printing.ts +13 -8
  84. package/src/update-check.ts +19 -0
  85. package/src/user.tsx +263 -109
  86. package/src/whoami.tsx +2 -1
  87. package/src/{api/worker.ts → worker.ts} +16 -30
  88. package/templates/gitignore +171 -0
  89. package/templates/static-asset-facade.js +1 -1
  90. package/wrangler-dist/cli.js +23800 -50736
  91. package/src/__tests__/helpers/mock-user.ts +0 -27
  92. package/src/__tests__/logout.test.ts +0 -50
  93. package/src/__tests__/sentry.test.ts +0 -146
  94. package/src/dev.tsx +0 -961
  95. package/src/guess-worker-format.ts +0 -68
  96. package/src/reporting.ts +0 -115
  97. package/wrangler-dist/cli.js.map +0 -7
package/README.md CHANGED
@@ -1,47 +1,56 @@
1
- ## 🤠 wrangler
1
+ ## ⛅️ wrangler
2
2
 
3
- `wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
4
-
5
- [(Read the full stack week launch blog post.)](https://blog.cloudflare.com/wrangler-v2-beta/)
3
+ > 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.
6
4
 
7
- **DISCLAIMER**: This is a work in progress, and is NOT recommended for use in production. We are opening this preview for feedback from the community, and to openly share our [roadmap](https://github.com/cloudflare/wrangler2/issues/12) for the future. As such, expect APIs and documentation to change before the end of the preview.
8
-
9
- Further, we will NOT do a general release until we are both feature complete, and have a full backward compatibility and incremental migration plan in place. For more details, follow the [parent roadmap issue](https://github.com/cloudflare/wrangler2/issues/12).
5
+ `wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
10
6
 
11
7
  ## Quick Start
12
8
 
13
9
  ```bash
14
10
  # Make a javascript file
15
- $ echo "export default { fetch() { return new Response('hello world') } }" > index.js
11
+ echo "export default { fetch() { return new Response('hello world') } }" > index.js
16
12
  # try it out
17
- $ npx wrangler@beta dev index.js
13
+ npx wrangler dev index.js
18
14
  # and then publish it
19
- $ npx wrangler@beta publish index.js --name my-worker
15
+ npx wrangler publish index.js --name my-worker
20
16
  # visit https://my-worker.<your workers subdomain>.workers.dev
21
17
  ```
22
18
 
19
+ ## Create a Project
20
+
21
+ ```bash
22
+ # Generate a new project
23
+ npx wrangler init my-worker
24
+ # try it out
25
+ cd my-worker && npm run start
26
+ # and then publish it
27
+ npm run publish
28
+ ```
29
+
23
30
  ## Installation:
24
31
 
25
32
  ```bash
26
- $ npm install wrangler@beta
33
+ $ npm install wrangler --save-dev
27
34
  ```
28
35
 
29
36
  ## Commands
30
37
 
31
38
  ### `wrangler init [name]`
32
39
 
33
- Creates a `wrangler.toml` configuration file. For more details on the configuration keys and values, refer to the [documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration).
40
+ Creates a Worker project. For details on configuration keys and values, refer to the [documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration).
34
41
 
35
- ### `wrangler dev [script]`
42
+ ### `wrangler dev`
36
43
 
37
44
  Start a local development server, with live reloading and devtools.
38
45
 
39
- ### `wrangler publish [script] --name [name]`
46
+ ### `wrangler publish`
40
47
 
41
48
  Publish the given script to the worldwide Cloudflare network.
42
49
 
43
50
  For more commands and options, refer to the [documentation](https://developers.cloudflare.com/workers/cli-wrangler/commands).
44
51
 
52
+ ## Pages
53
+
45
54
  ### `wrangler pages dev [directory] [-- command]`
46
55
 
47
56
  Either serves a static build asset directory, or proxies itself in front of a command.
@@ -49,3 +58,7 @@ Either serves a static build asset directory, or proxies itself in front of a co
49
58
  Builds and runs functions from a `./functions` directory or uses a `_worker.js` file inside the static build asset directory.
50
59
 
51
60
  For more commands and options, refer to the [documentation](https://developers.cloudflare.com/pages/platform/functions#develop-and-preview-locally) or run `wrangler pages dev --help`.
61
+
62
+ ## Documentation
63
+
64
+ For the latest Wrangler documentation, [click here](https://6b05b6e1.cloudflare-docs-7ou.pages.dev/workers/wrangler/).
package/bin/wrangler.js CHANGED
@@ -5,6 +5,8 @@ const semiver = require("semiver");
5
5
 
6
6
  const MIN_NODE_VERSION = "16.7.0";
7
7
 
8
+ let wranglerProcess;
9
+
8
10
  async function main() {
9
11
  if (semiver(process.versions.node, MIN_NODE_VERSION) < 0) {
10
12
  // Note Volta and nvm are also recommended in the official docs:
@@ -18,9 +20,12 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
18
20
  return;
19
21
  }
20
22
 
21
- spawn(
23
+ wranglerProcess = spawn(
22
24
  process.execPath,
23
25
  [
26
+ ...(semiver(process.versions.node, "18.0.0") >= 0
27
+ ? ["--no-experimental-fetch"] // TODO: remove this when https://github.com/cloudflare/wrangler2/issues/834 is properly fixed
28
+ : []),
24
29
  "--no-warnings",
25
30
  "--experimental-vm-modules",
26
31
  ...process.execArgv,
@@ -33,4 +38,11 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
33
38
  );
34
39
  }
35
40
 
41
+ process.on("SIGINT", () => {
42
+ wranglerProcess.kill();
43
+ });
44
+ process.on("SIGTERM", () => {
45
+ wranglerProcess.kill();
46
+ });
47
+
36
48
  void main();