wrangler 0.0.0-e95e5a0 → 0.0.0-e978986

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 (52) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/package.json +11 -7
  5. package/pages/functions/buildPlugin.ts +13 -0
  6. package/pages/functions/buildWorker.ts +14 -1
  7. package/pages/functions/template-plugin.ts +3 -2
  8. package/src/__tests__/configuration.test.ts +336 -87
  9. package/src/__tests__/dev.test.tsx +243 -25
  10. package/src/__tests__/helpers/mock-dialogs.ts +41 -1
  11. package/src/__tests__/index.test.ts +79 -72
  12. package/src/__tests__/init.test.ts +182 -131
  13. package/src/__tests__/jest.setup.ts +8 -0
  14. package/src/__tests__/kv.test.ts +173 -146
  15. package/src/__tests__/package-manager.test.ts +154 -7
  16. package/src/__tests__/pages.test.ts +381 -53
  17. package/src/__tests__/parse.test.ts +8 -0
  18. package/src/__tests__/publish.test.ts +682 -89
  19. package/src/__tests__/r2.test.ts +55 -36
  20. package/src/__tests__/secret.test.ts +39 -4
  21. package/src/abort.d.ts +3 -0
  22. package/src/bundle.ts +33 -2
  23. package/src/cfetch/index.ts +21 -4
  24. package/src/cfetch/internal.ts +17 -9
  25. package/src/config/config.ts +1 -1
  26. package/src/config/environment.ts +40 -14
  27. package/src/config/index.ts +162 -0
  28. package/src/config/validation.ts +180 -65
  29. package/src/create-worker-preview.ts +17 -7
  30. package/src/create-worker-upload-form.ts +22 -8
  31. package/src/dev/dev.tsx +7 -6
  32. package/src/dev/local.tsx +6 -0
  33. package/src/dev/remote.tsx +15 -1
  34. package/src/dialogs.tsx +48 -0
  35. package/src/durable.ts +102 -0
  36. package/src/entry.ts +64 -9
  37. package/src/index.tsx +357 -177
  38. package/src/inspect.ts +39 -0
  39. package/src/kv.ts +114 -25
  40. package/src/open-in-browser.ts +5 -12
  41. package/src/package-manager.ts +50 -3
  42. package/src/pages.tsx +271 -110
  43. package/src/parse.ts +23 -4
  44. package/src/proxy.ts +38 -22
  45. package/src/publish.ts +227 -113
  46. package/src/sites.tsx +19 -17
  47. package/src/user.tsx +11 -1
  48. package/src/worker.ts +8 -0
  49. package/templates/new-worker-scheduled.js +17 -0
  50. package/templates/new-worker-scheduled.ts +32 -0
  51. package/templates/new-worker.ts +16 -1
  52. package/wrangler-dist/cli.js +36017 -22687
