wrangler 2.0.0 → 2.0.3

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.
@@ -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 publish
26
28
  ```
27
29
 
28
30
  ## Installation:
package/bin/wrangler.js CHANGED
@@ -20,6 +20,20 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
20
20
  return;
21
21
  }
22
22
 
23
+ let pathToCACerts = process.env.NODE_EXTRA_CA_CERTS;
24
+ if (pathToCACerts) {
25
+ // TODO:
26
+ // - should we log a warning here?
27
+ // - maybe we can generate a certificate that concatenates with ours?
28
+ // - is there a security concern/should we cleanup after we exit?
29
+ //
30
+ // I do think it'll be rare that someone wants to add a cert AND
31
+ // use cloudflare WARP, but let's wait till the situation actually
32
+ // arises before we do anything about it
33
+ } else {
34
+ pathToCACerts = join(__dirname, "../Cloudflare_CA.pem");
35
+ }
36
+
23
37
  wranglerProcess = spawn(
24
38
  process.execPath,
25
39
  [
@@ -32,7 +46,13 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
32
46
  join(__dirname, "../wrangler-dist/cli.js"),
33
47
  ...process.argv.slice(2),
34
48
  ],
35
- { stdio: "inherit" }
49
+ {
50
+ stdio: "inherit",
51
+ env: {
52
+ ...process.env,
53
+ NODE_EXTRA_CA_CERTS: pathToCACerts,
54
+ },
55
+ }
36
56
  ).on("exit", (code) =>
37
57
  process.exit(code === undefined || code === null ? 0 : code)
38
58
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.0",
3
+ "version": "2.0.3",
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",
@@ -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",
@@ -109,7 +110,8 @@
109
110
  "wrangler-dist",
110
111
  "templates",
111
112
  "vendor",
112
- "import_meta_url.js"
113
+ "import_meta_url.js",
114
+ "Cloudflare_CA.pem"
113
115
  ],
114
116
  "scripts": {
115
117
  "clean": "rm -rf wrangler-dist miniflare-dist",
@@ -122,7 +122,7 @@ export function buildWorker({
122
122
  // TODO: Watch args.path for changes and re-copy when updated
123
123
  contents: `export const onRequest = ({ request, env, functionPath }) => {
124
124
  const url = new URL(request.url)
125
- const relativePathname = url.pathname.split(functionPath)[1] || "/";
125
+ const relativePathname = \`/\${url.pathname.split(functionPath)[1] || ''}\`.replace(/^\\/\\//, '/');
126
126
  url.pathname = '/cdn-cgi/pages-plugins/${identifier}' + relativePathname
127
127
  request = new Request(url.toString(), request)
128
128
  return env.ASSETS.fetch(request)
@@ -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) => {
@@ -27,7 +27,7 @@ describe("normalizeAndValidateConfig()", () => {
27
27
  dev: {
28
28
  ip: "localhost",
29
29
  local_protocol: "http",
30
- port: 8787,
30
+ port: undefined, // the default of 8787 is set at runtime
31
31
  upstream_protocol: "https",
32
32
  host: undefined,
33
33
  },
@@ -1,4 +1,5 @@
1
1
  import * as fs from "node:fs";
2
+ import getPort from "get-port";
2
3
  import patchConsole from "patch-console";
3
4
  import dedent from "ts-dedent";
4
5
  import Dev from "../dev/dev";
@@ -432,18 +433,20 @@ describe("wrangler dev", () => {
432
433
  },
433
434
  });
434
435
 
435
- await expect(
436
- runWrangler("dev")
437
- ).rejects.toThrowErrorMatchingInlineSnapshot(
438
- `"Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\""`
439
- );
436
+ await expect(runWrangler("dev")).rejects
437
+ .toThrowErrorMatchingInlineSnapshot(`
438
+ "The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
439
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build."
440
+ `);
440
441
  expect(std.out).toMatchInlineSnapshot(`
441
442
  "Running custom build: node -e \\"console.log('custom build');\\"
442
443
 
443
444
  If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
444
445
  `);
445
446
  expect(std.err).toMatchInlineSnapshot(`
446
- "X [ERROR] Could not resolve \\"index.js\\" after running custom build: node -e \\"console.log('custom build');\\"
447
+ "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
448
+
449
+ The \`main\` property in wrangler.toml should point to the file generated by the custom build.
447
450
 
448
451
  "
449
452
  `);
@@ -580,6 +583,71 @@ describe("wrangler dev", () => {
580
583
  });
581
584
  });
582
585
 
