wrangler 2.9.1 → 2.11.0
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/README.md +3 -3
- package/miniflare-dist/index.mjs +21 -4
- package/package.json +11 -11
- package/src/__tests__/configuration.test.ts +70 -0
- package/src/__tests__/d1/d1.test.ts +2 -2
- package/src/__tests__/d1/execute.test.ts +64 -0
- package/src/__tests__/d1/migrate.test.ts +14 -0
- package/src/__tests__/deployments.test.ts +40 -16
- package/src/__tests__/dev.test.tsx +3 -3
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/index.test.ts +2 -0
- package/src/__tests__/kv.test.ts +8 -8
- package/src/__tests__/middleware.test.ts +65 -0
- package/src/__tests__/mtls-certificates.test.ts +585 -0
- package/src/__tests__/pages/functions-build.test.ts +402 -0
- package/src/__tests__/pages/pages.test.ts +7 -7
- package/src/__tests__/pages/publish.test.ts +525 -1
- package/src/__tests__/publish.test.ts +80 -30
- package/src/__tests__/queues.test.ts +2 -2
- package/src/__tests__/secret.test.ts +4 -4
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +1 -1
- package/src/__tests__/whoami.test.tsx +1 -1
- package/src/api/index.ts +8 -0
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +75 -0
- package/src/api/pages/publish.tsx +52 -8
- package/src/bundle.ts +8 -6
- package/src/config/config.ts +7 -7
- package/src/config/environment.ts +9 -2
- package/src/config/index.ts +13 -0
- package/src/config/validation.ts +50 -3
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +9 -0
- package/src/d1/execute.tsx +123 -90
- package/src/d1/migrations/apply.tsx +29 -24
- package/src/d1/migrations/create.tsx +7 -7
- package/src/d1/migrations/helpers.ts +63 -38
- package/src/d1/migrations/list.tsx +19 -16
- package/src/d1/migrations/options.ts +6 -1
- package/src/d1/types.ts +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/deployments.ts +62 -39
- package/src/dev/dev.tsx +1 -15
- package/src/dev/local.tsx +5 -6
- package/src/dev/remote.tsx +2 -2
- package/src/dev.tsx +9 -6
- package/src/entry.ts +1 -2
- package/src/generate/index.ts +1 -1
- package/src/index.ts +15 -5
- package/src/inspect.ts +16 -1
- package/src/miniflare-cli/assets.ts +9 -8
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +103 -23
- package/src/pages/buildFunctions.ts +32 -31
- package/src/pages/dev.ts +4 -2
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/publish.tsx +12 -1
- package/src/pages/utils.ts +1 -1
- package/src/publish/publish.ts +3 -2
- package/src/secret/index.ts +1 -0
- package/src/sites.ts +1 -1
- package/src/tail/filters.ts +1 -1
- package/src/user/user.ts +4 -3
- package/src/worker.ts +6 -0
- package/templates/format-dev-errors.ts +1 -0
- package/templates/new-worker.ts +3 -0
- package/templates/serve-static-assets.ts +1 -0
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +596 -3
- package/wrangler-dist/cli.js +12237 -5091
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<h1 align="center"> ⛅️ wrangler </h1>
|
|
2
2
|
<section align="center" id="shieldio-badges">
|
|
3
3
|
<a href="https://www.npmjs.com/package/wrangler"><img alt="npm" src="https://img.shields.io/npm/dw/wrangler?style=flat-square"></a>
|
|
4
|
-
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/
|
|
5
|
-
<img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/
|
|
4
|
+
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/cloudflare/workers-sdk?style=flat-square">
|
|
5
|
+
<img alt="GitHub commit activity (branch)" src="https://img.shields.io/github/commit-activity/w/cloudflare/workers-sdk/main?style=flat-square">
|
|
6
6
|
<a href="https://discord.gg/CloudflareDev"><img alt="Discord" src="https://img.shields.io/discord/595317990191398933?color=%23F48120&style=flat-square"></a>
|
|
7
7
|
</section>
|
|
8
8
|
|
|
9
|
-
> 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.
|
|
9
|
+
> 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-legacy.
|
|
10
10
|
|
|
11
11
|
`wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
|
|
12
12
|
|
package/miniflare-dist/index.mjs
CHANGED
|
@@ -441,7 +441,11 @@ async function generateHandler({
|
|
|
441
441
|
async function generateResponse() {
|
|
442
442
|
const match = staticRedirectsMatcher() || generateRedirectsMatcher()({ request })[0];
|
|
443
443
|
if (match) {
|
|
444
|
-
|
|
444
|
+
if (match.status === 200) {
|
|
445
|
+
pathname = new URL(match.to, request.url).pathname;
|
|
446
|
+
} else {
|
|
447
|
+
return getResponseFromMatch(match, url);
|
|
448
|
+
}
|
|
445
449
|
}
|
|
446
450
|
if (!request.method.match(/^(get|head)$/i)) {
|
|
447
451
|
return new MethodNotAllowedResponse();
|
|
@@ -5615,7 +5619,7 @@ import { join } from "node:path";
|
|
|
5615
5619
|
var REDIRECTS_VERSION = 1;
|
|
5616
5620
|
var HEADERS_VERSION = 2;
|
|
5617
5621
|
var ANALYTICS_VERSION = 1;
|
|
5618
|
-
var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
5622
|
+
var PERMITTED_STATUS_CODES = /* @__PURE__ */ new Set([200, 301, 302, 303, 307, 308]);
|
|
5619
5623
|
var HEADER_SEPARATOR = ":";
|
|
5620
5624
|
var MAX_LINE_LENGTH = 2e3;
|
|
5621
5625
|
var MAX_HEADER_RULES = 100;
|
|
@@ -5994,7 +5998,7 @@ function parseRedirects(input) {
|
|
|
5994
5998
|
invalid.push({
|
|
5995
5999
|
line,
|
|
5996
6000
|
lineNumber: i + 1,
|
|
5997
|
-
message: `Valid status codes are 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
|
|
6001
|
+
message: `Valid status codes are 200, 301, 302 (default), 303, 307, or 308. Got ${str_status}.`
|
|
5998
6002
|
});
|
|
5999
6003
|
continue;
|
|
6000
6004
|
}
|
|
@@ -6007,6 +6011,19 @@ function parseRedirects(input) {
|
|
|
6007
6011
|
continue;
|
|
6008
6012
|
}
|
|
6009
6013
|
seen_paths.add(from);
|
|
6014
|
+
if (status === 200) {
|
|
6015
|
+
const [proxyTo, error] = validateUrl(to, true, true, true);
|
|
6016
|
+
if (error) {
|
|
6017
|
+
invalid.push({
|
|
6018
|
+
line,
|
|
6019
|
+
lineNumber: i + 1,
|
|
6020
|
+
message: `Proxy (200) redirects can only point to relative paths. Got ${to}`
|
|
6021
|
+
});
|
|
6022
|
+
continue;
|
|
6023
|
+
}
|
|
6024
|
+
rules.push({ from, to: proxyTo, status, lineNumber: i + 1 });
|
|
6025
|
+
continue;
|
|
6026
|
+
}
|
|
6010
6027
|
rules.push({ from, to, status, lineNumber: i + 1 });
|
|
6011
6028
|
}
|
|
6012
6029
|
return {
|
|
@@ -6152,7 +6169,7 @@ async function generateAssetsFetch(directory, log, tre) {
|
|
|
6152
6169
|
const filepath = assetKeyEntryMap.get(assetKey);
|
|
6153
6170
|
if (!filepath) {
|
|
6154
6171
|
throw new Error(
|
|
6155
|
-
"Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/
|
|
6172
|
+
"Could not fetch asset. Please file an issue on GitHub (https://github.com/cloudflare/workers-sdk/issues/new/choose) with reproduction steps."
|
|
6156
6173
|
);
|
|
6157
6174
|
}
|
|
6158
6175
|
const body = readFileSync5(filepath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"http",
|
|
25
25
|
"cli"
|
|
26
26
|
],
|
|
27
|
-
"homepage": "https://github.com/cloudflare/
|
|
27
|
+
"homepage": "https://github.com/cloudflare/workers-sdk#readme",
|
|
28
28
|
"bugs": {
|
|
29
|
-
"url": "https://github.com/cloudflare/
|
|
29
|
+
"url": "https://github.com/cloudflare/workers-sdk/issues"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/cloudflare/
|
|
33
|
+
"url": "https://github.com/cloudflare/workers-sdk.git",
|
|
34
34
|
"directory": "packages/wrangler"
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT OR Apache-2.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
64
64
|
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
65
65
|
"start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
66
|
-
"test": "npm run assert-git-version && jest --silent=false --verbose=true",
|
|
66
|
+
"test": "npm run assert-git-version && jest --silent=false --verbose=true --forceExit",
|
|
67
67
|
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
|
|
68
68
|
"test:ci": "npm run test -- --verbose=true --coverage"
|
|
69
69
|
},
|
|
@@ -100,13 +100,13 @@
|
|
|
100
100
|
"@cloudflare/kv-asset-handler": "^0.2.0",
|
|
101
101
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
102
102
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
|
103
|
-
"@miniflare/core": "2.
|
|
104
|
-
"@miniflare/d1": "2.
|
|
105
|
-
"@miniflare/durable-objects": "2.
|
|
103
|
+
"@miniflare/core": "2.12.1",
|
|
104
|
+
"@miniflare/d1": "2.12.1",
|
|
105
|
+
"@miniflare/durable-objects": "2.12.1",
|
|
106
106
|
"blake3-wasm": "^2.1.5",
|
|
107
107
|
"chokidar": "^3.5.3",
|
|
108
108
|
"esbuild": "0.16.3",
|
|
109
|
-
"miniflare": "2.
|
|
109
|
+
"miniflare": "2.12.1",
|
|
110
110
|
"nanoid": "^3.3.3",
|
|
111
111
|
"path-to-regexp": "^6.2.0",
|
|
112
112
|
"selfsigned": "^2.0.1",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"@cloudflare/workers-types": "^4.20221111.1",
|
|
119
119
|
"@iarna/toml": "^3.0.0",
|
|
120
120
|
"@microsoft/api-extractor": "^7.28.3",
|
|
121
|
-
"@miniflare/tre": "^3.0.0-next.
|
|
121
|
+
"@miniflare/tre": "^3.0.0-next.10",
|
|
122
122
|
"@types/better-sqlite3": "^7.6.0",
|
|
123
123
|
"@types/busboy": "^1.5.0",
|
|
124
124
|
"@types/command-exists": "^1.2.0",
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
"timeago.js": "^4.0.2",
|
|
180
180
|
"tmp-promise": "^3.0.3",
|
|
181
181
|
"ts-dedent": "^2.2.0",
|
|
182
|
-
"undici": "5.
|
|
182
|
+
"undici": "5.20.0",
|
|
183
183
|
"update-check": "^1.5.4",
|
|
184
184
|
"ws": "^8.5.0",
|
|
185
185
|
"xdg-app-paths": "^7.3.0",
|
|
@@ -68,6 +68,7 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
68
68
|
bindings: [],
|
|
69
69
|
},
|
|
70
70
|
dispatch_namespaces: [],
|
|
71
|
+
mtls_certificates: [],
|
|
71
72
|
usage_model: undefined,
|
|
72
73
|
vars: {},
|
|
73
74
|
define: {},
|
|
@@ -2190,6 +2191,75 @@ describe("normalizeAndValidateConfig()", () => {
|
|
|
2190
2191
|
});
|
|
2191
2192
|
});
|
|
2192
2193
|
|
|
2194
|
+
describe("[mtls_certificates]", () => {
|
|
2195
|
+
it("should error if mtls_certificates is not an array", () => {
|
|
2196
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2197
|
+
{
|
|
2198
|
+
mtls_certificates: "just a string",
|
|
2199
|
+
} as unknown as RawConfig,
|
|
2200
|
+
undefined,
|
|
2201
|
+
{ env: undefined }
|
|
2202
|
+
);
|
|
2203
|
+
|
|
2204
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2205
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
2206
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2207
|
+
"Processing wrangler configuration:
|
|
2208
|
+
- The field \\"mtls_certificates\\" should be an array but got \\"just a string\\"."
|
|
2209
|
+
`);
|
|
2210
|
+
});
|
|
2211
|
+
|
|
2212
|
+
it("should error on non valid mtls_certificates", () => {
|
|
2213
|
+
const { diagnostics } = normalizeAndValidateConfig(
|
|
2214
|
+
{
|
|
2215
|
+
mtls_certificates: [
|
|
2216
|
+
"a string",
|
|
2217
|
+
123,
|
|
2218
|
+
false,
|
|
2219
|
+
{
|
|
2220
|
+
binding: 123,
|
|
2221
|
+
namespace: 123,
|
|
2222
|
+
},
|
|
2223
|
+
{
|
|
2224
|
+
binding: "CERT_ONE",
|
|
2225
|
+
id: "1234",
|
|
2226
|
+
},
|
|
2227
|
+
{
|
|
2228
|
+
binding: "CERT_TWO",
|
|
2229
|
+
certificate_id: 1234,
|
|
2230
|
+
},
|
|
2231
|
+
// this one is valid
|
|
2232
|
+
{
|
|
2233
|
+
binding: "CERT_THREE",
|
|
2234
|
+
certificate_id: "1234",
|
|
2235
|
+
},
|
|
2236
|
+
{
|
|
2237
|
+
binding: true,
|
|
2238
|
+
service: "1234",
|
|
2239
|
+
},
|
|
2240
|
+
],
|
|
2241
|
+
} as unknown as RawConfig,
|
|
2242
|
+
undefined,
|
|
2243
|
+
{ env: undefined }
|
|
2244
|
+
);
|
|
2245
|
+
|
|
2246
|
+
expect(diagnostics.hasWarnings()).toBe(false);
|
|
2247
|
+
expect(diagnostics.hasErrors()).toBe(true);
|
|
2248
|
+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
|
|
2249
|
+
"Processing wrangler configuration:
|
|
2250
|
+
- \\"mtls_certificates\\" bindings should be objects, but got \\"a string\\"
|
|
2251
|
+
- \\"mtls_certificates\\" bindings should be objects, but got 123
|
|
2252
|
+
- \\"mtls_certificates\\" bindings should be objects, but got false
|
|
2253
|
+
- \\"mtls_certificates[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
|
|
2254
|
+
- \\"mtls_certificates[3]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
|
|
2255
|
+
- \\"mtls_certificates[4]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_ONE\\",\\"id\\":\\"1234\\"}.
|
|
2256
|
+
- \\"mtls_certificates[5]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_TWO\\",\\"certificate_id\\":1234}.
|
|
2257
|
+
- \\"mtls_certificates[7]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}.
|
|
2258
|
+
- \\"mtls_certificates[7]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}."
|
|
2259
|
+
`);
|
|
2260
|
+
});
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2193
2263
|
describe("[unsafe.bindings]", () => {
|
|
2194
2264
|
it("should error if unsafe is an array", () => {
|
|
2195
2265
|
const { diagnostics } = normalizeAndValidateConfig(
|
|
@@ -33,7 +33,7 @@ describe("d1", () => {
|
|
|
33
33
|
|
|
34
34
|
--------------------
|
|
35
35
|
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
36
|
-
🚧 Please report any bugs to https://github.com/cloudflare/
|
|
36
|
+
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
37
37
|
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
38
38
|
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
39
39
|
--------------------"
|
|
@@ -73,7 +73,7 @@ describe("d1", () => {
|
|
|
73
73
|
|
|
74
74
|
--------------------
|
|
75
75
|
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
76
|
-
🚧 Please report any bugs to https://github.com/cloudflare/
|
|
76
|
+
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
77
77
|
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
78
78
|
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
79
79
|
--------------------"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useMockIsTTY } from "../helpers/mock-istty";
|
|
2
|
+
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
3
|
+
import { runWrangler } from "../helpers/run-wrangler";
|
|
4
|
+
import writeWranglerToml from "../helpers/write-wrangler-toml";
|
|
5
|
+
|
|
6
|
+
describe("execute", () => {
|
|
7
|
+
runInTempDir();
|
|
8
|
+
const { setIsTTY } = useMockIsTTY();
|
|
9
|
+
|
|
10
|
+
it("should require login when running against prod", async () => {
|
|
11
|
+
setIsTTY(false);
|
|
12
|
+
writeWranglerToml({
|
|
13
|
+
d1_databases: [
|
|
14
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await expect(
|
|
19
|
+
runWrangler("d1 execute --command 'select 1;'")
|
|
20
|
+
).rejects.toThrowError(
|
|
21
|
+
`In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work. Please go to https://developers.cloudflare.com/api/tokens/create/ for instructions on how to create an api token, and assign its value to CLOUDFLARE_API_TOKEN.`
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should expect either --command or --file", async () => {
|
|
26
|
+
setIsTTY(false);
|
|
27
|
+
writeWranglerToml({
|
|
28
|
+
d1_databases: [
|
|
29
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
await expect(runWrangler("d1 execute db")).rejects.toThrowError(
|
|
34
|
+
`Error: must provide --command or --file`
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should reject the use of --preview with --local", async () => {
|
|
39
|
+
setIsTTY(false);
|
|
40
|
+
writeWranglerToml({
|
|
41
|
+
d1_databases: [
|
|
42
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await expect(
|
|
47
|
+
runWrangler(`d1 execute db --command "select;" --local --preview`)
|
|
48
|
+
).rejects.toThrowError(`Error: can't use --preview with --local`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should expect --local when using --persist-to", async () => {
|
|
52
|
+
setIsTTY(false);
|
|
53
|
+
writeWranglerToml({
|
|
54
|
+
d1_databases: [
|
|
55
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
56
|
+
],
|
|
57
|
+
});
|
|
58
|
+
await runWrangler("d1 migrations create db test");
|
|
59
|
+
|
|
60
|
+
await expect(
|
|
61
|
+
runWrangler("d1 migrations apply --local db --preview")
|
|
62
|
+
).rejects.toThrowError(`Error: can't use --preview with --local`);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -61,6 +61,20 @@ describe("migrate", () => {
|
|
|
61
61
|
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
62
62
|
);
|
|
63
63
|
});
|
|
64
|
+
|
|
65
|
+
it("should reject the use of --preview with --local", async () => {
|
|
66
|
+
setIsTTY(false);
|
|
67
|
+
writeWranglerToml({
|
|
68
|
+
d1_databases: [
|
|
69
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
await runWrangler("d1 migrations create db test");
|
|
73
|
+
|
|
74
|
+
await expect(
|
|
75
|
+
runWrangler("d1 migrations apply --local db --preview")
|
|
76
|
+
).rejects.toThrowError(`Error: can't use --preview with --local`);
|
|
77
|
+
});
|
|
64
78
|
});
|
|
65
79
|
|
|
66
80
|
describe("list", () => {
|
|
@@ -62,18 +62,30 @@ describe("deployments", () => {
|
|
|
62
62
|
|
|
63
63
|
await runWrangler("deployments");
|
|
64
64
|
expect(std.out).toMatchInlineSnapshot(`
|
|
65
|
-
"🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/
|
|
65
|
+
"🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
Deployment ID:
|
|
69
|
-
Created on:
|
|
70
|
-
Author:
|
|
71
|
-
|
|
68
|
+
Deployment ID: Constitution-Class
|
|
69
|
+
Created on: 2021-01-01T00:00:00.000000Z
|
|
70
|
+
Author: Jean-Luc-Picard@federation.org
|
|
71
|
+
Trigger: Upload from Wrangler 🤠
|
|
72
|
+
|
|
73
|
+
Deployment ID: Intrepid-Class
|
|
74
|
+
Created on: 2021-02-02T00:00:00.000000Z
|
|
75
|
+
Author: Kathryn-Janeway@federation.org
|
|
76
|
+
Trigger: Rollback from Wrangler 🤠
|
|
77
|
+
Rollback from: MOCK-DEPLOYMENT-ID-1111
|
|
72
78
|
|
|
73
79
|
Deployment ID: Intrepid-Class
|
|
74
|
-
Created on:
|
|
75
|
-
Author:
|
|
76
|
-
|
|
80
|
+
Created on: 2021-02-03T00:00:00.000000Z
|
|
81
|
+
Author: Kathryn-Janeway@federation.org
|
|
82
|
+
Trigger: Wrangler 🤠
|
|
83
|
+
|
|
84
|
+
Deployment ID: Galaxy-Class
|
|
85
|
+
Created on: 2021-01-04T00:00:00.000000Z
|
|
86
|
+
Author: Jean-Luc-Picard@federation.org
|
|
87
|
+
Trigger: Rollback from Wrangler 🤠
|
|
88
|
+
Rollback from: MOCK-DEPLOYMENT-ID-2222
|
|
77
89
|
🟩 Active"
|
|
78
90
|
`);
|
|
79
91
|
});
|
|
@@ -81,18 +93,30 @@ describe("deployments", () => {
|
|
|
81
93
|
it("should log deployments for script with passed in name option", async () => {
|
|
82
94
|
await runWrangler("deployments --name something-else");
|
|
83
95
|
expect(std.out).toMatchInlineSnapshot(`
|
|
84
|
-
"🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/
|
|
96
|
+
"🚧\`wrangler deployments\` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
85
97
|
|
|
86
98
|
|
|
87
|
-
Deployment ID:
|
|
88
|
-
Created on:
|
|
89
|
-
Author:
|
|
90
|
-
|
|
99
|
+
Deployment ID: Constitution-Class
|
|
100
|
+
Created on: 2021-01-01T00:00:00.000000Z
|
|
101
|
+
Author: Jean-Luc-Picard@federation.org
|
|
102
|
+
Trigger: Upload from Wrangler 🤠
|
|
103
|
+
|
|
104
|
+
Deployment ID: Intrepid-Class
|
|
105
|
+
Created on: 2021-02-02T00:00:00.000000Z
|
|
106
|
+
Author: Kathryn-Janeway@federation.org
|
|
107
|
+
Trigger: Rollback from Wrangler 🤠
|
|
108
|
+
Rollback from: MOCK-DEPLOYMENT-ID-1111
|
|
91
109
|
|
|
92
110
|
Deployment ID: Intrepid-Class
|
|
93
|
-
Created on:
|
|
94
|
-
Author:
|
|
95
|
-
|
|
111
|
+
Created on: 2021-02-03T00:00:00.000000Z
|
|
112
|
+
Author: Kathryn-Janeway@federation.org
|
|
113
|
+
Trigger: Wrangler 🤠
|
|
114
|
+
|
|
115
|
+
Deployment ID: Galaxy-Class
|
|
116
|
+
Created on: 2021-01-04T00:00:00.000000Z
|
|
117
|
+
Author: Jean-Luc-Picard@federation.org
|
|
118
|
+
Trigger: Rollback from Wrangler 🤠
|
|
119
|
+
Rollback from: MOCK-DEPLOYMENT-ID-2222
|
|
96
120
|
🟩 Active"
|
|
97
121
|
`);
|
|
98
122
|
});
|
|
@@ -136,7 +136,7 @@ describe("wrangler dev", () => {
|
|
|
136
136
|
|
|
137
137
|
expect(std.out).toMatchInlineSnapshot(`
|
|
138
138
|
"
|
|
139
|
-
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/
|
|
139
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
140
140
|
`);
|
|
141
141
|
expect(std.err).toMatchInlineSnapshot(`
|
|
142
142
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mMissing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`main\` config field.[0m
|
|
@@ -698,7 +698,7 @@ describe("wrangler dev", () => {
|
|
|
698
698
|
expect(std.out).toMatchInlineSnapshot(`
|
|
699
699
|
"Running custom build: node -e \\"console.log('custom build');\\"
|
|
700
700
|
|
|
701
|
-
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/
|
|
701
|
+
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
|
|
702
702
|
`);
|
|
703
703
|
expect(std.err).toMatchInlineSnapshot(`
|
|
704
704
|
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mThe expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".[0m
|
|
@@ -774,7 +774,7 @@ describe("wrangler dev", () => {
|
|
|
774
774
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mSetting upstream-protocol to http is not currently implemented.[0m
|
|
775
775
|
|
|
776
776
|
If this is required in your project, please add your use case to the following issue:
|
|
777
|
-
[4mhttps://github.com/cloudflare/
|
|
777
|
+
[4mhttps://github.com/cloudflare/workers-sdk/issues/583[0m.
|
|
778
778
|
|
|
779
779
|
"
|
|
780
780
|
`);
|
|
@@ -32,6 +32,41 @@ describe("guess worker format", () => {
|
|
|
32
32
|
expect(guess).toBe("service-worker");
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
+
it('should detect a "service-worker" worker using `typeof module`', async () => {
|
|
36
|
+
await writeFile("./index.ts", "typeof module");
|
|
37
|
+
const guess = await guessWorkerFormat(
|
|
38
|
+
path.join(process.cwd(), "./index.ts"),
|
|
39
|
+
process.cwd(),
|
|
40
|
+
undefined
|
|
41
|
+
);
|
|
42
|
+
expect(guess).toBe("service-worker");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should detect a "service-worker" worker using imports', async () => {
|
|
46
|
+
await writeFile(
|
|
47
|
+
"./dep.ts",
|
|
48
|
+
`
|
|
49
|
+
const value = 'thing';
|
|
50
|
+
export default value;
|
|
51
|
+
`
|
|
52
|
+
);
|
|
53
|
+
await writeFile(
|
|
54
|
+
"./index.ts",
|
|
55
|
+
`
|
|
56
|
+
import value from './dep.ts';
|
|
57
|
+
addEventListener('fetch', (event) => {
|
|
58
|
+
event.respondWith(new Response(value));
|
|
59
|
+
});
|
|
60
|
+
`
|
|
61
|
+
);
|
|
62
|
+
const guess = await guessWorkerFormat(
|
|
63
|
+
path.join(process.cwd(), "./index.ts"),
|
|
64
|
+
process.cwd(),
|
|
65
|
+
undefined
|
|
66
|
+
);
|
|
67
|
+
expect(guess).toBe("service-worker");
|
|
68
|
+
});
|
|
69
|
+
|
|
35
70
|
it("should throw an error when the hint doesn't match the guess (modules - service-worker)", async () => {
|
|
36
71
|
await writeFile("./index.ts", "export default {};");
|
|
37
72
|
await expect(
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { rest } from "msw";
|
|
2
2
|
import { createFetchResult } from "../index";
|
|
3
3
|
|
|
4
|
+
const latestDeployment = {
|
|
5
|
+
id: "Galaxy-Class",
|
|
6
|
+
number: "1701-E",
|
|
7
|
+
annotations: {
|
|
8
|
+
"workers/triggered_by": "rollback",
|
|
9
|
+
"workers/rollback_from": "MOCK-DEPLOYMENT-ID-2222",
|
|
10
|
+
},
|
|
11
|
+
metadata: {
|
|
12
|
+
author_id: "Picard-Gamma-6-0-7-3",
|
|
13
|
+
author_email: "Jean-Luc-Picard@federation.org",
|
|
14
|
+
source: "wrangler",
|
|
15
|
+
created_on: "2021-01-04T00:00:00.000000Z",
|
|
16
|
+
modified_on: "2021-01-04T00:00:00.000000Z",
|
|
17
|
+
},
|
|
18
|
+
resources: {
|
|
19
|
+
script: "MOCK-TAG",
|
|
20
|
+
bindings: [],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
4
23
|
export const mswSuccessDeployments = [
|
|
5
24
|
rest.get(
|
|
6
25
|
"*/accounts/:accountId/workers/deployments/by-script/:scriptTag",
|
|
@@ -8,25 +27,14 @@ export const mswSuccessDeployments = [
|
|
|
8
27
|
response.once(
|
|
9
28
|
context.json(
|
|
10
29
|
createFetchResult({
|
|
11
|
-
latest:
|
|
12
|
-
id: "Galaxy-Class",
|
|
13
|
-
number: "1701-E",
|
|
14
|
-
metadata: {
|
|
15
|
-
author_id: "Picard-Gamma-6-0-7-3",
|
|
16
|
-
author_email: "Jean-Luc-Picard@federation.org",
|
|
17
|
-
source: "wrangler",
|
|
18
|
-
created_on: "2021-01-01T00:00:00.000000Z",
|
|
19
|
-
modified_on: "2021-01-01T00:00:00.000000Z",
|
|
20
|
-
},
|
|
21
|
-
resources: {
|
|
22
|
-
script: "MOCK-TAG",
|
|
23
|
-
bindings: [],
|
|
24
|
-
},
|
|
25
|
-
},
|
|
30
|
+
latest: latestDeployment,
|
|
26
31
|
items: [
|
|
27
32
|
{
|
|
28
|
-
id: "
|
|
33
|
+
id: "Constitution-Class",
|
|
29
34
|
number: "1701-E",
|
|
35
|
+
annotations: {
|
|
36
|
+
"workers/triggered_by": "upload",
|
|
37
|
+
},
|
|
30
38
|
metadata: {
|
|
31
39
|
author_id: "Picard-Gamma-6-0-7-3",
|
|
32
40
|
author_email: "Jean-Luc-Picard@federation.org",
|
|
@@ -38,6 +46,10 @@ export const mswSuccessDeployments = [
|
|
|
38
46
|
{
|
|
39
47
|
id: "Intrepid-Class",
|
|
40
48
|
number: "NCC-74656",
|
|
49
|
+
annotations: {
|
|
50
|
+
"workers/triggered_by": "rollback",
|
|
51
|
+
"workers/rollback_from": "MOCK-DEPLOYMENT-ID-1111",
|
|
52
|
+
},
|
|
41
53
|
metadata: {
|
|
42
54
|
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
|
|
43
55
|
author_email: "Kathryn-Janeway@federation.org",
|
|
@@ -46,6 +58,18 @@ export const mswSuccessDeployments = [
|
|
|
46
58
|
modified_on: "2021-02-02T00:00:00.000000Z",
|
|
47
59
|
},
|
|
48
60
|
},
|
|
61
|
+
{
|
|
62
|
+
id: "Intrepid-Class",
|
|
63
|
+
number: "NCC-74656",
|
|
64
|
+
metadata: {
|
|
65
|
+
author_id: "Kathryn-Jane-Gamma-6-0-7-3",
|
|
66
|
+
author_email: "Kathryn-Janeway@federation.org",
|
|
67
|
+
source: "wrangler",
|
|
68
|
+
created_on: "2021-02-03T00:00:00.000000Z",
|
|
69
|
+
modified_on: "2021-02-03T00:00:00.000000Z",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
latestDeployment,
|
|
49
73
|
],
|
|
50
74
|
})
|
|
51
75
|
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type PatternReplacementPair = [string | RegExp, string];
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sometimes, we might need to test strings that contain dynamic |
|
|
5
|
+
* random | generated data (such as file hashes, IDs, etc.).
|
|
6
|
+
*
|
|
7
|
+
* This helper function replaces the dynamic parts of such strings with
|
|
8
|
+
* static values, thus enabling us to properly test the contents of the
|
|
9
|
+
* string.
|
|
10
|
+
*
|
|
11
|
+
* see https://jestjs.io/docs/snapshot-testing#property-matchers
|
|
12
|
+
*/
|
|
13
|
+
export function replaceRandomWithConstantData(
|
|
14
|
+
stringWithRandomData: string,
|
|
15
|
+
patternReplacementPairs: Array<PatternReplacementPair>
|
|
16
|
+
) {
|
|
17
|
+
let stringWithConstantData = stringWithRandomData;
|
|
18
|
+
|
|
19
|
+
patternReplacementPairs.forEach(
|
|
20
|
+
(pair) =>
|
|
21
|
+
(stringWithConstantData = stringWithConstantData.replace(
|
|
22
|
+
pair[0], // pattern
|
|
23
|
+
pair[1] // replacement
|
|
24
|
+
))
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return stringWithConstantData;
|
|
28
|
+
}
|
|
@@ -50,6 +50,7 @@ describe("wrangler", () => {
|
|
|
50
50
|
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
|
|
51
51
|
wrangler d1 🗄 Interact with a D1 database
|
|
52
52
|
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
|
|
53
|
+
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
|
|
53
54
|
wrangler login 🔓 Login to Cloudflare
|
|
54
55
|
wrangler logout 🚪 Logout from Cloudflare
|
|
55
56
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
@@ -99,6 +100,7 @@ describe("wrangler", () => {
|
|
|
99
100
|
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
|
|
100
101
|
wrangler d1 🗄 Interact with a D1 database
|
|
101
102
|
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
|
|
103
|
+
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
|
|
102
104
|
wrangler login 🔓 Login to Cloudflare
|
|
103
105
|
wrangler logout 🚪 Logout from Cloudflare
|
|
104
106
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|