wrangler 0.0.0-e6c9c5c0 → 0.0.0-e6e1daba
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 +22 -18
- package/package.json +12 -12
- package/src/__tests__/configuration.test.ts +70 -0
- package/src/__tests__/d1/d1.test.ts +13 -58
- package/src/__tests__/d1/execute.test.ts +64 -0
- package/src/__tests__/d1/migrate.test.ts +155 -0
- package/src/__tests__/deployments.test.ts +40 -16
- package/src/__tests__/dev.test.tsx +8 -7
- package/src/__tests__/generate.test.ts +1 -1
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -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 +38 -32
- package/src/__tests__/init.test.ts +1 -1
- package/src/__tests__/kv.test.ts +63 -52
- package/src/__tests__/middleware.test.ts +65 -0
- package/src/__tests__/mtls-certificates.test.ts +585 -0
- package/src/__tests__/pages/deployment-list.test.ts +78 -0
- package/src/__tests__/pages/functions-build.test.ts +402 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +108 -0
- package/src/__tests__/pages/project-upload.test.ts +481 -0
- package/src/__tests__/pages/publish.test.ts +2745 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +80 -30
- package/src/__tests__/pubsub.test.ts +15 -12
- package/src/__tests__/queues.test.ts +37 -30
- package/src/__tests__/r2.test.ts +25 -20
- 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/__tests__/worker-namespace.test.ts +26 -21
- package/src/api/dev.ts +80 -11
- 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 +59 -12
- package/src/bundle.ts +9 -7
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +9 -2
- package/src/config/index.ts +37 -20
- 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/backups.tsx +20 -24
- package/src/d1/create.tsx +6 -5
- package/src/d1/delete.ts +7 -10
- package/src/d1/execute.tsx +174 -143
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +21 -9
- package/src/d1/migrations/apply.tsx +42 -33
- package/src/d1/migrations/create.tsx +16 -17
- package/src/d1/migrations/helpers.ts +63 -38
- package/src/d1/migrations/list.tsx +37 -24
- package/src/d1/migrations/options.ts +7 -2
- package/src/d1/options.ts +3 -3
- package/src/d1/types.ts +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/delete.ts +5 -8
- package/src/deployments.ts +62 -39
- package/src/deprecated/index.ts +7 -8
- 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 +51 -86
- package/src/dispatch-namespace.ts +20 -16
- package/src/docs/index.ts +7 -8
- package/src/entry.ts +1 -2
- package/src/generate/index.ts +6 -8
- package/src/index.ts +37 -26
- package/src/init.ts +5 -7
- package/src/inspect.ts +16 -1
- package/src/kv/index.ts +15 -17
- 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 +109 -27
- package/src/pages/buildFunctions.ts +32 -31
- package/src/pages/deployment-tails.ts +7 -10
- package/src/pages/deployments.tsx +6 -4
- package/src/pages/dev.ts +19 -19
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/functions.ts +8 -4
- package/src/pages/index.ts +3 -3
- package/src/pages/projects.tsx +7 -12
- package/src/pages/publish.tsx +18 -5
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +6 -4
- package/src/pages/utils.ts +1 -1
- package/src/parse.ts +23 -1
- package/src/publish/index.ts +19 -15
- package/src/publish/publish.ts +5 -4
- package/src/pubsub/pubsub-commands.ts +18 -19
- package/src/queues/cli/commands/consumer/add.ts +18 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +10 -14
- package/src/sites.ts +1 -1
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +6 -8
- package/src/user/user.ts +4 -3
- package/src/worker.ts +6 -0
- package/src/yargs-types.ts +18 -5
- package/templates/checked-fetch.js +9 -1
- package/templates/format-dev-errors.ts +1 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-template-plugin.ts +7 -3
- package/templates/serve-static-assets.ts +1 -0
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig.init.json +1 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +596 -3
- package/wrangler-dist/cli.js +14276 -6748
- package/src/__tests__/pages.test.ts +0 -2898
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();
|
|
@@ -669,7 +673,7 @@ async function generateHandler({
|
|
|
669
673
|
return new HTMLRewriter().on("body", {
|
|
670
674
|
element(e) {
|
|
671
675
|
e.append(
|
|
672
|
-
`<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'
|
|
676
|
+
`<!-- Cloudflare Pages Analytics --><script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "${metadata.analytics?.token}"}'></script><!-- Cloudflare Pages Analytics -->`,
|
|
673
677
|
{ html: true }
|
|
674
678
|
);
|
|
675
679
|
}
|
|
@@ -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);
|
|
@@ -6349,16 +6366,3 @@ async function main() {
|
|
|
6349
6366
|
}
|
|
6350
6367
|
}
|
|
6351
6368
|
await main();
|
|
6352
|
-
/**
|
|
6353
|
-
* @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
|
|
6354
|
-
* CJS and ESM environments.
|
|
6355
|
-
*
|
|
6356
|
-
* @license
|
|
6357
|
-
* Copyright (c) 2016, Contributors
|
|
6358
|
-
* SPDX-License-Identifier: ISC
|
|
6359
|
-
*/
|
|
6360
|
-
/**
|
|
6361
|
-
* @license
|
|
6362
|
-
* Copyright (c) 2016, Contributors
|
|
6363
|
-
* SPDX-License-Identifier: ISC
|
|
6364
|
-
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e6e1daba",
|
|
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
|
-
"esbuild": "0.
|
|
109
|
-
"miniflare": "2.
|
|
108
|
+
"esbuild": "0.16.3",
|
|
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(
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { endEventLoop } from "../helpers/end-event-loop";
|
|
2
2
|
import { mockConsoleMethods } from "../helpers/mock-console";
|
|
3
|
-
import { useMockIsTTY } from "../helpers/mock-istty";
|
|
4
3
|
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
5
4
|
import { runWrangler } from "../helpers/run-wrangler";
|
|
6
|
-
import writeWranglerToml from "../helpers/write-wrangler-toml";
|
|
7
|
-
|
|
8
|
-
function endEventLoop() {
|
|
9
|
-
return new Promise((resolve) => setImmediate(resolve));
|
|
10
|
-
}
|
|
11
5
|
|
|
12
6
|
describe("d1", () => {
|
|
13
7
|
const std = mockConsoleMethods();
|
|
14
8
|
runInTempDir();
|
|
15
|
-
const { setIsTTY } = useMockIsTTY();
|
|
16
9
|
|
|
17
10
|
it("should show help when no argument is passed", async () => {
|
|
18
11
|
await runWrangler("d1");
|
|
@@ -32,14 +25,15 @@ describe("d1", () => {
|
|
|
32
25
|
wrangler d1 migrations Interact with D1 Migrations
|
|
33
26
|
|
|
34
27
|
Flags:
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
28
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
29
|
+
-c, --config Path to .toml configuration file [string]
|
|
30
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
31
|
+
-h, --help Show help [boolean]
|
|
32
|
+
-v, --version Show version number [boolean]
|
|
39
33
|
|
|
40
34
|
--------------------
|
|
41
35
|
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
42
|
-
🚧 Please report any bugs to https://github.com/cloudflare/
|
|
36
|
+
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
43
37
|
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
44
38
|
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
45
39
|
--------------------"
|
|
@@ -71,57 +65,18 @@ describe("d1", () => {
|
|
|
71
65
|
wrangler d1 migrations Interact with D1 Migrations
|
|
72
66
|
|
|
73
67
|
Flags:
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
-
|
|
77
|
-
-
|
|
68
|
+
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
|
|
69
|
+
-c, --config Path to .toml configuration file [string]
|
|
70
|
+
-e, --env Environment to use for operations and .env files [string]
|
|
71
|
+
-h, --help Show help [boolean]
|
|
72
|
+
-v, --version Show version number [boolean]
|
|
78
73
|
|
|
79
74
|
--------------------
|
|
80
75
|
🚧 D1 is currently in open alpha and is not recommended for production data and traffic
|
|
81
|
-
🚧 Please report any bugs to https://github.com/cloudflare/
|
|
76
|
+
🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose
|
|
82
77
|
🚧 To request features, visit https://community.cloudflare.com/c/developers/d1
|
|
83
78
|
🚧 To give feedback, visit https://discord.gg/cloudflaredev
|
|
84
79
|
--------------------"
|
|
85
80
|
`);
|
|
86
81
|
});
|
|
87
|
-
|
|
88
|
-
describe("migrate", () => {
|
|
89
|
-
describe("apply", () => {
|
|
90
|
-
it("should not attempt to login in local mode", async () => {
|
|
91
|
-
setIsTTY(false);
|
|
92
|
-
writeWranglerToml({
|
|
93
|
-
d1_databases: [
|
|
94
|
-
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
95
|
-
],
|
|
96
|
-
});
|
|
97
|
-
// If we get to the point where we are checking for migrations then we have not been asked to log in.
|
|
98
|
-
await expect(
|
|
99
|
-
runWrangler("d1 migrations apply --local DATABASE")
|
|
100
|
-
).rejects.toThrowError(
|
|
101
|
-
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("should try to read D1 config from wrangler.toml", async () => {
|
|
106
|
-
setIsTTY(false);
|
|
107
|
-
writeWranglerToml();
|
|
108
|
-
await expect(
|
|
109
|
-
runWrangler("d1 migrations apply DATABASE")
|
|
110
|
-
).rejects.toThrowError(
|
|
111
|
-
"Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
|
|
112
|
-
);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("should not try to read wrangler.toml in local mode", async () => {
|
|
116
|
-
setIsTTY(false);
|
|
117
|
-
writeWranglerToml();
|
|
118
|
-
// If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
|
|
119
|
-
await expect(
|
|
120
|
-
runWrangler("d1 migrations apply --local DATABASE")
|
|
121
|
-
).rejects.toThrowError(
|
|
122
|
-
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
82
|
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { cwd } from "process";
|
|
2
|
+
import { reinitialiseAuthTokens } from "../../user";
|
|
3
|
+
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
|
|
4
|
+
import { useMockIsTTY } from "../helpers/mock-istty";
|
|
5
|
+
import { runInTempDir } from "../helpers/run-in-tmp";
|
|
6
|
+
import { runWrangler } from "../helpers/run-wrangler";
|
|
7
|
+
import writeWranglerToml from "../helpers/write-wrangler-toml";
|
|
8
|
+
|
|
9
|
+
describe("migrate", () => {
|
|
10
|
+
runInTempDir();
|
|
11
|
+
const { setIsTTY } = useMockIsTTY();
|
|
12
|
+
|
|
13
|
+
describe("create", () => {
|
|
14
|
+
it("should reject the --local flag for create", async () => {
|
|
15
|
+
setIsTTY(false);
|
|
16
|
+
writeWranglerToml({
|
|
17
|
+
d1_databases: [
|
|
18
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await expect(
|
|
23
|
+
runWrangler("d1 migrations create test some-message --local DATABASE")
|
|
24
|
+
).rejects.toThrowError(`Unknown argument: local`);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("apply", () => {
|
|
29
|
+
it("should not attempt to login in local mode", async () => {
|
|
30
|
+
setIsTTY(false);
|
|
31
|
+
writeWranglerToml({
|
|
32
|
+
d1_databases: [
|
|
33
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
// If we get to the point where we are checking for migrations then we have not been asked to log in.
|
|
37
|
+
await expect(
|
|
38
|
+
runWrangler("d1 migrations apply --local DATABASE")
|
|
39
|
+
).rejects.toThrowError(
|
|
40
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should try to read D1 config from wrangler.toml", async () => {
|
|
45
|
+
setIsTTY(false);
|
|
46
|
+
writeWranglerToml();
|
|
47
|
+
await expect(
|
|
48
|
+
runWrangler("d1 migrations apply DATABASE")
|
|
49
|
+
).rejects.toThrowError(
|
|
50
|
+
"Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should not try to read wrangler.toml in local mode", async () => {
|
|
55
|
+
setIsTTY(false);
|
|
56
|
+
writeWranglerToml();
|
|
57
|
+
// If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
|
|
58
|
+
await expect(
|
|
59
|
+
runWrangler("d1 migrations apply --local DATABASE")
|
|
60
|
+
).rejects.toThrowError(
|
|
61
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
62
|
+
);
|
|
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
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("list", () => {
|
|
81
|
+
mockAccountId();
|
|
82
|
+
mockApiToken({ apiToken: null });
|
|
83
|
+
|
|
84
|
+
it("should not attempt to login in local mode", async () => {
|
|
85
|
+
setIsTTY(false);
|
|
86
|
+
writeWranglerToml({
|
|
87
|
+
d1_databases: [
|
|
88
|
+
{ binding: "DATABASE", database_name: "db", database_id: "xxxx" },
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
// If we get to the point where we are checking for migrations then we have not been asked to log in.
|
|
92
|
+
await expect(
|
|
93
|
+
runWrangler("d1 migrations list --local DATABASE")
|
|
94
|
+
).rejects.toThrowError(
|
|
95
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should use the custom migrations folder when provided", async () => {
|
|
100
|
+
setIsTTY(false);
|
|
101
|
+
writeWranglerToml({
|
|
102
|
+
d1_databases: [
|
|
103
|
+
{
|
|
104
|
+
binding: "DATABASE",
|
|
105
|
+
database_name: "db",
|
|
106
|
+
database_id: "xxxx",
|
|
107
|
+
migrations_dir: "my-migrations-go-here",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
await expect(
|
|
112
|
+
runWrangler("d1 migrations list --local DATABASE")
|
|
113
|
+
).rejects.toThrowError(
|
|
114
|
+
`No migrations present at ${cwd().replaceAll(
|
|
115
|
+
"\\",
|
|
116
|
+
"/"
|
|
117
|
+
)}/my-migrations-go-here.`
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should try to read D1 config from wrangler.toml when logged in", async () => {
|
|
122
|
+
// no need to clear this env var as it's implicitly cleared by mockApiToken in afterEach
|
|
123
|
+
process.env.CLOUDFLARE_API_TOKEN = "api-token";
|
|
124
|
+
reinitialiseAuthTokens();
|
|
125
|
+
setIsTTY(false);
|
|
126
|
+
writeWranglerToml();
|
|
127
|
+
await expect(
|
|
128
|
+
runWrangler("d1 migrations list DATABASE")
|
|
129
|
+
).rejects.toThrowError(
|
|
130
|
+
"Can't find a DB with name/binding 'DATABASE' in local config. Check info in wrangler.toml..."
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should throw if user is not authenticated and not using --local", async () => {
|
|
135
|
+
setIsTTY(false);
|
|
136
|
+
|
|
137
|
+
await expect(
|
|
138
|
+
runWrangler("d1 migrations list DATABASE")
|
|
139
|
+
).rejects.toThrowError(
|
|
140
|
+
"In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work"
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should not try to read wrangler.toml in local mode", async () => {
|
|
145
|
+
setIsTTY(false);
|
|
146
|
+
writeWranglerToml();
|
|
147
|
+
// If we get to the point where we are checking for migrations then we have not checked wrangler.toml.
|
|
148
|
+
await expect(
|
|
149
|
+
runWrangler("d1 migrations list --local DATABASE")
|
|
150
|
+
).rejects.toThrowError(
|
|
151
|
+
`No migrations present at ${cwd().replaceAll("\\", "/")}/migrations.`
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -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
|
});
|