wrangler 0.0.0-e2a26a0 → 0.0.0-e322475
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/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +54 -27
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +223 -36
- package/pages/functions/filepath-routing.ts +78 -120
- package/pages/functions/routes.ts +13 -17
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +24 -17
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +3548 -0
- package/src/__tests__/dev.test.tsx +1049 -65
- package/src/__tests__/guess-worker-format.test.ts +85 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -8
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +12 -8
- package/src/__tests__/helpers/mock-console.ts +49 -8
- package/src/__tests__/helpers/mock-dialogs.ts +99 -11
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-process.ts +24 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +150 -435
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +75 -5
- package/src/__tests__/kv.test.ts +634 -253
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/package-manager.test.ts +156 -9
- package/src/__tests__/pages.test.ts +754 -0
- package/src/__tests__/parse.test.ts +330 -0
- package/src/__tests__/publish.test.ts +5895 -961
- package/src/__tests__/r2.test.ts +233 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +362 -91
- package/src/__tests__/tail.test.ts +690 -0
- package/src/__tests__/user.test.ts +132 -0
- package/src/__tests__/whoami.test.tsx +60 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +204 -0
- package/src/cfetch/index.ts +27 -8
- package/src/cfetch/internal.ts +75 -34
- package/src/cli.ts +6 -2
- package/src/config/README.md +107 -0
- package/src/config/config.ts +243 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +420 -0
- package/src/config/index.ts +225 -0
- package/src/config/validation-helpers.ts +584 -0
- package/src/config/validation.ts +1580 -0
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +185 -0
- package/src/create-worker-upload-form.ts +254 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +399 -0
- package/src/dev/local.tsx +321 -0
- package/src/dev/remote.tsx +249 -0
- package/src/dev/use-esbuild.ts +112 -0
- package/src/dialogs.tsx +64 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +328 -0
- package/src/environment-variables.ts +35 -0
- package/src/errors.ts +11 -0
- package/src/generate-auth-url.ts +33 -0
- package/src/generate-random-state.ts +16 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1804 -1009
- package/src/inspect.ts +80 -14
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +193 -69
- package/src/logger.ts +73 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +226 -31
- package/src/open-in-browser.ts +17 -0
- package/src/package-manager.ts +79 -25
- package/src/pages.tsx +1131 -84
- package/src/parse.ts +222 -0
- package/src/proxy.ts +176 -70
- package/src/publish.ts +637 -308
- package/src/r2.ts +50 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +185 -57
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +67 -0
- package/src/update-check.ts +19 -0
- package/src/user.tsx +349 -166
- package/src/whoami.tsx +5 -3
- package/src/{api/worker.ts → worker.ts} +65 -39
- package/src/zones.ts +73 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +17 -2
- package/templates/no-op-worker.js +10 -0
- package/templates/static-asset-facade.js +3 -7
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +77463 -75999
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/api/form_data.ts +0 -134
- package/src/api/preview.ts +0 -128
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/tail.tsx +0 -73
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
|
-
import * as TOML from "@iarna/toml";
|
|
4
|
-
import { version as wranglerVersion } from "../../package.json";
|
|
5
1
|
import { getPackageManager } from "../package-manager";
|
|
6
2
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
8
3
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
4
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
5
|
+
import { writeWorkerSource } from "./helpers/write-worker-source";
|
|
6
|
+
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
10
7
|
import type { PackageManager } from "../package-manager";
|
|
11
8
|
|
|
12
9
|
describe("wrangler", () => {
|
|
@@ -15,6 +12,9 @@ describe("wrangler", () => {
|
|
|
15
12
|
|
|
16
13
|
beforeEach(() => {
|
|
17
14
|
mockPackageManager = {
|
|
15
|
+
cwd: process.cwd(),
|
|
16
|
+
// @ts-expect-error we're making a fake package manager here
|
|
17
|
+
type: "mockpm",
|
|
18
18
|
addDevDeps: jest.fn(),
|
|
19
19
|
install: jest.fn(),
|
|
20
20
|
};
|
|
@@ -32,23 +32,23 @@ describe("wrangler", () => {
|
|
|
32
32
|
|
|
33
33
|
Commands:
|
|
34
34
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
35
|
-
wrangler
|
|
36
|
-
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
35
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
37
36
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
38
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
37
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
39
38
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
40
39
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
41
40
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
42
41
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
43
42
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
43
|
+
wrangler r2 📦 Interact with an R2 store
|
|
44
|
+
wrangler login 🔓 Login to Cloudflare
|
|
45
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
46
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
44
47
|
|
|
45
48
|
Flags:
|
|
46
49
|
-c, --config Path to .toml configuration file [string]
|
|
47
50
|
-h, --help Show help [boolean]
|
|
48
|
-
-v, --version Show version number [boolean]
|
|
49
|
-
|
|
50
|
-
Options:
|
|
51
|
-
-l, --local Run on my machine [boolean] [default: false]"
|
|
51
|
+
-v, --version Show version number [boolean]"
|
|
52
52
|
`);
|
|
53
53
|
|
|
54
54
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -60,484 +60,199 @@ describe("wrangler", () => {
|
|
|
60
60
|
await expect(
|
|
61
61
|
runWrangler("invalid-command")
|
|
62
62
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
63
|
-
`"Unknown
|
|
63
|
+
`"Unknown argument: invalid-command"`
|
|
64
64
|
);
|
|
65
65
|
|
|
66
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
67
|
+
"
|
|
68
|
+
wrangler
|
|
69
69
|
|
|
70
70
|
Commands:
|
|
71
71
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
72
|
-
wrangler
|
|
73
|
-
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
72
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
74
73
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
75
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a
|
|
74
|
+
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
76
75
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
77
76
|
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
78
77
|
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
79
78
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
80
79
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
80
|
+
wrangler r2 📦 Interact with an R2 store
|
|
81
|
+
wrangler login 🔓 Login to Cloudflare
|
|
82
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
83
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
81
84
|
|
|
82
85
|
Flags:
|
|
83
86
|
-c, --config Path to .toml configuration file [string]
|
|
84
87
|
-h, --help Show help [boolean]
|
|
85
|
-
-v, --version Show version number [boolean]
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
-v, --version Show version number [boolean]"
|
|
89
|
+
`);
|
|
90
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
91
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: invalid-command[0m
|
|
89
92
|
|
|
90
|
-
|
|
93
|
+
"
|
|
91
94
|
`);
|
|
92
95
|
});
|
|
93
96
|
});
|
|
94
97
|
|
|
95
|
-
describe("
|
|
96
|
-
it("should
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
expect(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
112
|
-
"utf-8"
|
|
113
|
-
);
|
|
114
|
-
mockConfirm({
|
|
115
|
-
text: "Do you want to continue initializing this project?",
|
|
116
|
-
result: false,
|
|
117
|
-
});
|
|
118
|
-
await runWrangler("init");
|
|
119
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
120
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
121
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
125
|
-
fs.writeFileSync(
|
|
126
|
-
"./wrangler.toml",
|
|
127
|
-
`compatibility_date="something-else"`,
|
|
128
|
-
"utf-8"
|
|
129
|
-
);
|
|
130
|
-
mockConfirm(
|
|
131
|
-
{
|
|
132
|
-
text: "Do you want to continue initializing this project?",
|
|
133
|
-
result: true,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
text: "No package.json found. Would you like to create one?",
|
|
137
|
-
result: false,
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
await runWrangler("init");
|
|
141
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
142
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
143
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should create a package.json if none is found and user confirms", async () => {
|
|
147
|
-
mockConfirm(
|
|
148
|
-
{
|
|
149
|
-
text: "No package.json found. Would you like to create one?",
|
|
150
|
-
result: true,
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
text: "Would you like to use TypeScript?",
|
|
154
|
-
result: false,
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
158
|
-
result: false,
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
await runWrangler("init");
|
|
162
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
163
|
-
const packageJson = JSON.parse(
|
|
164
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
165
|
-
);
|
|
166
|
-
expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
|
|
167
|
-
expect(packageJson.version).toEqual("0.0.0");
|
|
168
|
-
expect(packageJson.devDependencies).toEqual({
|
|
169
|
-
wrangler: expect.any(String),
|
|
170
|
-
});
|
|
171
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
172
|
-
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
98
|
+
describe("preview", () => {
|
|
99
|
+
it("should throw an error if the deprecated command is used with positional arguments", async () => {
|
|
100
|
+
await expect(runWrangler("preview GET")).rejects
|
|
101
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
102
|
+
"Deprecation:
|
|
103
|
+
The \`wrangler preview\` command has been deprecated.
|
|
104
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
105
|
+
"
|
|
106
|
+
`);
|
|
107
|
+
await expect(runWrangler(`preview GET "SomeBody"`)).rejects
|
|
108
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
109
|
+
"Deprecation:
|
|
110
|
+
The \`wrangler preview\` command has been deprecated.
|
|
111
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
112
|
+
"
|
|
113
|
+
`);
|
|
173
114
|
});
|
|
115
|
+
});
|
|
174
116
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
text: "Would you like to use TypeScript?",
|
|
183
|
-
result: false,
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
187
|
-
result: false,
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
fs.writeFileSync(
|
|
192
|
-
"./package.json",
|
|
193
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
194
|
-
"utf-8"
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
await runWrangler("init");
|
|
198
|
-
const packageJson = JSON.parse(
|
|
199
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
200
|
-
);
|
|
201
|
-
expect(packageJson.name).toEqual("test");
|
|
202
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
203
|
-
});
|
|
117
|
+
describe("subcommand implicit help ran on incomplete command execution", () => {
|
|
118
|
+
it("no subcommand for 'secret' should display a list of available subcommands", async () => {
|
|
119
|
+
await runWrangler("secret");
|
|
120
|
+
await endEventLoop();
|
|
121
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
122
|
+
"wrangler secret
|
|
204
123
|
|
|
205
|
-
|
|
206
|
-
mockConfirm(
|
|
207
|
-
{
|
|
208
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
209
|
-
result: true,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
text: "Would you like to use TypeScript?",
|
|
213
|
-
result: false,
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
217
|
-
result: false,
|
|
218
|
-
}
|
|
219
|
-
);
|
|
124
|
+
🤫 Generate a secret that can be referenced in the worker script
|
|
220
125
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
126
|
+
Commands:
|
|
127
|
+
wrangler secret put <key> Create or update a secret variable for a script
|
|
128
|
+
wrangler secret delete <key> Delete a secret variable from a script
|
|
129
|
+
wrangler secret list List all secrets for a script
|
|
226
130
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
233
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
234
|
-
`wrangler@${wranglerVersion}`
|
|
235
|
-
);
|
|
131
|
+
Flags:
|
|
132
|
+
-c, --config Path to .toml configuration file [string]
|
|
133
|
+
-h, --help Show help [boolean]
|
|
134
|
+
-v, --version Show version number [boolean]"
|
|
135
|
+
`);
|
|
236
136
|
});
|
|
237
137
|
|
|
238
|
-
it("
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
text: "Would you like to use TypeScript?",
|
|
246
|
-
result: false,
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
250
|
-
result: false,
|
|
251
|
-
}
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
fs.writeFileSync(
|
|
255
|
-
"./package.json",
|
|
256
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
257
|
-
"utf-8"
|
|
258
|
-
);
|
|
138
|
+
it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
|
|
139
|
+
await runWrangler("kv:namespace");
|
|
140
|
+
await endEventLoop();
|
|
141
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
142
|
+
"wrangler kv:namespace
|
|
259
143
|
|
|
260
|
-
|
|
261
|
-
process.chdir("./sub-1/sub-2");
|
|
144
|
+
🗂️ Interact with your Workers KV Namespaces
|
|
262
145
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
146
|
+
Commands:
|
|
147
|
+
wrangler kv:namespace create <namespace> Create a new namespace
|
|
148
|
+
wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
|
|
149
|
+
wrangler kv:namespace delete Deletes a given namespace.
|
|
266
150
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
Object {
|
|
272
|
-
"name": "test",
|
|
273
|
-
"version": "1.0.0",
|
|
274
|
-
}
|
|
151
|
+
Flags:
|
|
152
|
+
-c, --config Path to .toml configuration file [string]
|
|
153
|
+
-h, --help Show help [boolean]
|
|
154
|
+
-v, --version Show version number [boolean]"
|
|
275
155
|
`);
|
|
276
156
|
});
|
|
277
157
|
|
|
278
|
-
it("
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
text: "Would you like to use TypeScript?",
|
|
286
|
-
result: false,
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
290
|
-
result: true,
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
fs.writeFileSync(
|
|
295
|
-
"./package.json",
|
|
296
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
297
|
-
"utf-8"
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
await runWrangler("init");
|
|
301
|
-
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
302
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it("should offer to create a worker in a typescript project", async () => {
|
|
306
|
-
mockConfirm(
|
|
307
|
-
{
|
|
308
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
309
|
-
result: false,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
text: "Would you like to use TypeScript?",
|
|
313
|
-
result: true,
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
317
|
-
result: true,
|
|
318
|
-
}
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
fs.writeFileSync(
|
|
322
|
-
"./package.json",
|
|
323
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
324
|
-
"utf-8"
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
await runWrangler("init");
|
|
328
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
329
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
330
|
-
});
|
|
158
|
+
it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
|
|
159
|
+
await runWrangler("kv:key");
|
|
160
|
+
await endEventLoop();
|
|
161
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
162
|
+
"wrangler kv:key
|
|
331
163
|
|
|
332
|
-
|
|
333
|
-
mockConfirm(
|
|
334
|
-
{
|
|
335
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
336
|
-
result: false,
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
text: "Would you like to use TypeScript?",
|
|
340
|
-
result: false,
|
|
341
|
-
}
|
|
342
|
-
);
|
|
164
|
+
🔑 Individually manage Workers KV key-value pairs
|
|
343
165
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
350
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
351
|
-
fs.writeFileSync("./src/index.js", PLACEHOLDER, "utf-8");
|
|
166
|
+
Commands:
|
|
167
|
+
wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
|
|
168
|
+
wrangler kv:key list Outputs a list of all keys in a given namespace.
|
|
169
|
+
wrangler kv:key get <key> Reads a single value by key from the given namespace.
|
|
170
|
+
wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
|
|
352
171
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
172
|
+
Flags:
|
|
173
|
+
-c, --config Path to .toml configuration file [string]
|
|
174
|
+
-h, --help Show help [boolean]
|
|
175
|
+
-v, --version Show version number [boolean]"
|
|
176
|
+
`);
|
|
356
177
|
});
|
|
357
178
|
|
|
358
|
-
it("
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
text: "Would you like to use TypeScript?",
|
|
366
|
-
result: true,
|
|
367
|
-
}
|
|
368
|
-
);
|
|
179
|
+
it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
|
|
180
|
+
await runWrangler("kv:bulk");
|
|
181
|
+
await endEventLoop();
|
|
182
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
183
|
+
"wrangler kv:bulk
|
|
369
184
|
|
|
370
|
-
|
|
371
|
-
"./package.json",
|
|
372
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
373
|
-
"utf-8"
|
|
374
|
-
);
|
|
375
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
376
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
377
|
-
fs.writeFileSync("./src/index.ts", PLACEHOLDER, "utf-8");
|
|
185
|
+
💪 Interact with multiple Workers KV key-value pairs at once
|
|
378
186
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
});
|
|
187
|
+
Commands:
|
|
188
|
+
wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
|
|
189
|
+
wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
|
|
383
190
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
text: "Would you like to use TypeScript?",
|
|
392
|
-
result: true,
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
396
|
-
result: false,
|
|
397
|
-
}
|
|
398
|
-
);
|
|
399
|
-
await runWrangler("init");
|
|
400
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
401
|
-
const tsconfigJson = JSON.parse(
|
|
402
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
403
|
-
);
|
|
404
|
-
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
405
|
-
"@cloudflare/workers-types",
|
|
406
|
-
]);
|
|
407
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
408
|
-
"@cloudflare/workers-types",
|
|
409
|
-
"typescript"
|
|
410
|
-
);
|
|
191
|
+
Flags:
|
|
192
|
+
-c, --config Path to .toml configuration file [string]
|
|
193
|
+
-h, --help Show help [boolean]
|
|
194
|
+
-v, --version Show version number [boolean]"
|
|
195
|
+
`);
|
|
411
196
|
});
|
|
412
197
|
|
|
413
|
-
it("
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
version: "1.0.0",
|
|
419
|
-
devDependencies: {
|
|
420
|
-
wrangler: "0.0.0",
|
|
421
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
422
|
-
},
|
|
423
|
-
}),
|
|
424
|
-
"utf-8"
|
|
425
|
-
);
|
|
426
|
-
fs.writeFileSync(
|
|
427
|
-
"./tsconfig.json",
|
|
428
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
429
|
-
"utf-8"
|
|
430
|
-
);
|
|
198
|
+
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
199
|
+
await runWrangler("r2");
|
|
200
|
+
await endEventLoop();
|
|
201
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
202
|
+
"wrangler r2
|
|
431
203
|
|
|
432
|
-
|
|
433
|
-
const tsconfigJson = JSON.parse(
|
|
434
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
435
|
-
);
|
|
436
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
437
|
-
});
|
|
204
|
+
📦 Interact with an R2 store
|
|
438
205
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
{
|
|
442
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
443
|
-
result: false,
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
447
|
-
result: true,
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
451
|
-
result: false,
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
fs.writeFileSync(
|
|
455
|
-
"./package.json",
|
|
456
|
-
JSON.stringify({
|
|
457
|
-
name: "test",
|
|
458
|
-
version: "1.0.0",
|
|
459
|
-
}),
|
|
460
|
-
"utf-8"
|
|
461
|
-
);
|
|
462
|
-
fs.writeFileSync(
|
|
463
|
-
"./tsconfig.json",
|
|
464
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
465
|
-
"utf-8"
|
|
466
|
-
);
|
|
206
|
+
Commands:
|
|
207
|
+
wrangler r2 bucket Manage R2 buckets
|
|
467
208
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
474
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
475
|
-
"@cloudflare/workers-types"
|
|
476
|
-
);
|
|
209
|
+
Flags:
|
|
210
|
+
-c, --config Path to .toml configuration file [string]
|
|
211
|
+
-h, --help Show help [boolean]
|
|
212
|
+
-v, --version Show version number [boolean]"
|
|
213
|
+
`);
|
|
477
214
|
});
|
|
215
|
+
});
|
|
478
216
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
wrangler: "0.0.0",
|
|
487
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
488
|
-
},
|
|
489
|
-
}),
|
|
490
|
-
"utf-8"
|
|
491
|
-
);
|
|
492
|
-
fs.writeFileSync(
|
|
493
|
-
"./tsconfig.json",
|
|
494
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
495
|
-
"utf-8"
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
499
|
-
process.chdir("./sub-1/sub-2");
|
|
217
|
+
describe("Deprecated commands", () => {
|
|
218
|
+
it("should print a deprecation message for 'generate'", async () => {
|
|
219
|
+
await runWrangler("generate").catch((err) => {
|
|
220
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
221
|
+
"Deprecation:
|
|
222
|
+
\`wrangler generate\` has been deprecated.
|
|
223
|
+
Try running \`wrangler init\` to generate a basic Worker, or cloning the template repository instead:
|
|
500
224
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
225
|
+
\`\`\`
|
|
226
|
+
git clone https://github.com/cloudflare/worker-template
|
|
227
|
+
\`\`\`
|
|
504
228
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
);
|
|
508
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
229
|
+
Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
509
232
|
});
|
|
233
|
+
});
|
|
510
234
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
515
|
-
`"The --type option is no longer supported."`
|
|
516
|
-
);
|
|
235
|
+
it("should print a deprecation message for 'build' and then try to run `publish --dry-run --outdir`", async () => {
|
|
236
|
+
writeWranglerToml({
|
|
237
|
+
main: "index.js",
|
|
517
238
|
});
|
|
239
|
+
writeWorkerSource();
|
|
240
|
+
await runWrangler("build");
|
|
241
|
+
await endEventLoop();
|
|
242
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
243
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mDeprecation: \`wrangler build\` has been deprecated.[0m
|
|
518
244
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
523
|
-
`"The --type option is no longer supported."`
|
|
524
|
-
);
|
|
525
|
-
});
|
|
245
|
+
Please refer to [4mhttps://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build[0m
|
|
246
|
+
for more information.
|
|
247
|
+
Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead:
|
|
526
248
|
|
|
527
|
-
it("should error if `--type rust` is used", async () => {
|
|
528
|
-
await expect(
|
|
529
|
-
runWrangler("init --type rust")
|
|
530
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
531
|
-
`"The --type option is no longer supported."`
|
|
532
|
-
);
|
|
533
|
-
});
|
|
534
249
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
"The --type option is no longer supported.
|
|
539
|
-
If you wish to use webpack then you will need to create a custom build."
|
|
540
|
-
`);
|
|
541
|
-
});
|
|
250
|
+
--dry-run: exiting now.
|
|
251
|
+
Total Upload: 0xx KiB / gzip: 0xx KiB"
|
|
252
|
+
`);
|
|
542
253
|
});
|
|
543
254
|
});
|
|
255
|
+
|
|
256
|
+
function endEventLoop() {
|
|
257
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
258
|
+
}
|