wrangler 0.0.0-e2a26a0 → 0.0.0-e2a6fa40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +47 -16
- package/bin/wrangler.js +118 -32
- package/kv-asset-handler.js +1 -0
- package/package.json +147 -78
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +30 -0
- package/templates/facade.d.ts +17 -0
- package/templates/gitignore +172 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +137 -0
- package/templates/middleware/loader-sw.ts +228 -0
- package/templates/middleware/middleware-d1-beta.d.ts +3 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
- package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
- package/templates/middleware/middleware-multiworker-dev.ts +59 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +4 -4
- package/templates/new-worker.ts +22 -4
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +8 -0
- package/wrangler-dist/cli.d.ts +1734 -0
- package/wrangler-dist/cli.js +139455 -113761
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -47
- package/pages/functions/filepath-routing.ts +0 -231
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -160
- package/pages/functions/template-worker.ts +0 -136
- package/src/__tests__/dev.test.tsx +0 -71
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/mock-account-id.ts +0 -30
- package/src/__tests__/helpers/mock-bin.ts +0 -33
- package/src/__tests__/helpers/mock-cfetch.ts +0 -207
- package/src/__tests__/helpers/mock-console.ts +0 -56
- package/src/__tests__/helpers/mock-dialogs.ts +0 -65
- package/src/__tests__/helpers/mock-kv.ts +0 -40
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/helpers/run-in-tmp.ts +0 -29
- package/src/__tests__/helpers/run-wrangler.ts +0 -14
- package/src/__tests__/index.test.ts +0 -543
- package/src/__tests__/jest.setup.ts +0 -37
- package/src/__tests__/kv.test.ts +0 -1139
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/package-manager.test.ts +0 -206
- package/src/__tests__/publish.test.ts +0 -1222
- package/src/__tests__/secret.test.ts +0 -210
- package/src/__tests__/whoami.test.tsx +0 -86
- package/src/api/form_data.ts +0 -134
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch/index.ts +0 -102
- package/src/cfetch/internal.ts +0 -101
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -2101
- package/src/inspect.ts +0 -596
- package/src/kv.tsx +0 -284
- package/src/module-collection.ts +0 -63
- package/src/package-manager.ts +0 -120
- package/src/pages.tsx +0 -1046
- package/src/paths.ts +0 -26
- package/src/proxy.ts +0 -370
- package/src/publish.ts +0 -410
- package/src/sites.tsx +0 -240
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1019
- package/src/whoami.tsx +0 -69
- package/templates/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,543 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
|
-
import * as TOML from "@iarna/toml";
|
|
4
|
-
import { version as wranglerVersion } from "../../package.json";
|
|
5
|
-
import { getPackageManager } from "../package-manager";
|
|
6
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
8
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
|
-
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
|
-
import type { PackageManager } from "../package-manager";
|
|
11
|
-
|
|
12
|
-
describe("wrangler", () => {
|
|
13
|
-
let mockPackageManager: PackageManager;
|
|
14
|
-
runInTempDir();
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
mockPackageManager = {
|
|
18
|
-
addDevDeps: jest.fn(),
|
|
19
|
-
install: jest.fn(),
|
|
20
|
-
};
|
|
21
|
-
(getPackageManager as jest.Mock).mockResolvedValue(mockPackageManager);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const std = mockConsoleMethods();
|
|
25
|
-
|
|
26
|
-
describe("no command", () => {
|
|
27
|
-
it("should display a list of available commands", async () => {
|
|
28
|
-
await runWrangler();
|
|
29
|
-
|
|
30
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
31
|
-
"wrangler
|
|
32
|
-
|
|
33
|
-
Commands:
|
|
34
|
-
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
35
|
-
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
36
|
-
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
37
|
-
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
38
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
39
|
-
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
40
|
-
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
41
|
-
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
42
|
-
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
43
|
-
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
44
|
-
|
|
45
|
-
Flags:
|
|
46
|
-
-c, --config Path to .toml configuration file [string]
|
|
47
|
-
-h, --help Show help [boolean]
|
|
48
|
-
-v, --version Show version number [boolean]
|
|
49
|
-
|
|
50
|
-
Options:
|
|
51
|
-
-l, --local Run on my machine [boolean] [default: false]"
|
|
52
|
-
`);
|
|
53
|
-
|
|
54
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe("invalid command", () => {
|
|
59
|
-
it("should display an error", async () => {
|
|
60
|
-
await expect(
|
|
61
|
-
runWrangler("invalid-command")
|
|
62
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
63
|
-
`"Unknown command: invalid-command."`
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
67
|
-
expect(std.err).toMatchInlineSnapshot(`
|
|
68
|
-
"wrangler
|
|
69
|
-
|
|
70
|
-
Commands:
|
|
71
|
-
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
72
|
-
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
73
|
-
wrangler dev <filename> 👂 Start a local server for developing your worker
|
|
74
|
-
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
75
|
-
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
76
|
-
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
77
|
-
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
|
|
78
|
-
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
|
|
79
|
-
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
80
|
-
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
81
|
-
|
|
82
|
-
Flags:
|
|
83
|
-
-c, --config Path to .toml configuration file [string]
|
|
84
|
-
-h, --help Show help [boolean]
|
|
85
|
-
-v, --version Show version number [boolean]
|
|
86
|
-
|
|
87
|
-
Options:
|
|
88
|
-
-l, --local Run on my machine [boolean] [default: false]
|
|
89
|
-
|
|
90
|
-
Unknown command: invalid-command."
|
|
91
|
-
`);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe("init", () => {
|
|
96
|
-
it("should create a wrangler.toml", async () => {
|
|
97
|
-
mockConfirm({
|
|
98
|
-
text: "No package.json found. Would you like to create one?",
|
|
99
|
-
result: false,
|
|
100
|
-
});
|
|
101
|
-
await runWrangler("init");
|
|
102
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
103
|
-
expect(typeof parsed.compatibility_date).toBe("string");
|
|
104
|
-
expect(fs.existsSync("./package.json")).toBe(false);
|
|
105
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
109
|
-
fs.writeFileSync(
|
|
110
|
-
"./wrangler.toml",
|
|
111
|
-
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
112
|
-
"utf-8"
|
|
113
|
-
);
|
|
114
|
-
mockConfirm({
|
|
115
|
-
text: "Do you want to continue initializing this project?",
|
|
116
|
-
result: false,
|
|
117
|
-
});
|
|
118
|
-
await runWrangler("init");
|
|
119
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
120
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
121
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
125
|
-
fs.writeFileSync(
|
|
126
|
-
"./wrangler.toml",
|
|
127
|
-
`compatibility_date="something-else"`,
|
|
128
|
-
"utf-8"
|
|
129
|
-
);
|
|
130
|
-
mockConfirm(
|
|
131
|
-
{
|
|
132
|
-
text: "Do you want to continue initializing this project?",
|
|
133
|
-
result: true,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
text: "No package.json found. Would you like to create one?",
|
|
137
|
-
result: false,
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
await runWrangler("init");
|
|
141
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
142
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
143
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should create a package.json if none is found and user confirms", async () => {
|
|
147
|
-
mockConfirm(
|
|
148
|
-
{
|
|
149
|
-
text: "No package.json found. Would you like to create one?",
|
|
150
|
-
result: true,
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
text: "Would you like to use TypeScript?",
|
|
154
|
-
result: false,
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
158
|
-
result: false,
|
|
159
|
-
}
|
|
160
|
-
);
|
|
161
|
-
await runWrangler("init");
|
|
162
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
163
|
-
const packageJson = JSON.parse(
|
|
164
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
165
|
-
);
|
|
166
|
-
expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
|
|
167
|
-
expect(packageJson.version).toEqual("0.0.0");
|
|
168
|
-
expect(packageJson.devDependencies).toEqual({
|
|
169
|
-
wrangler: expect.any(String),
|
|
170
|
-
});
|
|
171
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
172
|
-
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it("should not touch an existing package.json in the same directory", async () => {
|
|
176
|
-
mockConfirm(
|
|
177
|
-
{
|
|
178
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
179
|
-
result: false,
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
text: "Would you like to use TypeScript?",
|
|
183
|
-
result: false,
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
187
|
-
result: false,
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
fs.writeFileSync(
|
|
192
|
-
"./package.json",
|
|
193
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
194
|
-
"utf-8"
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
await runWrangler("init");
|
|
198
|
-
const packageJson = JSON.parse(
|
|
199
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
200
|
-
);
|
|
201
|
-
expect(packageJson.name).toEqual("test");
|
|
202
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("should offer to install wrangler into an existing package.json", async () => {
|
|
206
|
-
mockConfirm(
|
|
207
|
-
{
|
|
208
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
209
|
-
result: true,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
text: "Would you like to use TypeScript?",
|
|
213
|
-
result: false,
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
217
|
-
result: false,
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
fs.writeFileSync(
|
|
222
|
-
"./package.json",
|
|
223
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
224
|
-
"utf-8"
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
await runWrangler("init");
|
|
228
|
-
const packageJson = JSON.parse(
|
|
229
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
230
|
-
);
|
|
231
|
-
expect(packageJson.name).toEqual("test");
|
|
232
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
233
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
234
|
-
`wrangler@${wranglerVersion}`
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("should not touch an existing package.json in an ancestor directory", async () => {
|
|
239
|
-
mockConfirm(
|
|
240
|
-
{
|
|
241
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
242
|
-
result: false,
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
text: "Would you like to use TypeScript?",
|
|
246
|
-
result: false,
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
250
|
-
result: false,
|
|
251
|
-
}
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
fs.writeFileSync(
|
|
255
|
-
"./package.json",
|
|
256
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
257
|
-
"utf-8"
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
261
|
-
process.chdir("./sub-1/sub-2");
|
|
262
|
-
|
|
263
|
-
await runWrangler("init");
|
|
264
|
-
expect(fs.existsSync("./package.json")).toBe(false);
|
|
265
|
-
expect(fs.existsSync("../../package.json")).toBe(true);
|
|
266
|
-
|
|
267
|
-
const packageJson = JSON.parse(
|
|
268
|
-
fs.readFileSync("../../package.json", "utf-8")
|
|
269
|
-
);
|
|
270
|
-
expect(packageJson).toMatchInlineSnapshot(`
|
|
271
|
-
Object {
|
|
272
|
-
"name": "test",
|
|
273
|
-
"version": "1.0.0",
|
|
274
|
-
}
|
|
275
|
-
`);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("should offer to create a worker in a non-typescript project", async () => {
|
|
279
|
-
mockConfirm(
|
|
280
|
-
{
|
|
281
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
282
|
-
result: false,
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
text: "Would you like to use TypeScript?",
|
|
286
|
-
result: false,
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
290
|
-
result: true,
|
|
291
|
-
}
|
|
292
|
-
);
|
|
293
|
-
|
|
294
|
-
fs.writeFileSync(
|
|
295
|
-
"./package.json",
|
|
296
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
297
|
-
"utf-8"
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
await runWrangler("init");
|
|
301
|
-
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
302
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
it("should offer to create a worker in a typescript project", async () => {
|
|
306
|
-
mockConfirm(
|
|
307
|
-
{
|
|
308
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
309
|
-
result: false,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
text: "Would you like to use TypeScript?",
|
|
313
|
-
result: true,
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
317
|
-
result: true,
|
|
318
|
-
}
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
fs.writeFileSync(
|
|
322
|
-
"./package.json",
|
|
323
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
324
|
-
"utf-8"
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
await runWrangler("init");
|
|
328
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
329
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
|
|
333
|
-
mockConfirm(
|
|
334
|
-
{
|
|
335
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
336
|
-
result: false,
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
text: "Would you like to use TypeScript?",
|
|
340
|
-
result: false,
|
|
341
|
-
}
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
fs.writeFileSync(
|
|
345
|
-
"./package.json",
|
|
346
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
347
|
-
"utf-8"
|
|
348
|
-
);
|
|
349
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
350
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
351
|
-
fs.writeFileSync("./src/index.js", PLACEHOLDER, "utf-8");
|
|
352
|
-
|
|
353
|
-
await runWrangler("init");
|
|
354
|
-
expect(fs.readFileSync("./src/index.js", "utf-8")).toBe(PLACEHOLDER);
|
|
355
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
|
|
359
|
-
mockConfirm(
|
|
360
|
-
{
|
|
361
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
362
|
-
result: false,
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
text: "Would you like to use TypeScript?",
|
|
366
|
-
result: true,
|
|
367
|
-
}
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
fs.writeFileSync(
|
|
371
|
-
"./package.json",
|
|
372
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
373
|
-
"utf-8"
|
|
374
|
-
);
|
|
375
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
376
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
377
|
-
fs.writeFileSync("./src/index.ts", PLACEHOLDER, "utf-8");
|
|
378
|
-
|
|
379
|
-
await runWrangler("init");
|
|
380
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
381
|
-
expect(fs.readFileSync("./src/index.ts", "utf-8")).toBe(PLACEHOLDER);
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
385
|
-
mockConfirm(
|
|
386
|
-
{
|
|
387
|
-
text: "No package.json found. Would you like to create one?",
|
|
388
|
-
result: true,
|
|
389
|
-
},
|
|
390
|
-
{
|
|
391
|
-
text: "Would you like to use TypeScript?",
|
|
392
|
-
result: true,
|
|
393
|
-
},
|
|
394
|
-
{
|
|
395
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
396
|
-
result: false,
|
|
397
|
-
}
|
|
398
|
-
);
|
|
399
|
-
await runWrangler("init");
|
|
400
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
401
|
-
const tsconfigJson = JSON.parse(
|
|
402
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
403
|
-
);
|
|
404
|
-
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
405
|
-
"@cloudflare/workers-types",
|
|
406
|
-
]);
|
|
407
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
408
|
-
"@cloudflare/workers-types",
|
|
409
|
-
"typescript"
|
|
410
|
-
);
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
414
|
-
fs.writeFileSync(
|
|
415
|
-
"./package.json",
|
|
416
|
-
JSON.stringify({
|
|
417
|
-
name: "test",
|
|
418
|
-
version: "1.0.0",
|
|
419
|
-
devDependencies: {
|
|
420
|
-
wrangler: "0.0.0",
|
|
421
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
422
|
-
},
|
|
423
|
-
}),
|
|
424
|
-
"utf-8"
|
|
425
|
-
);
|
|
426
|
-
fs.writeFileSync(
|
|
427
|
-
"./tsconfig.json",
|
|
428
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
429
|
-
"utf-8"
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
await runWrangler("init");
|
|
433
|
-
const tsconfigJson = JSON.parse(
|
|
434
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
435
|
-
);
|
|
436
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
440
|
-
mockConfirm(
|
|
441
|
-
{
|
|
442
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
443
|
-
result: false,
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
447
|
-
result: true,
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
451
|
-
result: false,
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
fs.writeFileSync(
|
|
455
|
-
"./package.json",
|
|
456
|
-
JSON.stringify({
|
|
457
|
-
name: "test",
|
|
458
|
-
version: "1.0.0",
|
|
459
|
-
}),
|
|
460
|
-
"utf-8"
|
|
461
|
-
);
|
|
462
|
-
fs.writeFileSync(
|
|
463
|
-
"./tsconfig.json",
|
|
464
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
465
|
-
"utf-8"
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
await runWrangler("init");
|
|
469
|
-
const tsconfigJson = JSON.parse(
|
|
470
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
471
|
-
);
|
|
472
|
-
// unchanged tsconfig
|
|
473
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
474
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
475
|
-
"@cloudflare/workers-types"
|
|
476
|
-
);
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
480
|
-
fs.writeFileSync(
|
|
481
|
-
"./package.json",
|
|
482
|
-
JSON.stringify({
|
|
483
|
-
name: "test",
|
|
484
|
-
version: "1.0.0",
|
|
485
|
-
devDependencies: {
|
|
486
|
-
wrangler: "0.0.0",
|
|
487
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
488
|
-
},
|
|
489
|
-
}),
|
|
490
|
-
"utf-8"
|
|
491
|
-
);
|
|
492
|
-
fs.writeFileSync(
|
|
493
|
-
"./tsconfig.json",
|
|
494
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
495
|
-
"utf-8"
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
fs.mkdirSync("./sub-1/sub-2", { recursive: true });
|
|
499
|
-
process.chdir("./sub-1/sub-2");
|
|
500
|
-
|
|
501
|
-
await runWrangler("init");
|
|
502
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
503
|
-
expect(fs.existsSync("../../tsconfig.json")).toBe(true);
|
|
504
|
-
|
|
505
|
-
const tsconfigJson = JSON.parse(
|
|
506
|
-
fs.readFileSync("../../tsconfig.json", "utf-8")
|
|
507
|
-
);
|
|
508
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it("should error if `--type` is used", async () => {
|
|
512
|
-
await expect(
|
|
513
|
-
runWrangler("init --type")
|
|
514
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
515
|
-
`"The --type option is no longer supported."`
|
|
516
|
-
);
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it("should error if `--type javascript` is used", async () => {
|
|
520
|
-
await expect(
|
|
521
|
-
runWrangler("init --type javascript")
|
|
522
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
523
|
-
`"The --type option is no longer supported."`
|
|
524
|
-
);
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
it("should error if `--type rust` is used", async () => {
|
|
528
|
-
await expect(
|
|
529
|
-
runWrangler("init --type rust")
|
|
530
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
531
|
-
`"The --type option is no longer supported."`
|
|
532
|
-
);
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
it("should error if `--type webpack` is used", async () => {
|
|
536
|
-
await expect(runWrangler("init --type webpack")).rejects
|
|
537
|
-
.toThrowErrorMatchingInlineSnapshot(`
|
|
538
|
-
"The --type option is no longer supported.
|
|
539
|
-
If you wish to use webpack then you will need to create a custom build."
|
|
540
|
-
`);
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import fetchMock from "jest-fetch-mock";
|
|
2
|
-
import { fetchInternal, fetchKVGetValue } from "../cfetch/internal";
|
|
3
|
-
import { confirm, prompt } from "../dialogs";
|
|
4
|
-
import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
|
|
5
|
-
|
|
6
|
-
jest.mock("undici", () => {
|
|
7
|
-
return {
|
|
8
|
-
...jest.requireActual("undici"),
|
|
9
|
-
fetch: jest.requireActual("jest-fetch-mock"),
|
|
10
|
-
};
|
|
11
|
-
});
|
|
12
|
-
fetchMock.doMock(() => {
|
|
13
|
-
// Any un-mocked fetches should throw
|
|
14
|
-
throw new Error("Unexpected fetch request");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
jest.mock("../package-manager");
|
|
18
|
-
|
|
19
|
-
jest.mock("../cfetch/internal");
|
|
20
|
-
(fetchInternal as jest.Mock).mockImplementation(mockFetchInternal);
|
|
21
|
-
(fetchKVGetValue as jest.Mock).mockImplementation(mockFetchKVGetValue);
|
|
22
|
-
|
|
23
|
-
jest.mock("../dialogs");
|
|
24
|
-
|
|
25
|
-
// By default (if not configured by mockConfirm()) calls to `confirm()` should throw.
|
|
26
|
-
(confirm as jest.Mock).mockImplementation(() => {
|
|
27
|
-
throw new Error(
|
|
28
|
-
"Unexpected call to `confirm()`. You should use `mockConfirm()` to mock calls to `confirm()` with expectations. Search the codebase for `mockConfirm` to learn more."
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// By default (if not configured by mockPrompt()) calls to `prompt()` should throw.
|
|
33
|
-
(prompt as jest.Mock).mockImplementation(() => {
|
|
34
|
-
throw new Error(
|
|
35
|
-
"Unexpected call to `prompt()`. You should use `mockPrompt()` to mock calls to `prompt()` with expectations. Search the codebase for `mockPrompt` to learn more."
|
|
36
|
-
);
|
|
37
|
-
});
|