@@ -0,0 +1,18 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIC6zCCAkygAwIBAgIUI7b68p0pPrCBoW4ptlyvVcPItscwCgYIKoZIzj0EAwQw
3
+ gY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
4
+ YW4gRnJhbmNpc2NvMRgwFgYDVQQKEw9DbG91ZGZsYXJlLCBJbmMxNzA1BgNVBAMT
5
+ LkNsb3VkZmxhcmUgZm9yIFRlYW1zIEVDQyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw
6
+ HhcNMjAwMjA0MTYwNTAwWhcNMjUwMjAyMTYwNTAwWjCBjTELMAkGA1UEBhMCVVMx
7
+ EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGDAW
8
+ BgNVBAoTD0Nsb3VkZmxhcmUsIEluYzE3MDUGA1UEAxMuQ2xvdWRmbGFyZSBmb3Ig
9
+ VGVhbXMgRUNDIENlcnRpZmljYXRlIEF1dGhvcml0eTCBmzAQBgcqhkjOPQIBBgUr
10
+ gQQAIwOBhgAEAVdXsX8tpA9NAQeEQalvUIcVaFNDvGsR69ysZxOraRWNGHLfq1mi
11
+ P6o3wtmtx/C2OXG01Cw7UFJbKl5MEDxnT2KoAdFSynSJOF2NDoe5LoZHbUW+yR3X
12
+ FDl+MF6JzZ590VLGo6dPBf06UsXbH7PvHH2XKtFt8bBXVNMa5a21RdmpD0Pho0Uw
13
+ QzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBAjAdBgNVHQ4EFgQU
14
+ YBcQng1AEMMNteuRDAMG0/vgFe0wCgYIKoZIzj0EAwQDgYwAMIGIAkIBQU5OTA2h
15
+ YqmFk8paan5ezHVLcmcucsfYw4L/wmeEjCkczRmCVNm6L86LjhWU0v0wER0e+lHO
16
+ 3efvjbsu8gIGSagCQgEBnyYMP9gwg8l96QnQ1khFA1ljFlnqc2XgJHDSaAJC0gdz
17
+ +NV3JMeWaD2Rb32jc9r6/a7xY0u0ByqxBQ1OQ0dt7A==
18
+ -----END CERTIFICATE-----
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## ⛅️ wrangler
2
2
 
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.
4
+
3
5
  `wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
4
6
 
5
7
  ## Quick Start
@@ -22,7 +24,7 @@ npx wrangler init my-worker
22
24
  # try it out
23
25
  cd my-worker && npm run start
24
26
  # and then publish it
25
- npx wrangler publish
27
+ npm run deploy
26
28
  ```
27
29
 
28
30
  ## Installation:
package/bin/wrangler.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require("node:child_process");
3
- const { join } = require("node:path");
2
+ const { spawn } = require("child_process");
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const os = require("os");
4
6
  const semiver = require("semiver");
5
7
 
6
8
  const MIN_NODE_VERSION = "16.7.0";
@@ -20,6 +22,30 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
20
22
  return;
21
23
  }
22
24
 
25
+ let pathToCACerts = process.env.NODE_EXTRA_CA_CERTS;
26
+ if (pathToCACerts) {
27
+ // TODO:
28
+ // - should we log a warning here?
29
+ // - maybe we can generate a certificate that concatenates with ours?
30
+ //
31
+ // I do think it'll be rare that someone wants to add a cert AND
32
+ // use cloudflare WARP, but let's wait till the situation actually
33
+ // arises before we do anything about it
34
+ } else {
35
+ const osTempDir = os.tmpdir();
36
+ const certDir = path.join(osTempDir, "wrangler-cert");
37
+ const certPath = path.join(certDir, "Cloudflare_CA.pem");
38
+ // copy cert to the system temp dir if needed
39
+ if (!fs.existsSync(certPath)) {
40
+ fs.mkdirSync(certDir, { recursive: true });
41
+ fs.writeFileSync(
42
+ certPath,
43
+ fs.readFileSync(path.join(__dirname, "../Cloudflare_CA.pem"), "utf-8")
44
+ );
45
+ }
46
+ pathToCACerts = certPath;
47
+ }
48
+
23
49
  wranglerProcess = spawn(
24
50
  process.execPath,
25
51
  [
@@ -29,10 +55,16 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
29
55
  "--no-warnings",
30
56
  "--experimental-vm-modules",
31
57
  ...process.execArgv,
32
- join(__dirname, "../wrangler-dist/cli.js"),
58
+ path.join(__dirname, "../wrangler-dist/cli.js"),
33
59
  ...process.argv.slice(2),
34
60
  ],
35
- { stdio: "inherit" }
61
+ {
62
+ stdio: "inherit",
63
+ env: {
64
+ ...process.env,
65
+ NODE_EXTRA_CA_CERTS: pathToCACerts,
66
+ },
67
+ }
36
68
  ).on("exit", (code) =>
37
69
  process.exit(code === undefined || code === null ? 0 : code)
38
70
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-e95e5a0",
3
+ "version": "0.0.0-e978986",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -9,9 +9,9 @@
9
9
  },
