wrangler 0.0.0-b63efe6 → 0.0.0-b8a3e78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wrangler.js +2 -2
- package/package.json +8 -8
- package/pages/functions/buildWorker.ts +1 -1
- package/pages/functions/filepath-routing.ts +3 -3
- package/pages/functions/routes.ts +2 -2
- package/src/__tests__/dev.test.tsx +4 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/mock-account-id.ts +30 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +6 -6
- package/src/__tests__/helpers/mock-console.ts +56 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +14 -0
- package/src/__tests__/index.test.ts +166 -54
- package/src/__tests__/jest.setup.ts +14 -2
- package/src/__tests__/kv.test.ts +222 -272
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/publish.test.ts +713 -163
- package/src/__tests__/secret.test.ts +210 -0
- package/src/__tests__/whoami.test.tsx +7 -51
- package/src/api/form_data.ts +10 -7
- package/src/api/preview.ts +2 -2
- package/src/api/worker.ts +3 -3
- package/src/cfetch/index.ts +4 -3
- package/src/cfetch/internal.ts +3 -2
- package/src/config.ts +3 -8
- package/src/dev.tsx +91 -36
- package/src/dialogs.tsx +2 -2
- package/src/index.tsx +171 -86
- package/src/inspect.ts +72 -19
- package/src/kv.tsx +1 -1
- package/src/module-collection.ts +5 -6
- package/src/npm-installer.ts +24 -0
- package/src/pages.tsx +16 -13
- package/src/proxy.ts +78 -10
- package/src/publish.ts +51 -26
- package/src/sites.tsx +14 -17
- package/src/user.tsx +13 -13
- package/wrangler-dist/cli.js +110749 -110111
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
package/bin/wrangler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { spawn } = require("child_process");
|
|
3
|
-
const { join } = require("path");
|
|
2
|
+
const { spawn } = require("node:child_process");
|
|
3
|
+
const { join } = require("node:path");
|
|
4
4
|
const semiver = require("semiver");
|
|
5
5
|
|
|
6
6
|
const MIN_NODE_VERSION = "16.7.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-b8a3e78",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"cli"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"esbuild": "0.14.
|
|
39
|
+
"esbuild": "0.14.14",
|
|
40
40
|
"miniflare": "2.2.0",
|
|
41
41
|
"path-to-regexp": "^6.2.0",
|
|
42
42
|
"semiver": "^1.1.0",
|
|
@@ -65,22 +65,21 @@
|
|
|
65
65
|
"faye-websocket": "^0.11.4",
|
|
66
66
|
"finalhandler": "^1.1.2",
|
|
67
67
|
"find-up": "^6.2.0",
|
|
68
|
-
"formdata-node": "^4.3.1",
|
|
69
68
|
"ignore": "^5.2.0",
|
|
70
69
|
"ink": "^3.2.0",
|
|
71
70
|
"ink-select-input": "^4.2.1",
|
|
72
71
|
"ink-table": "^3.0.0",
|
|
73
72
|
"ink-testing-library": "^2.1.0",
|
|
74
73
|
"ink-text-input": "^4.0.2",
|
|
74
|
+
"jest-fetch-mock": "^3.0.3",
|
|
75
75
|
"mime": "^3.0.0",
|
|
76
|
-
"node-fetch": "3.1.1",
|
|
77
76
|
"open": "^8.4.0",
|
|
78
77
|
"react": "^17.0.2",
|
|
79
78
|
"react-error-boundary": "^3.1.4",
|
|
80
79
|
"serve-static": "^1.14.1",
|
|
81
80
|
"signal-exit": "^3.0.6",
|
|
82
81
|
"tmp-promise": "^3.0.3",
|
|
83
|
-
"undici": "
|
|
82
|
+
"undici": "4.13.0",
|
|
84
83
|
"ws": "^8.3.0",
|
|
85
84
|
"yargs": "^17.3.0"
|
|
86
85
|
},
|
|
@@ -99,7 +98,7 @@
|
|
|
99
98
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
100
99
|
"build": "npm run clean && npm run bundle",
|
|
101
100
|
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
102
|
-
"test": "
|
|
101
|
+
"test": "jest --silent=false --verbose=true",
|
|
103
102
|
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
104
103
|
},
|
|
105
104
|
"engines": {
|
|
@@ -107,12 +106,13 @@
|
|
|
107
106
|
},
|
|
108
107
|
"jest": {
|
|
109
108
|
"restoreMocks": true,
|
|
109
|
+
"testTimeout": 30000,
|
|
110
110
|
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
111
111
|
"transformIgnorePatterns": [
|
|
112
|
-
"node_modules/(?!
|
|
112
|
+
"node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream)"
|
|
113
113
|
],
|
|
114
114
|
"moduleNameMapper": {
|
|
115
|
-
"clipboardy": "<rootDir>/src/__tests__/clipboardy-mock.js"
|
|
115
|
+
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js"
|
|
116
116
|
},
|
|
117
117
|
"transform": {
|
|
118
118
|
"^.+\\.c?(t|j)sx?$": [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { transform } from "esbuild";
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
4
3
|
import * as acorn from "acorn";
|
|
5
4
|
import * as acornWalk from "acorn-walk";
|
|
5
|
+
import { transform } from "esbuild";
|
|
6
6
|
import type { Config, RouteConfig } from "./routes";
|
|
7
7
|
import type { ExportNamedDeclaration, Identifier } from "estree";
|
|
8
8
|
|
|
@@ -44,11 +44,14 @@ function renderDev({
|
|
|
44
44
|
compatibilityFlags,
|
|
45
45
|
usageModel,
|
|
46
46
|
buildCommand = {},
|
|
47
|
+
enableLocalPersistence = false,
|
|
48
|
+
env = undefined,
|
|
47
49
|
}: Partial<DevProps>) {
|
|
48
50
|
return render(
|
|
49
51
|
<Dev
|
|
50
52
|
name={name}
|
|
51
53
|
entry={entry}
|
|
54
|
+
env={env}
|
|
52
55
|
port={port}
|
|
53
56
|
buildCommand={buildCommand}
|
|
54
57
|
format={format}
|
|
@@ -62,6 +65,7 @@ function renderDev({
|
|
|
62
65
|
compatibilityFlags={compatibilityFlags}
|
|
63
66
|
usageModel={usageModel}
|
|
64
67
|
bindings={bindings}
|
|
68
|
+
enableLocalPersistence={enableLocalPersistence}
|
|
65
69
|
/>
|
|
66
70
|
);
|
|
67
71
|
}
|
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const ORIGINAL_CF_API_TOKEN = process.env.CF_API_TOKEN;
|
|
2
|
+
const ORIGINAL_CF_ACCOUNT_ID = process.env.CF_ACCOUNT_ID;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Mock the API token so that we don't need to read it from user configuration files.
|
|
6
|
+
*/
|
|
7
|
+
export function mockApiToken({
|
|
8
|
+
apiToken = "some-api-token",
|
|
9
|
+
}: { apiToken?: string } = {}) {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
process.env.CF_API_TOKEN = apiToken;
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
process.env.CF_API_TOKEN = ORIGINAL_CF_API_TOKEN;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mock the current account ID so that we don't need to read it from configuration files.
|
|
20
|
+
*/
|
|
21
|
+
export function mockAccountId({
|
|
22
|
+
accountId = "some-account-id",
|
|
23
|
+
}: { accountId?: string } = {}) {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
process.env.CF_ACCOUNT_ID = accountId;
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
process.env.CF_ACCOUNT_ID = ORIGINAL_CF_ACCOUNT_ID;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { URLSearchParams } from "node:url";
|
|
1
|
+
import { URL, URLSearchParams } from "node:url";
|
|
3
2
|
import { pathToRegexp } from "path-to-regexp";
|
|
4
|
-
import { CF_API_BASE_URL } from "
|
|
5
|
-
import type { FetchResult } from "
|
|
3
|
+
import { CF_API_BASE_URL } from "../../cfetch";
|
|
4
|
+
import type { FetchResult } from "../../cfetch";
|
|
5
|
+
import type { RequestInit } from "undici";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The signature of the function that will handle a mock request.
|
|
@@ -11,7 +11,7 @@ export type MockHandler<ResponseType> = (
|
|
|
11
11
|
uri: RegExpExecArray,
|
|
12
12
|
init: RequestInit,
|
|
13
13
|
queryParams: URLSearchParams
|
|
14
|
-
) => ResponseType
|
|
14
|
+
) => ResponseType | Promise<ResponseType>;
|
|
15
15
|
|
|
16
16
|
type RemoveMockFn = () => void;
|
|
17
17
|
|
|
@@ -41,7 +41,7 @@ export async function mockFetchInternal(
|
|
|
41
41
|
if (uri !== null && (!method || method === (init.method ?? "GET"))) {
|
|
42
42
|
// The `resource` regular expression will extract the labelled groups from the URL.
|
|
43
43
|
// These are passed through to the `handler` call, to allow it to do additional checks or behaviour.
|
|
44
|
-
return handler(uri, init, queryParams); // TODO: should we have some kind of fallthrough system? we'll see.
|
|
44
|
+
return await handler(uri, init, queryParams); // TODO: should we have some kind of fallthrough system? we'll see.
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
throw new Error(
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We use this module to mock console methods, and optionally
|
|
3
|
+
* assert on the values they're called with in our tests.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
let logSpy: jest.SpyInstance,
|
|
7
|
+
errorSpy: jest.SpyInstance,
|
|
8
|
+
warnSpy: jest.SpyInstance;
|
|
9
|
+
|
|
10
|
+
const std = {
|
|
11
|
+
get out() {
|
|
12
|
+
return normalizeSlashes(stripTimings(logSpy.mock.calls.flat(2).join("\n")));
|
|
13
|
+
},
|
|
14
|
+
get err() {
|
|
15
|
+
return normalizeSlashes(
|
|
16
|
+
stripTimings(errorSpy.mock.calls.flat(2).join("\n"))
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
get warn() {
|
|
20
|
+
return normalizeSlashes(
|
|
21
|
+
stripTimings(warnSpy.mock.calls.flat(2).join("\n"))
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function mockConsoleMethods() {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
logSpy = jest.spyOn(console, "log").mockImplementation();
|
|
29
|
+
errorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
30
|
+
warnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
31
|
+
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
logSpy.mockRestore();
|
|
34
|
+
errorSpy.mockRestore();
|
|
35
|
+
warnSpy.mockRestore();
|
|
36
|
+
});
|
|
37
|
+
return std;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Ensure slashes in the `str` are OS file-system agnostic.
|
|
42
|
+
*
|
|
43
|
+
* Use this in snapshot tests to be resilient to file-system differences.
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeSlashes(str: string): string {
|
|
46
|
+
return str.replace(/\\/g, "/");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Strip "timing data" out of the `stdout` string, since this is not always deterministic.
|
|
51
|
+
*
|
|
52
|
+
* Use this in snapshot tests to be resilient to slight changes in timing of processing.
|
|
53
|
+
*/
|
|
54
|
+
export function stripTimings(stdout: string): string {
|
|
55
|
+
return stdout.replace(/\(\d+\.\d+ sec\)/g, "(TIMINGS)");
|
|
56
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createFetchResult, setMockRawResponse } from "./mock-cfetch";
|
|
2
|
+
|
|
3
|
+
export function mockKeyListRequest(
|
|
4
|
+
expectedNamespaceId: string,
|
|
5
|
+
expectedKeys: string[],
|
|
6
|
+
keysPerRequest = 1000,
|
|
7
|
+
blankCursorValue: "" | undefined | null = undefined
|
|
8
|
+
) {
|
|
9
|
+
const requests = { count: 0 };
|
|
10
|
+
// See https://api.cloudflare.com/#workers-kv-namespace-list-a-namespace-s-keys
|
|
11
|
+
const expectedKeyObjects = expectedKeys.map((name) => ({
|
|
12
|
+
name,
|
|
13
|
+
expiration: 123456789,
|
|
14
|
+
metadata: {},
|
|
15
|
+
}));
|
|
16
|
+
setMockRawResponse(
|
|
17
|
+
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/keys",
|
|
18
|
+
"GET",
|
|
19
|
+
([_url, accountId, namespaceId], _init, query) => {
|
|
20
|
+
requests.count++;
|
|
21
|
+
expect(accountId).toEqual("some-account-id");
|
|
22
|
+
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
23
|
+
if (expectedKeyObjects.length <= keysPerRequest) {
|
|
24
|
+
return createFetchResult(expectedKeyObjects);
|
|
25
|
+
} else {
|
|
26
|
+
const start = parseInt(query.get("cursor") ?? "0") || 0;
|
|
27
|
+
const end = start + keysPerRequest;
|
|
28
|
+
const cursor = end < expectedKeyObjects.length ? end : blankCursorValue;
|
|
29
|
+
return createFetchResult(
|
|
30
|
+
expectedKeyObjects.slice(start, end),
|
|
31
|
+
true,
|
|
32
|
+
[],
|
|
33
|
+
[],
|
|
34
|
+
{ cursor }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
return requests;
|
|
40
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export function writeUserConfig(
|
|
6
|
+
oauth_token?: string,
|
|
7
|
+
refresh_token?: string,
|
|
8
|
+
expiration_time?: string
|
|
9
|
+
) {
|
|
10
|
+
const lines: string[] = [];
|
|
11
|
+
if (oauth_token) {
|
|
12
|
+
lines.push(`oauth_token = "${oauth_token}"`);
|
|
13
|
+
}
|
|
14
|
+
if (refresh_token) {
|
|
15
|
+
lines.push(`refresh_token = "${refresh_token}"`);
|
|
16
|
+
}
|
|
17
|
+
if (expiration_time) {
|
|
18
|
+
lines.push(`expiration_time = "${expiration_time}"`);
|
|
19
|
+
}
|
|
20
|
+
const configPath = path.join(os.homedir(), ".wrangler/config");
|
|
21
|
+
mkdirSync(configPath, { recursive: true });
|
|
22
|
+
writeFileSync(
|
|
23
|
+
path.join(configPath, "default.toml"),
|
|
24
|
+
lines.join("\n"),
|
|
25
|
+
"utf-8"
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
const originalCwd = process.cwd();
|
|
6
|
+
|
|
7
|
+
export function runInTempDir({ homedir }: { homedir?: string } = {}) {
|
|
8
|
+
let tmpDir: string;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
|
|
12
|
+
process.chdir(tmpDir);
|
|
13
|
+
if (homedir !== undefined) {
|
|
14
|
+
// Override where the home directory is so that we can write our own user config,
|
|
15
|
+
// without destroying the real thing.
|
|
16
|
+
fs.mkdirSync(homedir);
|
|
17
|
+
// Note it is very important that we use the "default" value from "node:os" (e.g. `import os from "node:os";`)
|
|
18
|
+
// rather than an alias to the module (e.g. `import * as os from "node:os";`).
|
|
19
|
+
// This is because the module gets transpiled so that the "method" `homedir()` gets converted to a
|
|
20
|
+
// getter that is not configurable (and so cannot be spied upon).
|
|
21
|
+
jest.spyOn(os, "homedir").mockReturnValue(homedir);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
process.chdir(originalCwd);
|
|
27
|
+
fs.rmSync(tmpDir, { recursive: true });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { main } from "../../index";
|
|
2
|
+
import { normalizeSlashes, stripTimings } from "./mock-console";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A helper to 'run' wrangler commands for tests.
|
|
6
|
+
*/
|
|
7
|
+
export async function runWrangler(cmd?: string) {
|
|
8
|
+
try {
|
|
9
|
+
await main(cmd?.split(" ") ?? []);
|
|
10
|
+
} catch (e) {
|
|
11
|
+
e.message = normalizeSlashes(stripTimings(e.message));
|
|
12
|
+
throw e;
|
|
13
|
+
}
|
|
14
|
+
}
|