586
+ describe("port", () => {
587
+ it("should default port to 8787 if it is not in use", async () => {
588
+ writeWranglerToml({
589
+ main: "index.js",
590
+ });
591
+ fs.writeFileSync("index.js", `export default {};`);
592
+ await runWrangler("dev");
593
+ expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8787);
594
+ expect(std.out).toMatchInlineSnapshot(`""`);
595
+ expect(std.warn).toMatchInlineSnapshot(`""`);
596
+ expect(std.err).toMatchInlineSnapshot(`""`);
597
+ });
598
+
599
+ it("should use to `port` from `wrangler.toml`, if available", async () => {
600
+ writeWranglerToml({
601
+ main: "index.js",
602
+ dev: {
603
+ port: 8888,
604
+ },
605
+ });
606
+ fs.writeFileSync("index.js", `export default {};`);
607
+ // Mock `getPort()` to resolve to a completely different port.
608
+ (getPort as jest.Mock).mockResolvedValue(98765);
609
+
610
+ await runWrangler("dev");
611
+ expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(8888);
612
+ expect(std.out).toMatchInlineSnapshot(`""`);
613
+ expect(std.warn).toMatchInlineSnapshot(`""`);
614
+ expect(std.err).toMatchInlineSnapshot(`""`);
615
+ });
616
+
617
+ it("should use --port command line arg, if provided", async () => {
618
+ writeWranglerToml({
619
+ main: "index.js",
620
+ dev: {
621
+ port: 8888,
622
+ },
623
+ });
624
+ fs.writeFileSync("index.js", `export default {};`);
625
+ // Mock `getPort()` to resolve to a completely different port.
626
+ (getPort as jest.Mock).mockResolvedValue(98765);
627
+
628
+ await runWrangler("dev --port=9999");
629
+ expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(9999);
630
+ expect(std.out).toMatchInlineSnapshot(`""`);
631
+ expect(std.warn).toMatchInlineSnapshot(`""`);
632
+ expect(std.err).toMatchInlineSnapshot(`""`);
633
+ });
634
+
635
+ it("should use a different port to the default if it is in use", async () => {
636
+ writeWranglerToml({
637
+ main: "index.js",
638
+ });
639
+ fs.writeFileSync("index.js", `export default {};`);
640
+ // Mock `getPort()` to resolve to a completely different port.
641
+ (getPort as jest.Mock).mockResolvedValue(98765);
642
+
643
+ await runWrangler("dev");
644
+ expect((Dev as jest.Mock).mock.calls[0][0].port).toEqual(98765);
645
+ expect(std.out).toMatchInlineSnapshot(`""`);
646
+ expect(std.warn).toMatchInlineSnapshot(`""`);
647
+ expect(std.err).toMatchInlineSnapshot(`""`);
648
+ });
649
+ });
650
+
583
651
  describe("durable_objects", () => {
584
652
  it("should warn if there is one or more remote Durable Object", async () => {
585
653
  writeWranglerToml({
@@ -688,10 +756,9 @@ describe("wrangler dev", () => {
688
756
  script The path to an entry point for your worker [string]
689
757
 
690
758
  Flags:
691
- -c, --config Path to .toml configuration file [string]
692
- -h, --help Show help [boolean]
693
- -v, --version Show version number [boolean]
694
- --legacy-env Use legacy environments [boolean]
759
+ -c, --config Path to .toml configuration file [string]
760
+ -h, --help Show help [boolean]
761
+ -v, --version Show version number [boolean]
695
762
 
696
763
  Options:
697
764
  --name Name of the worker [string]
@@ -44,10 +44,9 @@ describe("wrangler", () => {
44
44
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
45
45
 
46
46
  Flags:
47
- -c, --config Path to .toml configuration file [string]
48
- -h, --help Show help [boolean]
49
- -v, --version Show version number [boolean]
50
- --legacy-env Use legacy environments [boolean]"
47
+ -c, --config Path to .toml configuration file [string]
48
+ -h, --help Show help [boolean]
49
+ -v, --version Show version number [boolean]"
51
50
  `);
52
51
 
53
52
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -85,10 +84,9 @@ describe("wrangler", () => {
85
84
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
86
85
 
87
86
  Flags:
88
- -c, --config Path to .toml configuration file [string]
89
- -h, --help Show help [boolean]
90
- -v, --version Show version number [boolean]
91
- --legacy-env Use legacy environments [boolean]
87
+ -c, --config Path to .toml configuration file [string]
88
+ -h, --help Show help [boolean]
89
+ -v, --version Show version number [boolean]
92
90
  X [ERROR] Unknown argument: invalid-command
93
91
 
94
92
  "
@@ -133,10 +131,9 @@ describe("wrangler", () => {
133
131
  wrangler secret list List all secrets for a script
134
132
 
135
133
  Flags:
136
- -c, --config Path to .toml configuration file [string]
137
- -h, --help Show help [boolean]
138
- -v, --version Show version number [boolean]
139
- --legacy-env Use legacy environments [boolean]"
134
+ -c, --config Path to .toml configuration file [string]
135
+ -h, --help Show help [boolean]
136
+ -v, --version Show version number [boolean]"
140
137
  `);
141
138
  });
142
139
 
@@ -144,20 +141,19 @@ describe("wrangler", () => {
144
141
  await runWrangler("kv:namespace");
145
142
  await endEventLoop();
146
143
  expect(std.out).toMatchInlineSnapshot(`
147
- "wrangler kv:namespace
144
+ "wrangler kv:namespace
148
145
 
149
- 🗂️ Interact with your Workers KV Namespaces
146
+ 🗂️ Interact with your Workers KV Namespaces
150
147
 
151
- Commands:
152
- wrangler kv:namespace create <namespace> Create a new namespace
153
- wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
154
- wrangler kv:namespace delete Deletes a given namespace.
148
+ Commands:
149
+ wrangler kv:namespace create <namespace> Create a new namespace
150
+ wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
151
+ wrangler kv:namespace delete Deletes a given namespace.
155
152
 
156
- Flags:
157
- -c, --config Path to .toml configuration file [string]
158
- -h, --help Show help [boolean]
159
- -v, --version Show version number [boolean]
160
- --legacy-env Use legacy environments [boolean]"
153
+ Flags:
154
+ -c, --config Path to .toml configuration file [string]
155
+ -h, --help Show help [boolean]
156
+ -v, --version Show version number [boolean]"
161
157
  `);
162
158
  });
163
159
 
@@ -165,60 +161,57 @@ describe("wrangler", () => {
165
161
  await runWrangler("kv:key");
166
162
  await endEventLoop();
167
163
  expect(std.out).toMatchInlineSnapshot(`
168
- "wrangler kv:key
164
+ "wrangler kv:key
169
165
 
170
- 🔑 Individually manage Workers KV key-value pairs
166
+ 🔑 Individually manage Workers KV key-value pairs
171
167
 
172
- Commands:
173
- wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
174
- wrangler kv:key list Outputs a list of all keys in a given namespace.
175
- wrangler kv:key get <key> Reads a single value by key from the given namespace.
176
- wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
168
+ Commands:
169
+ wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
170
+ wrangler kv:key list Outputs a list of all keys in a given namespace.
171
+ wrangler kv:key get <key> Reads a single value by key from the given namespace.
172
+ wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
177
173
 
178
- Flags:
179
- -c, --config Path to .toml configuration file [string]
180
- -h, --help Show help [boolean]
181
- -v, --version Show version number [boolean]
182
- --legacy-env Use legacy environments [boolean]"
183
- `);
174
+ Flags:
175
+ -c, --config Path to .toml configuration file [string]
176
+ -h, --help Show help [boolean]
177
+ -v, --version Show version number [boolean]"
178
+ `);
184
179
  });
185
180
 
186
181
  it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
187
182
  await runWrangler("kv:bulk");
188
183
  await endEventLoop();
189
184
  expect(std.out).toMatchInlineSnapshot(`
190
- "wrangler kv:bulk
185
+ "wrangler kv:bulk
191
186
 
192
- 💪 Interact with multiple Workers KV key-value pairs at once
187
+ 💪 Interact with multiple Workers KV key-value pairs at once
193
188
 
194
- Commands:
195
- wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
196
- wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
189
+ Commands:
190
+ wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
191
+ wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
197
192
 
198
- Flags:
199
- -c, --config Path to .toml configuration file [string]
200
- -h, --help Show help [boolean]
201
- -v, --version Show version number [boolean]
202
- --legacy-env Use legacy environments [boolean]"
203
- `);
193
+ Flags:
194
+ -c, --config Path to .toml configuration file [string]
195
+ -h, --help Show help [boolean]
196
+ -v, --version Show version number [boolean]"
197
+ `);
204
198
  });
205
199
  it("no subcommand 'r2' should display a list of available subcommands", async () => {
206
200
  await runWrangler("r2");
207
201
  await endEventLoop();
208
202
  expect(std.out).toMatchInlineSnapshot(`
209
- "wrangler r2
203
+ "wrangler r2
210
204
 
211
- 📦 Interact with an R2 store
205
+ 📦 Interact with an R2 store
212
206
 
213
- Commands:
214
- wrangler r2 bucket Manage R2 buckets
207
+ Commands:
208
+ wrangler r2 bucket Manage R2 buckets
215
209
 
216
- Flags:
217
- -c, --config Path to .toml configuration file [string]
218
- -h, --help Show help [boolean]
219
- -v, --version Show version number [boolean]
220
- --legacy-env Use legacy environments [boolean]"
221
- `);
210
+ Flags:
211
+ -c, --config Path to .toml configuration file [string]
212
+ -h, --help Show help [boolean]
213
+ -v, --version Show version number [boolean]"
214
+ `);
222
215
  });
223
216
  });
224
217
  describe("Deprecated commands", () => {
@@ -241,7 +234,7 @@ describe("wrangler", () => {
241
234
  await runWrangler("build").catch((err) => {
242
235
  expect(err.message).toMatchInlineSnapshot(`
243
236
  "Deprecation:
244
- \`wrangler build\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#build for alternatives"
237
+ \`wrangler build\` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for alternatives"
245
238
  `);
246
239
  });
247
240
  });
@@ -8,6 +8,14 @@ import { confirm, prompt } from "../dialogs";
8
8
  import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
9
9
  import { MockWebSocket } from "./helpers/mock-web-socket";
10
10
 
11
+ // Mock out getPort since we don't actually care about what ports are open in unit tests.
12
+ jest.mock("get-port", () => {
13
+ return {
14
+ __esModule: true,
15
+ default: jest.fn().mockImplementation(async (options) => options.port),
16
+ };
17
+ });
18
+
11
19
  jest.mock("ws", () => {
12
20
  return {
13
21
  __esModule: true,