10
10
  "license": "MIT OR Apache-2.0",
11
11
  "bugs": {
12
- "url": "https://github.com/cloudflare/wrangler/issues"
12
+ "url": "https://github.com/cloudflare/wrangler2/issues"
13
13
  },
14
- "homepage": "https://github.com/cloudflare/wrangler#readme",
14
+ "homepage": "https://github.com/cloudflare/wrangler2#readme",
15
15
  "keywords": [
16
16
  "wrangler",
17
17
  "cloudflare",
@@ -40,7 +40,7 @@
40
40
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
41
41
  "blake3-wasm": "^2.1.5",
42
42
  "esbuild": "0.14.34",
43
- "miniflare": "2.4.0",
43
+ "miniflare": "^2.5.0",
44
44
  "nanoid": "^3.3.3",
45
45
  "path-to-regexp": "^6.2.0",
46
46
  "selfsigned": "^2.0.1",
@@ -62,6 +62,7 @@
62
62
  "@types/supports-color": "^8.1.1",
63
63
  "@types/ws": "^8.5.3",
64
64
  "@types/yargs": "^17.0.10",
65
+ "@webcontainer/env": "^1.0.1",
65
66
  "chokidar": "^3.5.3",
66
67
  "clipboardy": "^3.0.0",
67
68
  "cmd-shim": "^4.1.0",
@@ -74,6 +75,7 @@
74
75
  "find-up": "^6.3.0",
75
76
  "get-port": "^6.1.2",
76
77
  "glob-to-regexp": "0.4.1",
78
+ "http-terminator": "^3.2.0",
77
79
  "ignore": "^5.2.0",
78
80
  "ink": "^3.2.0",
79
81
  "ink-select-input": "^4.2.1",
@@ -85,6 +87,7 @@
85
87
  "jest-websocket-mock": "^2.3.0",
86
88
  "mime": "^3.0.0",
87
89
  "open": "^8.4.0",
90
+ "p-queue": "^7.2.0",
88
91
  "pretty-bytes": "^6.0.0",
89
92
  "prompts": "^2.4.2",
90
93
  "react": "^17.0.2",
@@ -95,7 +98,7 @@
95
98
  "timeago.js": "^4.0.2",
96
99
  "tmp-promise": "^3.0.3",
97
100
  "ts-dedent": "^2.2.0",
98
- "undici": "^4.15.1",
101
+ "undici": "^5.3.0",
99
102
  "update-check": "^1.5.4",
100
103
  "ws": "^8.5.0",
101
104
  "yargs": "^17.4.1"
@@ -109,7 +112,8 @@
109
112
  "wrangler-dist",
110
113
  "templates",
111
114
  "vendor",
112
- "import_meta_url.js"
115
+ "import_meta_url.js",
116
+ "Cloudflare_CA.pem"
113
117
  ],
