wrangler 0.0.0-e452a04 → 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 (94) 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 +36 -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 +1180 -272
  14. package/src/__tests__/dev.test.tsx +447 -25
  15. package/src/__tests__/guess-worker-format.test.ts +28 -1
  16. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  17. package/src/__tests__/helpers/mock-cfetch.ts +5 -1
  18. package/src/__tests__/helpers/mock-console.ts +20 -3
  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/run-in-tmp.ts +10 -0
  25. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  26. package/src/__tests__/https-options.test.ts +5 -2
  27. package/src/__tests__/index.test.ts +77 -826
  28. package/src/__tests__/init.test.ts +1516 -0
  29. package/src/__tests__/jest.setup.ts +12 -4
  30. package/src/__tests__/kv.test.ts +208 -174
  31. package/src/__tests__/logger.test.ts +115 -0
  32. package/src/__tests__/pages.test.ts +309 -26
  33. package/src/__tests__/parse.test.ts +4 -0
  34. package/src/__tests__/publish.test.ts +3249 -553
  35. package/src/__tests__/r2.test.ts +38 -26
  36. package/src/__tests__/route.test.ts +4 -4
  37. package/src/__tests__/secret.test.ts +55 -34
  38. package/src/__tests__/tail.test.ts +146 -20
  39. package/src/__tests__/user.test.ts +131 -0
  40. package/src/__tests__/whoami.test.tsx +26 -7
  41. package/src/bundle.ts +31 -4
  42. package/src/cfetch/internal.ts +9 -7
  43. package/src/cli.ts +5 -11
  44. package/src/config/README.md +7 -7
  45. package/src/config/config.ts +34 -79
  46. package/src/config/environment.ts +93 -4
  47. package/src/config/index.ts +15 -4
  48. package/src/config/validation-helpers.ts +202 -15
  49. package/src/config/validation.ts +531 -134
  50. package/src/config-cache.ts +45 -0
  51. package/src/create-worker-preview.ts +22 -13
  52. package/src/create-worker-upload-form.ts +32 -9
  53. package/src/dev/dev-vars.ts +36 -0
  54. package/src/dev/dev.tsx +136 -75
  55. package/src/dev/local.tsx +196 -125
  56. package/src/dev/remote.tsx +25 -13
  57. package/src/dev/use-esbuild.ts +23 -5
  58. package/src/dialogs.tsx +16 -6
  59. package/src/entry.ts +119 -11
  60. package/src/environment-variables.ts +3 -1
  61. package/src/errors.ts +11 -0
  62. package/src/https-options.ts +3 -2
  63. package/src/index.tsx +782 -413
  64. package/src/inspect.ts +17 -11
  65. package/src/intl-polyfill.d.ts +139 -0
  66. package/src/{kv/index.tsx → kv.ts} +8 -28
  67. package/src/logger.ts +66 -0
  68. package/src/miniflare-cli/README.md +30 -0
  69. package/src/miniflare-cli/enum-keys.ts +17 -0
  70. package/src/miniflare-cli/index.ts +41 -0
  71. package/src/miniflare-cli/request-context.ts +40 -0
  72. package/src/module-collection.ts +63 -58
  73. package/src/open-in-browser.ts +5 -4
  74. package/src/package-manager.ts +9 -8
  75. package/src/pages.tsx +892 -62
  76. package/src/parse.ts +4 -2
  77. package/src/proxy.ts +32 -21
  78. package/src/publish.ts +276 -159
  79. package/src/sites.tsx +88 -33
  80. package/src/tail/index.ts +2 -2
  81. package/src/tail/printing.ts +13 -8
  82. package/src/update-check.ts +19 -0
  83. package/src/user.tsx +242 -104
  84. package/src/whoami.tsx +2 -1
  85. package/src/worker.ts +15 -6
  86. package/templates/gitignore +171 -0
  87. package/templates/static-asset-facade.js +1 -1
  88. package/wrangler-dist/cli.js +22355 -49416
  89. package/src/__tests__/dev2.test.tsx +0 -152
  90. package/src/__tests__/helpers/mock-user.ts +0 -27
  91. package/src/__tests__/logout.test.ts +0 -50
  92. package/src/__tests__/sentry.test.ts +0 -146
  93. package/src/reporting.ts +0 -131
  94. 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();