wrangler 2.0.16 → 2.0.17

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.
package/bin/wrangler.js CHANGED
@@ -6,6 +6,10 @@ const os = require("os");
6
6
  const semiver = require("semiver");
7
7
 
8
8
  const MIN_NODE_VERSION = "16.7.0";
9
+ const debug =
10
+ process.env["WRANGLER_LOG"] === "debug"
11
+ ? (...args) => console.log(...args)
12
+ : () => {};
9
13
 
10
14
  let wranglerProcess;
11
15
 
@@ -84,9 +88,8 @@ function runDelegatedWrangler() {
84
88
  } = JSON.parse(fs.readFileSync(packageJsonPath));
85
89
  const resolvedBinaryPath = path.resolve(packageJsonPath, "..", binaryPath);
86
90
 
87
- console.log(
88
- `Delegating to locally-installed version of wrangler @ v${version}`
89
- );
91
+ debug(`Delegating to locally-installed version of wrangler @ v${version}`);
92
+
90
93
  // this call to `spawn` is simpler because the delegated version will do all
91
94
  // of the other work.
92
95
  return spawn(
@@ -4871,6 +4871,7 @@ async function main() {
4871
4871
  try {
4872
4872
  await mf.startServer();
4873
4873
  await mf.startScheduler();
4874
+ process.send && process.send("ready");
4874
4875
  } catch (e) {
4875
4876
  mf.log.error(e);
4876
4877
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,18 +1,7 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.16",
4
- "author": "wrangler@cloudflare.com",
3
+ "version": "2.0.17",
5
4
  "description": "Command-line interface for all things Cloudflare Workers",
6
- "bin": {
7
- "wrangler": "./bin/wrangler.js",
8
- "wrangler2": "./bin/wrangler.js"
9
- },
10
- "main": "wrangler-dist/cli.js",
11
- "license": "MIT OR Apache-2.0",
12
- "bugs": {
13
- "url": "https://github.com/cloudflare/wrangler2/issues"
14
- },
15
- "homepage": "https://github.com/cloudflare/wrangler2#readme",
16
5
  "keywords": [
17
6
  "wrangler",
18
7
  "cloudflare",
@@ -29,31 +18,87 @@
29
18
  "webassembly",
30
19
  "rust",
31
20
  "emscripten",
32
- "rust",
33
21
  "typescript",
34
22
  "graphql",
35
23
  "router",
36
24
  "http",
37
25
  "cli"
38
26
  ],
27
+ "homepage": "https://github.com/cloudflare/wrangler2#readme",
28
+ "bugs": {
29
+ "url": "https://github.com/cloudflare/wrangler2/issues"
30
+ },
31
+ "license": "MIT OR Apache-2.0",
32
+ "author": "wrangler@cloudflare.com",
33
+ "main": "wrangler-dist/cli.js",
34
+ "types": "wrangler-dist/cli.d.ts",
35
+ "bin": {
36
+ "wrangler": "./bin/wrangler.js",
37
+ "wrangler2": "./bin/wrangler.js"
38
+ },
39
+ "files": [
40
+ "src",
41
+ "bin",
42
+ "miniflare-config-stubs",
43
+ "miniflare-dist",
44
+ "wrangler-dist",
45
+ "templates",
46
+ "vendor",
47
+ "import_meta_url.js",
48
+ "kv-asset-handler.js",
49
+ "Cloudflare_CA.pem"
50
+ ],
51
+ "scripts": {
52
+ "build": "npm run clean && npm run bundle && npm run emit-types",
53
+ "bundle": "node -r esbuild-register scripts/bundle.ts",
54
+ "check:type": "tsc",
55
+ "clean": "rm -rf wrangler-dist miniflare-dist emitted-types",
56
+ "dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
57
+ "emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
58
+ "prepublishOnly": "SOURCEMAPS=false npm run build",
59
+ "start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
60
+ "test": "jest --silent=false --verbose=true",
61
+ "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
62
+ },
63
+ "jest": {
64
+ "moduleNameMapper": {
65
+ "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
66
+ "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
67
+ },
68
+ "restoreMocks": true,
69
+ "setupFilesAfterEnv": [
70
+ "<rootDir>/src/__tests__/jest.setup.ts"
71
+ ],
72
+ "testRegex": ".*.(test|spec)\\.[jt]sx?$",
73
+ "testTimeout": 30000,
74
+ "transform": {
75
+ "^.+\\.c?(t|j)sx?$": [
76
+ "esbuild-jest",
77
+ {
78
+ "sourcemap": true
79
+ }
80
+ ]
81
+ },
82
+ "transformIgnorePatterns": [
83
+ "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)"
84
+ ]
85
+ },
39
86
  "dependencies": {
40
87
  "@cloudflare/kv-asset-handler": "^0.2.0",
41
88
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
42
89
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
43
90
  "blake3-wasm": "^2.1.5",
44
91
  "esbuild": "0.14.47",
45
- "miniflare": "^2.5.1",
92
+ "miniflare": "^2.6.0",
46
93
  "nanoid": "^3.3.3",
47
94
  "path-to-regexp": "^6.2.0",
48
95
  "selfsigned": "^2.0.1",
49
96
  "semiver": "^1.1.0",
50
97
  "xxhash-wasm": "^1.0.1"
51
98
  },
52
- "optionalDependencies": {
53
- "fsevents": "~2.3.2"
54
- },
55
99
  "devDependencies": {
56
100
  "@iarna/toml": "^3.0.0",
101
+ "@microsoft/api-extractor": "^7.28.3",
57
102
  "@types/command-exists": "^1.2.0",
58
103
  "@types/glob-to-regexp": "0.4.1",
59
104
  "@types/mime": "^2.0.3",
@@ -106,53 +151,10 @@
106
151
  "ws": "^8.5.0",
107
152
  "yargs": "^17.4.1"
108
153
  },
109
- "files": [
110
- "src",
111
- "bin",
112
- "miniflare-config-stubs",
113
- "miniflare-dist",
114
- "wrangler-dist",
115
- "templates",
116
- "vendor",
117
- "import_meta_url.js",
118
- "kv-asset-handler.js",
119
- "Cloudflare_CA.pem"
120
- ],
121
- "scripts": {
122
- "clean": "rm -rf wrangler-dist miniflare-dist",
123
- "check:type": "tsc",
124
- "bundle": "node -r esbuild-register scripts/bundle.ts",
125
- "build": "npm run clean && npm run bundle",
126
- "dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
127
- "prepublishOnly": "SOURCEMAPS=false npm run build",
128
- "start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
129
- "test": "jest --silent=false --verbose=true",
130
- "test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
154
+ "optionalDependencies": {
155
+ "fsevents": "~2.3.2"
131
156
  },
132
157
  "engines": {
133
158
  "node": ">=16.7.0"
134
- },
135
- "jest": {
136
- "restoreMocks": true,
137
- "testTimeout": 30000,
138
- "testRegex": ".*.(test|spec)\\.[jt]sx?$",
139
- "transformIgnorePatterns": [
140
- "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)"
141
- ],
142
- "moduleNameMapper": {
143
- "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
144
- "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
145
- },
146
- "transform": {
147
- "^.+\\.c?(t|j)sx?$": [
148
- "esbuild-jest",
149
- {
150
- "sourcemap": true
151
- }
152
- ]
153
- },
154
- "setupFilesAfterEnv": [
155
- "<rootDir>/src/__tests__/jest.setup.ts"
156
- ]
157
159
  }
158
160
  }
@@ -5,7 +5,9 @@ import { reinitialiseAuthTokens } from "../../user";
5
5
 
6
6
  const originalCwd = process.cwd();
7
7
 
8
- export function runInTempDir({ homedir }: { homedir?: string } = {}) {
8
+ export function runInTempDir(
9
+ { homedir }: { homedir?: string } = { homedir: "./home" }
10
+ ) {
9
11
  let tmpDir: string;
10
12
 
11
13
  beforeAll(() => {
@@ -16,17 +18,22 @@ export function runInTempDir({ homedir }: { homedir?: string } = {}) {
16
18
  });
17
19
 
18
20
  beforeEach(() => {
19
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
21
+ // Use realpath because the temporary path can point to a symlink rather than the actual path.
22
+ tmpDir = fs.realpathSync(
23
+ fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"))
24
+ );
20
25
  process.chdir(tmpDir);
21
26
  if (homedir !== undefined) {
27
+ // The path that is returned from `homedir()` should be absolute.
28
+ const absHomedir = path.resolve(tmpDir, homedir);
22
29
  // Override where the home directory is so that we can write our own user config,
23
30
  // without destroying the real thing.
24
- fs.mkdirSync(homedir);
31
+ fs.mkdirSync(absHomedir, { recursive: true });
25
32
  // Note it is very important that we use the "default" value from "node:os" (e.g. `import os from "node:os";`)
26
33
  // rather than an alias to the module (e.g. `import * as os from "node:os";`).
27
34
  // This is because the module gets transpiled so that the "method" `homedir()` gets converted to a
28
35
  // getter that is not configurable (and so cannot be spied upon).
29
- jest.spyOn(os, "homedir").mockReturnValue(homedir);
36
+ jest.spyOn(os, "homedir").mockReturnValue(absHomedir);
30
37
  // Now that we have changed the home directory location, we must reinitialize the user auth state
31
38
  reinitialiseAuthTokens();
32
39
  }
@@ -6,7 +6,7 @@ import { mockConsoleMethods } from "./helpers/mock-console";
6
6
  import { runInTempDir } from "./helpers/run-in-tmp";
7
7
 
8
8
  describe("getHttpsOptions()", () => {
9
- runInTempDir({ homedir: "./home" });
9
+ runInTempDir();
10
10
  const std = mockConsoleMethods();
11
11
 
12
12
  it("should use cached values if they have not expired", async () => {
@@ -35,7 +35,7 @@ describe("wrangler", () => {
35
35
  wrangler dev [script] 👂 Start a local server for developing your worker
36
36
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
37
37
  wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
38
- wrangler secret 🤫 Generate a secret that can be referenced in the worker script
38
+ wrangler secret 🤫 Generate a secret that can be referenced in a Worker
39
39
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
40
40
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
41
41
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
@@ -74,7 +74,7 @@ describe("wrangler", () => {
74
74
  wrangler dev [script] 👂 Start a local server for developing your worker
75
75
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
76
76
  wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
77
- wrangler secret 🤫 Generate a secret that can be referenced in the worker script
77
+ wrangler secret 🤫 Generate a secret that can be referenced in a Worker
78
78
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
79
79
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
80
80
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
@@ -123,20 +123,20 @@ describe("wrangler", () => {
123
123
  await runWrangler("secret");
124
124
  await endEventLoop();
125
125
  expect(std.out).toMatchInlineSnapshot(`
126
- "wrangler secret
126
+ "wrangler secret
127
127
 
128
- 🤫 Generate a secret that can be referenced in the worker script
128
+ 🤫 Generate a secret that can be referenced in a Worker
129
129
 
130
- Commands:
131
- wrangler secret put <key> Create or update a secret variable for a script
132
- wrangler secret delete <key> Delete a secret variable from a script
133
- wrangler secret list List all secrets for a script
130
+ Commands:
131
+ wrangler secret put <key> Create or update a secret variable for a Worker
132
+ wrangler secret delete <key> Delete a secret variable from a Worker
133
+ wrangler secret list List all secrets for a Worker
134
134
 
135
- Flags:
136
- -c, --config Path to .toml configuration file [string]
137
- -h, --help Show help [boolean]
138
- -v, --version Show version number [boolean]"
139
- `);
135
+ Flags:
136
+ -c, --config Path to .toml configuration file [string]
137
+ -h, --help Show help [boolean]
138
+ -v, --version Show version number [boolean]"
139
+ `);
140
140
  });
141
141
 
142
142
  it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
@@ -1,5 +1,5 @@
1
1
  import { writeFileSync } from "node:fs";
2
- import { Headers } from "undici";
2
+ import { FormData, Headers } from "undici";
3
3
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
4
4
  import {
5
5
  setMockResponse,
@@ -330,7 +330,15 @@ describe("wrangler", () => {
330
330
  expect(accountId).toEqual("some-account-id");
331
331
  expect(namespaceId).toEqual(expectedNamespaceId);
332
332
  expect(key).toEqual(expectedKV.key);
333
- expect(body).toEqual(expectedKV.value);
333
+ if (expectedKV.metadata) {
334
+ expect(body).toBeInstanceOf(FormData);
335
+ expect((body as FormData).get("value")).toEqual(expectedKV.value);
336
+ expect((body as FormData).get("metadata")).toEqual(
337
+ JSON.stringify(expectedKV.metadata)
338
+ );
339
+ } else {
340
+ expect(body).toEqual(expectedKV.value);
341
+ }
334
342
  if (expectedKV.expiration !== undefined) {
335
343
  expect(query.get("expiration")).toEqual(
336
344
  `${expectedKV.expiration}`
@@ -488,6 +496,24 @@ describe("wrangler", () => {
488
496
  expect(requests.count).toEqual(1);
489
497
  });
490
498
 
499
+ it("should put a key with metadata", async () => {
500
+ const requests = mockKeyPutRequest("some-namespace-id", {
501
+ key: "dKey",
502
+ value: "dVal",
503
+ metadata: {
504
+ mKey: "mValue",
505
+ },
506
+ });
507
+ await runWrangler(
508
+ `kv:key put dKey dVal --namespace-id some-namespace-id --metadata {"mKey":"mValue"}`
509
+ );
510
+ expect(requests.count).toEqual(1);
511
+ expect(std.out).toMatchInlineSnapshot(
512
+ `"Writing the value \\"dVal\\" to key \\"dKey\\" on namespace some-namespace-id with metadata \\"{\\"mKey\\":\\"mValue\\"}\\"."`
513
+ );
514
+ expect(std.err).toMatchInlineSnapshot(`""`);
515
+ });
516
+
491
517
  it("should error if no key is provided", async () => {
492
518
  await expect(
493
519
  runWrangler("kv:key put")
@@ -517,6 +543,7 @@ describe("wrangler", () => {
517
543
  --preview Interact with a preview namespace [boolean]
518
544
  --ttl Time for which the entries should be visible [number]
519
545
  --expiration Time since the UNIX epoch after which the entry expires [number]
546
+ --metadata Arbitrary JSON that is associated with a key [string]
520
547
  --path Read value from the file at a given path [string]"
521
548
  `);
522
549
  expect(std.err).toMatchInlineSnapshot(`
@@ -555,6 +582,7 @@ describe("wrangler", () => {
555
582
  --preview Interact with a preview namespace [boolean]
556
583
  --ttl Time for which the entries should be visible [number]
557
584
  --expiration Time since the UNIX epoch after which the entry expires [number]
585
+ --metadata Arbitrary JSON that is associated with a key [string]
558
586
  --path Read value from the file at a given path [string]"
559
587
  `);
560
588
  expect(std.err).toMatchInlineSnapshot(`
@@ -593,6 +621,7 @@ describe("wrangler", () => {
593
621
  --preview Interact with a preview namespace [boolean]
594
622
  --ttl Time for which the entries should be visible [number]
595
623
  --expiration Time since the UNIX epoch after which the entry expires [number]
624
+ --metadata Arbitrary JSON that is associated with a key [string]
596
625
  --path Read value from the file at a given path [string]"
597
626
  `);
598
627
  expect(std.err).toMatchInlineSnapshot(`
@@ -631,6 +660,7 @@ describe("wrangler", () => {
631
660
  --preview Interact with a preview namespace [boolean]
632
661
  --ttl Time for which the entries should be visible [number]
633
662
  --expiration Time since the UNIX epoch after which the entry expires [number]
663
+ --metadata Arbitrary JSON that is associated with a key [string]
634
664
  --path Read value from the file at a given path [string]"
635
665
  `);
636
666
  expect(std.err).toMatchInlineSnapshot(`
@@ -669,6 +699,7 @@ describe("wrangler", () => {
669
699
  --preview Interact with a preview namespace [boolean]
670
700
  --ttl Time for which the entries should be visible [number]
671
701
  --expiration Time since the UNIX epoch after which the entry expires [number]
702
+ --metadata Arbitrary JSON that is associated with a key [string]
672
703
  --path Read value from the file at a given path [string]"
673
704
  `);
674
705
  expect(std.err).toMatchInlineSnapshot(`
@@ -29,7 +29,7 @@ import type { FormData, File } from "undici";
29
29
  describe("publish", () => {
30
30
  mockAccountId();
31
31
  mockApiToken();
32
- runInTempDir({ homedir: "./home" });
32
+ runInTempDir();
33
33
  const { setIsTTY } = useMockIsTTY();
34
34
  const std = mockConsoleMethods();
35
35
  const {
@@ -97,33 +97,23 @@ describe("publish", () => {
97
97
  api_token: "some-api-token",
98
98
  });
99
99
 
100
- const accessTokenRequest = mockGrantAccessToken({ respondWith: "ok" });
101
- mockGrantAuthorization({ respondWith: "success" });
102
-
103
100
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
104
101
 
105
- expect(accessTokenRequest.actual.url).toEqual(
106
- accessTokenRequest.expected.url
107
- );
108
-
109
102
  expect(std.out).toMatchInlineSnapshot(`
110
- "Attempting to login via OAuth...
111
- Opening a link in your default browser: https://dash.cloudflare.com/oauth2/auth?response_type=code&client_id=54d11594-84e4-41aa-b438-e81b8fa78ee7&redirect_uri=http%3A%2F%2Flocalhost%3A8976%2Foauth%2Fcallback&scope=account%3Aread%20user%3Aread%20workers%3Awrite%20workers_kv%3Awrite%20workers_routes%3Awrite%20workers_scripts%3Awrite%20workers_tail%3Aread%20pages%3Awrite%20zone%3Aread%20offline_access&state=MOCK_STATE_PARAM&code_challenge=MOCK_CODE_CHALLENGE&code_challenge_method=S256
112
- Successfully logged in.
113
- Total Upload: 0xx KiB / gzip: 0xx KiB
114
- Uploaded test-name (TIMINGS)
115
- Published test-name (TIMINGS)
116
- test-name.test-sub-domain.workers.dev"
117
- `);
103
+ "Total Upload: 0xx KiB / gzip: 0xx KiB
104
+ Uploaded test-name (TIMINGS)
105
+ Published test-name (TIMINGS)
106
+ test-name.test-sub-domain.workers.dev"
107
+ `);
118
108
  expect(std.warn).toMatchInlineSnapshot(`
119
- "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
109
+ "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
120
110
 
121
- This is no longer supported in the current version of Wrangler.
122
- If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\`
123
- environment variable.
111
+ This is no longer supported in the current version of Wrangler.
112
+ If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\`
113
+ environment variable.
124
114
 
125
- "
126
- `);
115
+ "
116
+ `);
127
117
  expect(std.err).toMatchInlineSnapshot(`""`);
128
118
  });
129
119