114
118
  "scripts": {
115
119
  "clean": "rm -rf wrangler-dist miniflare-dist",
@@ -129,7 +133,7 @@
129
133
  "testTimeout": 30000,
130
134
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
131
135
  "transformIgnorePatterns": [
132
- "node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
136
+ "node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
133
137
  ],
134
138
  "moduleNameMapper": {
135
139
  "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
@@ -1,5 +1,7 @@
1
1
  import { access, lstat } from "node:fs/promises";
2
2
  import { dirname, relative, resolve } from "node:path";
3
+ import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
4
+ import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
3
5
  import { build } from "esbuild";
4
6
 
5
7
  type Options = {
@@ -8,6 +10,7 @@ type Options = {
8
10
  minify?: boolean;
9
11
  sourcemap?: boolean;
10
12
  watch?: boolean;
13
+ nodeCompat?: boolean;
11
14
  onEnd?: () => void;
12
15
  };
13
16
 
@@ -17,6 +20,7 @@ export function buildPlugin({
17
20
  minify = false,
18
21
  sourcemap = false,
19
22
  watch = false,
23
+ nodeCompat,
20
24
  onEnd = () => {},
21
25
  }: Options) {
22
26
  return build({
@@ -30,6 +34,7 @@ export function buildPlugin({
30
34
  sourcemap,
31
35
  watch,
32
36
  allowOverwrite: true,
37
+ define: { ...(nodeCompat ? { global: "globalThis" } : {}) },
33
38
  plugins: [
34
39
  {
35
40
  name: "wrangler notifier and monitor",
@@ -87,6 +92,14 @@ export function buildPlugin({
87
92
  }
88
93
  },
89
94
  },
95
+ ...(nodeCompat
96
+ ? [
97
+ NodeGlobalsPolyfills({
98
+ buffer: true,
99
+ }),
100
+ NodeModulesPolyfills(),
101
+ ]
102
+ : []),
90
103
  ],
91
104
  });
92
105
  }
@@ -1,5 +1,7 @@
1
1
  import { access, cp, lstat, rm } from "node:fs/promises";
2
2
  import { join, resolve } from "node:path";
3
+ import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
4
+ import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
3
5
  import { build } from "esbuild";
4
6
  import { nanoid } from "nanoid";
5
7
 
@@ -12,6 +14,7 @@ type Options = {
12
14
  watch?: boolean;
13
15
  onEnd?: () => void;
14
16
  buildOutputDirectory?: string;
17
+ nodeCompat?: boolean;
15
18
  };
16
19
 
17
20
  export function buildWorker({
@@ -23,6 +26,7 @@ export function buildWorker({
23
26
  watch = false,
24
27
  onEnd = () => {},
25
28
  buildOutputDirectory,
29
+ nodeCompat,
26
30
  }: Options) {
27
31
  return build({
28
32
  entryPoints: [resolve(__dirname, "../pages/functions/template-worker.ts")],
@@ -37,6 +41,7 @@ export function buildWorker({
37
41
  allowOverwrite: true,
38
42
  define: {
39
43
  __FALLBACK_SERVICE__: JSON.stringify(fallbackService),
44
+ ...(nodeCompat ? { global: "globalThis" } : {}),
40
45
  },
41
46
  plugins: [
42
47
  {
@@ -122,7 +127,7 @@ export function buildWorker({
122
127
  // TODO: Watch args.path for changes and re-copy when updated
123
128
  contents: `export const onRequest = ({ request, env, functionPath }) => {
124
129
  const url = new URL(request.url)
125
- const relativePathname = url.pathname.split(functionPath)[1] || "/";
130
+ const relativePathname = \`/\${url.pathname.split(functionPath)[1] || ''}\`.replace(/^\\/\\//, '/');
126
131
  url.pathname = '/cdn-cgi/pages-plugins/${identifier}' + relativePathname
127
132
  request = new Request(url.toString(), request)
128
133
  return env.ASSETS.fetch(request)
@@ -133,6 +138,14 @@ export function buildWorker({
133
138
  );
134
139
  },
135
140
  },
141
+ ...(nodeCompat
142
+ ? [
143
+ NodeGlobalsPolyfills({
144
+ buffer: true,
145
+ }),
146
+ NodeModulesPolyfills(),
147
+ ]
148
+ : []),
136
149
  ],
137
150
  });
138
151
  }
@@ -103,8 +103,9 @@ export default function (pluginArgs) {
103
103
  const { env, next, data } = workerContext;
104
104
 
105
105
  const url = new URL(request.url);
106
- const relativePathname =
107
- url.pathname.split(workerContext.functionPath)[1] || "/";
106
+ const relativePathname = `/${
107
+ url.pathname.split(workerContext.functionPath)[1] || ""
108
+ }`.replace(/^\/\//, "/");
108
109
 
109
110
  const handlerIterator = executeRequest(request, relativePathname);
110
111
  const pluginNext = async (input?: RequestInfo, init?: RequestInit) => {