wrangler 0.0.0-e95bea2 → 0.0.0-ea8e701
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/bin/wrangler.js +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +7 -6
- package/pages/functions/filepath-routing.test.ts +125 -25
- package/pages/functions/filepath-routing.ts +6 -3
- package/src/__tests__/configuration.test.ts +826 -223
- package/src/__tests__/dev.test.tsx +145 -9
- package/src/__tests__/guess-worker-format.test.ts +26 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
- package/src/__tests__/helpers/run-in-tmp.ts +3 -0
- package/src/__tests__/index.test.ts +9 -13
- package/src/__tests__/jest.setup.ts +5 -0
- package/src/__tests__/kv.test.ts +43 -71
- package/src/__tests__/pages.test.ts +48 -10
- package/src/__tests__/publish.test.ts +1456 -327
- package/src/__tests__/r2.test.ts +4 -4
- package/src/__tests__/tail.test.ts +78 -4
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +16 -7
- package/src/bundle.ts +15 -2
- package/src/cfetch/internal.ts +9 -5
- package/src/config/README.md +6 -6
- package/src/config/config.ts +17 -78
- package/src/config/environment.ts +67 -1
- package/src/config/index.ts +13 -3
- package/src/config/validation-helpers.ts +177 -11
- package/src/config/validation.ts +305 -100
- package/src/dev/dev.tsx +76 -41
- package/src/dev/local.tsx +105 -114
- package/src/dev/remote.tsx +2 -0
- package/src/dev/use-esbuild.ts +4 -0
- package/src/entry.ts +103 -6
- package/src/index.tsx +251 -189
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +58 -53
- package/src/pages.tsx +26 -10
- package/src/proxy.ts +5 -3
- package/src/publish.ts +17 -21
- package/src/sites.tsx +67 -25
- package/src/tail/index.ts +1 -1
- package/src/tail/printing.ts +2 -2
- package/src/user.tsx +161 -81
- package/wrangler-dist/cli.js +3418 -1437
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/dev2.test.tsx +0 -152
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import TestRenderer from "react-test-renderer";
|
|
4
|
-
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
|
|
5
|
-
import { unsetAllMocks } from "./helpers/mock-cfetch";
|
|
6
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
|
-
import type { DevProps, default as DevType } from "../dev/dev";
|
|
9
|
-
|
|
10
|
-
function sleep(period = 100): Promise<void> {
|
|
11
|
-
return new Promise((resolve) => setTimeout(resolve, period));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// we use this ["mock"] form to avoid esbuild-jest from rewriting it
|
|
15
|
-
jest["mock"]("../proxy", () => {
|
|
16
|
-
return {
|
|
17
|
-
usePreviewServer() {},
|
|
18
|
-
waitForPortToBeAvailable() {},
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
jest["mock"]("../inspect", () => {
|
|
22
|
-
return () => {};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const Dev: typeof DevType = jest.requireActual("../dev/dev").DevImplementation;
|
|
26
|
-
|
|
27
|
-
mockAccountId();
|
|
28
|
-
mockApiToken();
|
|
29
|
-
runInTempDir();
|
|
30
|
-
mockConsoleMethods();
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
unsetAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("dev", () => {
|
|
36
|
-
it("should render", async () => {
|
|
37
|
-
fs.writeFileSync("./index.js", `export default {}`);
|
|
38
|
-
|
|
39
|
-
const testRenderer = await renderDev({
|
|
40
|
-
entry: {
|
|
41
|
-
file: "./index.js",
|
|
42
|
-
directory: process.cwd(),
|
|
43
|
-
format: "modules",
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
expect(testRenderer.toJSON()).toMatchInlineSnapshot(`
|
|
47
|
-
<ink-box
|
|
48
|
-
style={
|
|
49
|
-
Object {
|
|
50
|
-
"borderStyle": "round",
|
|
51
|
-
"flexDirection": "row",
|
|
52
|
-
"flexGrow": 0,
|
|
53
|
-
"flexShrink": 1,
|
|
54
|
-
"marginBottom": 0,
|
|
55
|
-
"marginLeft": 0,
|
|
56
|
-
"marginRight": 0,
|
|
57
|
-
"marginTop": 0,
|
|
58
|
-
"paddingBottom": 0,
|
|
59
|
-
"paddingLeft": 1,
|
|
60
|
-
"paddingRight": 1,
|
|
61
|
-
"paddingTop": 0,
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
>
|
|
65
|
-
<ink-text
|
|
66
|
-
internal_transform={[Function]}
|
|
67
|
-
style={
|
|
68
|
-
Object {
|
|
69
|
-
"flexDirection": "row",
|
|
70
|
-
"flexGrow": 0,
|
|
71
|
-
"flexShrink": 1,
|
|
72
|
-
"textWrap": "wrap",
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
>
|
|
76
|
-
B to open a browser, D to open Devtools, L to turn off local mode, X to exit
|
|
77
|
-
</ink-text>
|
|
78
|
-
</ink-box>
|
|
79
|
-
`);
|
|
80
|
-
await TestRenderer.act(async () => {
|
|
81
|
-
// TODO: get rid of these sleep statements
|
|
82
|
-
await sleep(50);
|
|
83
|
-
testRenderer.unmount();
|
|
84
|
-
await sleep(50);
|
|
85
|
-
});
|
|
86
|
-
await sleep(50);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
async function renderDev({
|
|
91
|
-
name,
|
|
92
|
-
entry = { file: "index.js", directory: "", format: "modules" },
|
|
93
|
-
port,
|
|
94
|
-
inspectorPort = 9229,
|
|
95
|
-
accountId,
|
|
96
|
-
legacyEnv = true,
|
|
97
|
-
initialMode = "local",
|
|
98
|
-
jsxFactory,
|
|
99
|
-
jsxFragment,
|
|
100
|
-
localProtocol = "http",
|
|
101
|
-
upstreamProtocol = "https",
|
|
102
|
-
rules = [],
|
|
103
|
-
bindings = {
|
|
104
|
-
kv_namespaces: [],
|
|
105
|
-
vars: {},
|
|
106
|
-
durable_objects: { bindings: [] },
|
|
107
|
-
r2_buckets: [],
|
|
108
|
-
wasm_modules: undefined,
|
|
109
|
-
text_blobs: undefined,
|
|
110
|
-
unsafe: [],
|
|
111
|
-
},
|
|
112
|
-
public: publicDir,
|
|
113
|
-
assetPaths,
|
|
114
|
-
compatibilityDate,
|
|
115
|
-
compatibilityFlags,
|
|
116
|
-
usageModel,
|
|
117
|
-
buildCommand = {},
|
|
118
|
-
enableLocalPersistence = false,
|
|
119
|
-
env,
|
|
120
|
-
zone,
|
|
121
|
-
}: Partial<DevProps>): Promise<TestRenderer.ReactTestRenderer> {
|
|
122
|
-
let instance: TestRenderer.ReactTestRenderer | undefined;
|
|
123
|
-
await TestRenderer.act(async () => {
|
|
124
|
-
instance = TestRenderer.create(
|
|
125
|
-
<Dev
|
|
126
|
-
name={name}
|
|
127
|
-
entry={entry}
|
|
128
|
-
env={env}
|
|
129
|
-
rules={rules}
|
|
130
|
-
port={port}
|
|
131
|
-
inspectorPort={inspectorPort}
|
|
132
|
-
legacyEnv={legacyEnv}
|
|
133
|
-
buildCommand={buildCommand}
|
|
134
|
-
initialMode={initialMode}
|
|
135
|
-
localProtocol={localProtocol}
|
|
136
|
-
upstreamProtocol={upstreamProtocol}
|
|
137
|
-
jsxFactory={jsxFactory}
|
|
138
|
-
jsxFragment={jsxFragment}
|
|
139
|
-
accountId={accountId}
|
|
140
|
-
assetPaths={assetPaths}
|
|
141
|
-
public={publicDir}
|
|
142
|
-
compatibilityDate={compatibilityDate}
|
|
143
|
-
compatibilityFlags={compatibilityFlags}
|
|
144
|
-
usageModel={usageModel}
|
|
145
|
-
bindings={bindings}
|
|
146
|
-
enableLocalPersistence={enableLocalPersistence}
|
|
147
|
-
zone={zone}
|
|
148
|
-
/>
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
return instance as TestRenderer.ReactTestRenderer;
|
|
152
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import fetchMock from "jest-fetch-mock";
|
|
5
|
-
import { initialise } from "../user";
|
|
6
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { writeUserConfig } from "./helpers/mock-user";
|
|
8
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
|
-
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
|
-
|
|
11
|
-
describe("wrangler", () => {
|
|
12
|
-
runInTempDir({ homedir: "./home" });
|
|
13
|
-
const std = mockConsoleMethods();
|
|
14
|
-
|
|
15
|
-
describe("logout", () => {
|
|
16
|
-
it("should exit with a message stating the user is not logged in", async () => {
|
|
17
|
-
await initialise();
|
|
18
|
-
await runWrangler("logout");
|
|
19
|
-
expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should logout user that has been properly logged in", async () => {
|
|
23
|
-
writeUserConfig("some-oauth-tok", "some-refresh-tok");
|
|
24
|
-
|
|
25
|
-
// Mock out the response for a request to revoke the auth tokens,
|
|
26
|
-
// checking the form of the request is as expected.
|
|
27
|
-
fetchMock.mockResponseOnce(async (req) => {
|
|
28
|
-
expect(req.url).toEqual("https://dash.cloudflare.com/oauth2/revoke");
|
|
29
|
-
expect(req.method).toEqual("POST");
|
|
30
|
-
return "";
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await initialise();
|
|
34
|
-
await runWrangler("logout");
|
|
35
|
-
|
|
36
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
37
|
-
"💁 Wrangler is configured with an OAuth token. The token has been successfully revoked
|
|
38
|
-
Removing ./home/.wrangler/config/default.toml.. success!"
|
|
39
|
-
`);
|
|
40
|
-
|
|
41
|
-
// Make sure that we made the request to logout.
|
|
42
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
43
|
-
|
|
44
|
-
// Make sure that logout removed the config file containing the auth tokens.
|
|
45
|
-
expect(
|
|
46
|
-
existsSync(path.join(os.homedir(), ".wrangler/config/default.toml"))
|
|
47
|
-
).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|