wrangler 0.0.0-e5d3690 → 0.0.0-e5ebdb143
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 +44 -25
- package/bin/wrangler.js +94 -31
- package/config-schema.json +3324 -0
- package/kv-asset-handler.js +1 -0
- package/package.json +146 -91
- 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 +19 -0
- package/templates/gitignore +170 -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 +134 -0
- package/templates/middleware/loader-sw.ts +229 -0
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
- package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
- package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
- package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +29 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +33 -0
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +32 -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/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +336 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +8 -0
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +241 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26702 -0
- package/wrangler-dist/cli.js +164834 -117766
- 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 -39
- package/pages/functions/filepath-routing.ts +0 -228
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -158
- package/pages/functions/template-worker.ts +0 -136
- package/src/__tests__/clipboardy-mock.js +0 -4
- package/src/__tests__/dev.test.tsx +0 -67
- package/src/__tests__/index.test.ts +0 -289
- package/src/__tests__/jest.setup.ts +0 -22
- package/src/__tests__/kv.test.ts +0 -1199
- package/src/__tests__/mock-cfetch.ts +0 -173
- package/src/__tests__/mock-dialogs.ts +0 -65
- package/src/__tests__/publish.test.ts +0 -672
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/__tests__/whoami.test.tsx +0 -130
- package/src/api/form_data.ts +0 -131
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch/index.ts +0 -110
- package/src/cfetch/internal.ts +0 -71
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -646
- package/src/dev.tsx +0 -779
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -1975
- package/src/inspect.ts +0 -543
- package/src/kv.tsx +0 -276
- package/src/module-collection.ts +0 -64
- package/src/pages.tsx +0 -1040
- package/src/proxy.ts +0 -302
- package/src/publish.ts +0 -382
- package/src/sites.tsx +0 -243
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1019
- package/src/whoami.tsx +0 -69
- package/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,672 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { KVNamespaceInfo } from "../kv";
|
|
4
|
-
import { mockKeyListRequest } from "./kv.test";
|
|
5
|
-
import { setMockResponse, unsetAllMocks } from "./mock-cfetch";
|
|
6
|
-
import { runInTempDir } from "./run-in-tmp";
|
|
7
|
-
import { runWrangler } from "./run-wrangler";
|
|
8
|
-
|
|
9
|
-
describe("publish", () => {
|
|
10
|
-
runInTempDir();
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
unsetAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe("entry-points", () => {
|
|
17
|
-
it("should be able to use `index` with no extension as the entry-point", async () => {
|
|
18
|
-
writeWranglerToml();
|
|
19
|
-
writeEsmWorkerSource();
|
|
20
|
-
mockUploadWorkerRequest();
|
|
21
|
-
mockSubDomainRequest();
|
|
22
|
-
|
|
23
|
-
const { stdout, stderr, error } = await runWrangler("publish ./index");
|
|
24
|
-
|
|
25
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
26
|
-
"Uploaded
|
|
27
|
-
test-name
|
|
28
|
-
(TIMINGS)
|
|
29
|
-
Deployed
|
|
30
|
-
test-name
|
|
31
|
-
(TIMINGS)
|
|
32
|
-
|
|
33
|
-
test-name.test-sub-domain.workers.dev"
|
|
34
|
-
`);
|
|
35
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
36
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should be able to use the `build.upload.main` config as the entry-point for ESM sources", async () => {
|
|
40
|
-
writeWranglerToml("./index.js");
|
|
41
|
-
writeEsmWorkerSource();
|
|
42
|
-
mockUploadWorkerRequest();
|
|
43
|
-
mockSubDomainRequest();
|
|
44
|
-
|
|
45
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
46
|
-
|
|
47
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
48
|
-
"Uploaded
|
|
49
|
-
test-name
|
|
50
|
-
(TIMINGS)
|
|
51
|
-
Deployed
|
|
52
|
-
test-name
|
|
53
|
-
(TIMINGS)
|
|
54
|
-
|
|
55
|
-
test-name.test-sub-domain.workers.dev"
|
|
56
|
-
`);
|
|
57
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
58
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("asset upload", () => {
|
|
63
|
-
it("should upload all the files in the directory specified by `config.site.bucket`", async () => {
|
|
64
|
-
const assets = [
|
|
65
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
66
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
67
|
-
];
|
|
68
|
-
const kvNamespace = {
|
|
69
|
-
title: "__test-name_sites_assets",
|
|
70
|
-
id: "__test-name_sites_assets-id",
|
|
71
|
-
};
|
|
72
|
-
writeWranglerToml("./index.js", "assets");
|
|
73
|
-
writeEsmWorkerSource();
|
|
74
|
-
writeAssets(assets);
|
|
75
|
-
mockUploadWorkerRequest();
|
|
76
|
-
mockSubDomainRequest();
|
|
77
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
78
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
79
|
-
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
|
|
80
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
81
|
-
|
|
82
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
83
|
-
"reading assets/file-1.txt...
|
|
84
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
85
|
-
reading assets/file-2.txt...
|
|
86
|
-
uploading as assets/file-2.5938485188.txt...
|
|
87
|
-
Uploaded
|
|
88
|
-
test-name
|
|
89
|
-
(TIMINGS)
|
|
90
|
-
Deployed
|
|
91
|
-
test-name
|
|
92
|
-
(TIMINGS)
|
|
93
|
-
|
|
94
|
-
test-name.test-sub-domain.workers.dev"
|
|
95
|
-
`);
|
|
96
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
97
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should only upload files that are not already in the KV namespace", async () => {
|
|
101
|
-
const assets = [
|
|
102
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
103
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
104
|
-
];
|
|
105
|
-
const kvNamespace = {
|
|
106
|
-
title: "__test-name_sites_assets",
|
|
107
|
-
id: "__test-name_sites_assets-id",
|
|
108
|
-
};
|
|
109
|
-
writeWranglerToml("./index.js", "assets");
|
|
110
|
-
writeEsmWorkerSource();
|
|
111
|
-
writeAssets(assets);
|
|
112
|
-
mockUploadWorkerRequest();
|
|
113
|
-
mockSubDomainRequest();
|
|
114
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
115
|
-
// Put file-1 in the KV namespace
|
|
116
|
-
mockKeyListRequest(kvNamespace.id, ["assets/file-1.2ca234f380.txt"]);
|
|
117
|
-
// Check we do not upload file-1
|
|
118
|
-
mockUploadAssetsToKVRequest(
|
|
119
|
-
kvNamespace.id,
|
|
120
|
-
assets.filter((a) => a.filePath !== "assets/file-1.txt")
|
|
121
|
-
);
|
|
122
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
123
|
-
|
|
124
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
125
|
-
"reading assets/file-1.txt...
|
|
126
|
-
skipping - already uploaded
|
|
127
|
-
reading assets/file-2.txt...
|
|
128
|
-
uploading as assets/file-2.5938485188.txt...
|
|
129
|
-
Uploaded
|
|
130
|
-
test-name
|
|
131
|
-
(TIMINGS)
|
|
132
|
-
Deployed
|
|
133
|
-
test-name
|
|
134
|
-
(TIMINGS)
|
|
135
|
-
|
|
136
|
-
test-name.test-sub-domain.workers.dev"
|
|
137
|
-
`);
|
|
138
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
139
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should only upload files that match the `site-include` arg", async () => {
|
|
143
|
-
const assets = [
|
|
144
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
145
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
146
|
-
];
|
|
147
|
-
const kvNamespace = {
|
|
148
|
-
title: "__test-name_sites_assets",
|
|
149
|
-
id: "__test-name_sites_assets-id",
|
|
150
|
-
};
|
|
151
|
-
writeWranglerToml("./index.js", "assets");
|
|
152
|
-
writeEsmWorkerSource();
|
|
153
|
-
writeAssets(assets);
|
|
154
|
-
mockUploadWorkerRequest();
|
|
155
|
-
mockSubDomainRequest();
|
|
156
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
157
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
158
|
-
// Check we only upload file-1
|
|
159
|
-
mockUploadAssetsToKVRequest(
|
|
160
|
-
kvNamespace.id,
|
|
161
|
-
assets.filter((a) => a.filePath === "assets/file-1.txt")
|
|
162
|
-
);
|
|
163
|
-
const { stdout, stderr, error } = await runWrangler(
|
|
164
|
-
"publish --site-include file-1.txt"
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
168
|
-
"reading assets/file-1.txt...
|
|
169
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
170
|
-
Uploaded
|
|
171
|
-
test-name
|
|
172
|
-
(TIMINGS)
|
|
173
|
-
Deployed
|
|
174
|
-
test-name
|
|
175
|
-
(TIMINGS)
|
|
176
|
-
|
|
177
|
-
test-name.test-sub-domain.workers.dev"
|
|
178
|
-
`);
|
|
179
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
180
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("should not upload files that match the `site-exclude` arg", async () => {
|
|
184
|
-
const assets = [
|
|
185
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
186
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
187
|
-
];
|
|
188
|
-
const kvNamespace = {
|
|
189
|
-
title: "__test-name_sites_assets",
|
|
190
|
-
id: "__test-name_sites_assets-id",
|
|
191
|
-
};
|
|
192
|
-
writeWranglerToml("./index.js", "assets");
|
|
193
|
-
writeEsmWorkerSource();
|
|
194
|
-
writeAssets(assets);
|
|
195
|
-
mockUploadWorkerRequest();
|
|
196
|
-
mockSubDomainRequest();
|
|
197
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
198
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
199
|
-
// Check we only upload file-1
|
|
200
|
-
mockUploadAssetsToKVRequest(
|
|
201
|
-
kvNamespace.id,
|
|
202
|
-
assets.filter((a) => a.filePath === "assets/file-1.txt")
|
|
203
|
-
);
|
|
204
|
-
const { stdout, stderr, error } = await runWrangler(
|
|
205
|
-
"publish --site-exclude file-2.txt"
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
209
|
-
"reading assets/file-1.txt...
|
|
210
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
211
|
-
Uploaded
|
|
212
|
-
test-name
|
|
213
|
-
(TIMINGS)
|
|
214
|
-
Deployed
|
|
215
|
-
test-name
|
|
216
|
-
(TIMINGS)
|
|
217
|
-
|
|
218
|
-
test-name.test-sub-domain.workers.dev"
|
|
219
|
-
`);
|
|
220
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
221
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("should only upload files that match the `site.include` config", async () => {
|
|
225
|
-
const assets = [
|
|
226
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
227
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
228
|
-
];
|
|
229
|
-
const kvNamespace = {
|
|
230
|
-
title: "__test-name_sites_assets",
|
|
231
|
-
id: "__test-name_sites_assets-id",
|
|
232
|
-
};
|
|
233
|
-
writeWranglerToml("./index.js", "assets", ["file-1.txt"]);
|
|
234
|
-
writeEsmWorkerSource();
|
|
235
|
-
writeAssets(assets);
|
|
236
|
-
mockUploadWorkerRequest();
|
|
237
|
-
mockSubDomainRequest();
|
|
238
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
239
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
240
|
-
// Check we only upload file-1
|
|
241
|
-
mockUploadAssetsToKVRequest(
|
|
242
|
-
kvNamespace.id,
|
|
243
|
-
assets.filter((a) => a.filePath === "assets/file-1.txt")
|
|
244
|
-
);
|
|
245
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
246
|
-
|
|
247
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
248
|
-
"reading assets/file-1.txt...
|
|
249
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
250
|
-
Uploaded
|
|
251
|
-
test-name
|
|
252
|
-
(TIMINGS)
|
|
253
|
-
Deployed
|
|
254
|
-
test-name
|
|
255
|
-
(TIMINGS)
|
|
256
|
-
|
|
257
|
-
test-name.test-sub-domain.workers.dev"
|
|
258
|
-
`);
|
|
259
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
260
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("should not upload files that match the `site.exclude` config", async () => {
|
|
264
|
-
const assets = [
|
|
265
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
266
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
267
|
-
];
|
|
268
|
-
const kvNamespace = {
|
|
269
|
-
title: "__test-name_sites_assets",
|
|
270
|
-
id: "__test-name_sites_assets-id",
|
|
271
|
-
};
|
|
272
|
-
writeWranglerToml("./index.js", "assets", undefined, ["file-2.txt"]);
|
|
273
|
-
writeEsmWorkerSource();
|
|
274
|
-
writeAssets(assets);
|
|
275
|
-
mockUploadWorkerRequest();
|
|
276
|
-
mockSubDomainRequest();
|
|
277
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
278
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
279
|
-
// Check we only upload file-1
|
|
280
|
-
mockUploadAssetsToKVRequest(
|
|
281
|
-
kvNamespace.id,
|
|
282
|
-
assets.filter((a) => a.filePath === "assets/file-1.txt")
|
|
283
|
-
);
|
|
284
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
285
|
-
|
|
286
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
287
|
-
"reading assets/file-1.txt...
|
|
288
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
289
|
-
Uploaded
|
|
290
|
-
test-name
|
|
291
|
-
(TIMINGS)
|
|
292
|
-
Deployed
|
|
293
|
-
test-name
|
|
294
|
-
(TIMINGS)
|
|
295
|
-
|
|
296
|
-
test-name.test-sub-domain.workers.dev"
|
|
297
|
-
`);
|
|
298
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
299
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("should use `site-include` arg over `site.include` config", async () => {
|
|
303
|
-
const assets = [
|
|
304
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
305
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
306
|
-
];
|
|
307
|
-
const kvNamespace = {
|
|
308
|
-
title: "__test-name_sites_assets",
|
|
309
|
-
id: "__test-name_sites_assets-id",
|
|
310
|
-
};
|
|
311
|
-
writeWranglerToml("./index.js", "assets", ["file-2.txt"]);
|
|
312
|
-
writeEsmWorkerSource();
|
|
313
|
-
writeAssets(assets);
|
|
314
|
-
mockUploadWorkerRequest();
|
|
315
|
-
mockSubDomainRequest();
|
|
316
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
317
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
318
|
-
// Check we only upload file-1
|
|
319
|
-
mockUploadAssetsToKVRequest(
|
|
320
|
-
kvNamespace.id,
|
|
321
|
-
assets.filter((a) => a.filePath === "assets/file-1.txt")
|
|
322
|
-
);
|
|
323
|
-
const { stdout, stderr, error } = await runWrangler(
|
|
324
|
-
"publish --site-include file-1.txt"
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
328
|
-
"reading assets/file-1.txt...
|
|
329
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
330
|
-
Uploaded
|
|
331
|
-
test-name
|
|
332
|
-
(TIMINGS)
|
|
333
|
-
Deployed
|
|
334
|
-
test-name
|
|
335
|
-
(TIMINGS)
|
|
336
|
-
|
|
337
|
-
test-name.test-sub-domain.workers.dev"
|
|
338
|
-
`);
|
|
339
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
340
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it("should use `site-exclude` arg over `site.exclude` config", async () => {
|
|
344
|
-
const assets = [
|
|
345
|
-
{ filePath: "assets/file-1.txt", content: "Content of file-1" },
|
|
346
|
-
{ filePath: "assets/file-2.txt", content: "Content of file-2" },
|
|
347
|
-
];
|
|
348
|
-
const kvNamespace = {
|
|
349
|
-
title: "__test-name_sites_assets",
|
|
350
|
-
id: "__test-name_sites_assets-id",
|
|
351
|
-
};
|
|
352
|
-
writeWranglerToml("./index.js", "assets", undefined, [
|
|
353
|
-
"assets/file-1.txt",
|
|
354
|
-
]);
|
|
355
|
-
writeEsmWorkerSource();
|
|
356
|
-
writeAssets(assets);
|
|
357
|
-
mockUploadWorkerRequest();
|
|
358
|
-
mockSubDomainRequest();
|
|
359
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
360
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
361
|
-
// Check we only upload file-1
|
|
362
|
-
mockUploadAssetsToKVRequest(
|
|
363
|
-
kvNamespace.id,
|
|
364
|
-
assets.filter((a) => a.filePath.endsWith("assets/file-1.txt"))
|
|
365
|
-
);
|
|
366
|
-
const { stdout, stderr, error } = await runWrangler(
|
|
367
|
-
"publish --site-exclude file-2.txt"
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
371
|
-
"reading assets/file-1.txt...
|
|
372
|
-
uploading as assets/file-1.2ca234f380.txt...
|
|
373
|
-
Uploaded
|
|
374
|
-
test-name
|
|
375
|
-
(TIMINGS)
|
|
376
|
-
Deployed
|
|
377
|
-
test-name
|
|
378
|
-
(TIMINGS)
|
|
379
|
-
|
|
380
|
-
test-name.test-sub-domain.workers.dev"
|
|
381
|
-
`);
|
|
382
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
383
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it("should walk directories except node_modules", async () => {
|
|
387
|
-
const assets = [
|
|
388
|
-
{
|
|
389
|
-
filePath: "assets/directory-1/file-1.txt",
|
|
390
|
-
content: "Content of file-1",
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
filePath: "assets/node_modules/file-2.txt",
|
|
394
|
-
content: "Content of file-2",
|
|
395
|
-
},
|
|
396
|
-
];
|
|
397
|
-
const kvNamespace = {
|
|
398
|
-
title: "__test-name_sites_assets",
|
|
399
|
-
id: "__test-name_sites_assets-id",
|
|
400
|
-
};
|
|
401
|
-
writeWranglerToml("./index.js", "assets");
|
|
402
|
-
writeEsmWorkerSource();
|
|
403
|
-
writeAssets(assets);
|
|
404
|
-
mockUploadWorkerRequest();
|
|
405
|
-
mockSubDomainRequest();
|
|
406
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
407
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
408
|
-
// Only expect file-1 to be uploaded
|
|
409
|
-
mockUploadAssetsToKVRequest(kvNamespace.id, assets.slice(0, 1));
|
|
410
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
411
|
-
|
|
412
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
413
|
-
"reading assets/directory-1/file-1.txt...
|
|
414
|
-
uploading as assets/directory-1/file-1.2ca234f380.txt...
|
|
415
|
-
Uploaded
|
|
416
|
-
test-name
|
|
417
|
-
(TIMINGS)
|
|
418
|
-
Deployed
|
|
419
|
-
test-name
|
|
420
|
-
(TIMINGS)
|
|
421
|
-
|
|
422
|
-
test-name.test-sub-domain.workers.dev"
|
|
423
|
-
`);
|
|
424
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
425
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it("should skip hidden files and directories except `.well-known`", async () => {
|
|
429
|
-
const assets = [
|
|
430
|
-
{
|
|
431
|
-
filePath: "assets/.hidden-file.txt",
|
|
432
|
-
content: "Content of hidden-file",
|
|
433
|
-
},
|
|
434
|
-
{
|
|
435
|
-
filePath: "assets/.hidden/file-1.txt",
|
|
436
|
-
content: "Content of file-1",
|
|
437
|
-
},
|
|
438
|
-
{
|
|
439
|
-
filePath: "assets/.well-known/file-2.txt",
|
|
440
|
-
content: "Content of file-2",
|
|
441
|
-
},
|
|
442
|
-
];
|
|
443
|
-
const kvNamespace = {
|
|
444
|
-
title: "__test-name_sites_assets",
|
|
445
|
-
id: "__test-name_sites_assets-id",
|
|
446
|
-
};
|
|
447
|
-
writeWranglerToml("./index.js", "assets");
|
|
448
|
-
writeEsmWorkerSource();
|
|
449
|
-
writeAssets(assets);
|
|
450
|
-
mockUploadWorkerRequest();
|
|
451
|
-
mockSubDomainRequest();
|
|
452
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
453
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
454
|
-
// Only expect file-2 to be uploaded
|
|
455
|
-
mockUploadAssetsToKVRequest(kvNamespace.id, assets.slice(2));
|
|
456
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
457
|
-
|
|
458
|
-
expect(stripTimings(stdout)).toMatchInlineSnapshot(`
|
|
459
|
-
"reading assets/.well-known/file-2.txt...
|
|
460
|
-
uploading as assets/.well-known/file-2.5938485188.txt...
|
|
461
|
-
Uploaded
|
|
462
|
-
test-name
|
|
463
|
-
(TIMINGS)
|
|
464
|
-
Deployed
|
|
465
|
-
test-name
|
|
466
|
-
(TIMINGS)
|
|
467
|
-
|
|
468
|
-
test-name.test-sub-domain.workers.dev"
|
|
469
|
-
`);
|
|
470
|
-
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
471
|
-
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
it("should error if the asset is over 25Mb", async () => {
|
|
475
|
-
const assets = [
|
|
476
|
-
{
|
|
477
|
-
filePath: "assets/large-file.txt",
|
|
478
|
-
// This file is greater than 25MiB when base64 encoded but small enough to be uploaded.
|
|
479
|
-
content: "X".repeat(25 * 1024 * 1024 * 0.8 + 1),
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
filePath: "assets/too-large-file.txt",
|
|
483
|
-
content: "X".repeat(25 * 1024 * 1024 + 1),
|
|
484
|
-
},
|
|
485
|
-
];
|
|
486
|
-
const kvNamespace = {
|
|
487
|
-
title: "__test-name_sites_assets",
|
|
488
|
-
id: "__test-name_sites_assets-id",
|
|
489
|
-
};
|
|
490
|
-
writeWranglerToml("./index.js", "assets", undefined, [
|
|
491
|
-
"assets/file-1.txt",
|
|
492
|
-
]);
|
|
493
|
-
writeEsmWorkerSource();
|
|
494
|
-
writeAssets(assets);
|
|
495
|
-
mockUploadWorkerRequest();
|
|
496
|
-
mockSubDomainRequest();
|
|
497
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
498
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
499
|
-
|
|
500
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
501
|
-
|
|
502
|
-
expect(stdout).toMatchInlineSnapshot(`
|
|
503
|
-
"reading assets/large-file.txt...
|
|
504
|
-
uploading as assets/large-file.0ea0637a45.txt..."
|
|
505
|
-
`);
|
|
506
|
-
expect(stderr).toMatchInlineSnapshot(`
|
|
507
|
-
"File assets/too-large-file.txt is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits
|
|
508
|
-
|
|
509
|
-
[32m%s[0m
|
|
510
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
511
|
-
`);
|
|
512
|
-
expect(error).toMatchInlineSnapshot(
|
|
513
|
-
`[Error: File assets/too-large-file.txt is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits]`
|
|
514
|
-
);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
it("should error if the asset key is over 512 characters", async () => {
|
|
518
|
-
const longFilePathAsset = {
|
|
519
|
-
filePath: "assets/" + "folder/".repeat(100) + "file.txt",
|
|
520
|
-
content: "content of file",
|
|
521
|
-
};
|
|
522
|
-
const kvNamespace = {
|
|
523
|
-
title: "__test-name_sites_assets",
|
|
524
|
-
id: "__test-name_sites_assets-id",
|
|
525
|
-
};
|
|
526
|
-
writeWranglerToml("./index.js", "assets");
|
|
527
|
-
writeEsmWorkerSource();
|
|
528
|
-
writeAssets([longFilePathAsset]);
|
|
529
|
-
mockUploadWorkerRequest();
|
|
530
|
-
mockSubDomainRequest();
|
|
531
|
-
mockListKVNamespacesRequest(kvNamespace);
|
|
532
|
-
mockKeyListRequest(kvNamespace.id, []);
|
|
533
|
-
|
|
534
|
-
const { stdout, stderr, error } = await runWrangler("publish");
|
|
535
|
-
|
|
536
|
-
expect(stdout).toMatchInlineSnapshot(
|
|
537
|
-
`"reading assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.txt..."`
|
|
538
|
-
);
|
|
539
|
-
expect(stderr).toMatchInlineSnapshot(`
|
|
540
|
-
"The asset path key \\"assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.3da0d0cd12.txt\\" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits\\",
|
|
541
|
-
|
|
542
|
-
[32m%s[0m
|
|
543
|
-
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
544
|
-
`);
|
|
545
|
-
expect(error).toMatchInlineSnapshot(
|
|
546
|
-
`[Error: The asset path key "assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.3da0d0cd12.txt" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits",]`
|
|
547
|
-
);
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
/** Write a mock wrangler.toml file to disk. */
|
|
553
|
-
function writeWranglerToml(
|
|
554
|
-
main?: string,
|
|
555
|
-
bucket?: string,
|
|
556
|
-
include?: string[],
|
|
557
|
-
exclude?: string[]
|
|
558
|
-
) {
|
|
559
|
-
fs.writeFileSync(
|
|
560
|
-
"./wrangler.toml",
|
|
561
|
-
[
|
|
562
|
-
`compatibility_date = "2022-01-12"`,
|
|
563
|
-
`name = "test-name"`,
|
|
564
|
-
main !== undefined ? `[build.upload]\nmain = "${main}"` : "",
|
|
565
|
-
bucket || include || exclude ? "[site]" : "",
|
|
566
|
-
bucket !== undefined ? `bucket = "${bucket}"` : "",
|
|
567
|
-
include !== undefined ? `include = ${JSON.stringify(include)}` : "",
|
|
568
|
-
exclude !== undefined ? `exclude = ${JSON.stringify(exclude)}` : "",
|
|
569
|
-
].join("\n"),
|
|
570
|
-
"utf-8"
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/** Write a mock Worker script to disk. */
|
|
575
|
-
function writeEsmWorkerSource() {
|
|
576
|
-
fs.writeFileSync(
|
|
577
|
-
"index.js",
|
|
578
|
-
[
|
|
579
|
-
`import { foo } from "./another";`,
|
|
580
|
-
`export default {`,
|
|
581
|
-
` async fetch(request) {`,
|
|
582
|
-
` return new Response('Hello' + foo);`,
|
|
583
|
-
` },`,
|
|
584
|
-
`};`,
|
|
585
|
-
].join("\n")
|
|
586
|
-
);
|
|
587
|
-
fs.writeFileSync("another.js", `export const foo = 100;`);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/** Write mock assets to the file system so they can be uploaded. */
|
|
591
|
-
function writeAssets(assets: { filePath: string; content: string }[]) {
|
|
592
|
-
for (const asset of assets) {
|
|
593
|
-
fs.mkdirSync(path.dirname(asset.filePath), { recursive: true });
|
|
594
|
-
fs.writeFileSync(asset.filePath, asset.content);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
/** Create a mock handler for the request to upload a worker script. */
|
|
599
|
-
function mockUploadWorkerRequest(available_on_subdomain = true) {
|
|
600
|
-
setMockResponse(
|
|
601
|
-
"/accounts/:accountId/workers/scripts/:scriptName",
|
|
602
|
-
"PUT",
|
|
603
|
-
([_url, accountId, scriptName], _init, queryParams) => {
|
|
604
|
-
expect(accountId).toEqual("some-account-id");
|
|
605
|
-
expect(scriptName).toEqual("test-name");
|
|
606
|
-
expect(queryParams.get("available_on_subdomains")).toEqual("true");
|
|
607
|
-
return { available_on_subdomain };
|
|
608
|
-
}
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/** Create a mock handler for the request to get the account's subdomain. */
|
|
613
|
-
function mockSubDomainRequest(subdomain = "test-sub-domain") {
|
|
614
|
-
setMockResponse("/accounts/:accountId/workers/subdomain", () => {
|
|
615
|
-
return { subdomain };
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
/** Create a mock handler for the request to get a list of all KV namespaces. */
|
|
620
|
-
function mockListKVNamespacesRequest(...namespaces: KVNamespaceInfo[]) {
|
|
621
|
-
setMockResponse(
|
|
622
|
-
"/accounts/:accountId/storage/kv/namespaces",
|
|
623
|
-
"GET",
|
|
624
|
-
([_url, accountId]) => {
|
|
625
|
-
expect(accountId).toEqual("some-account-id");
|
|
626
|
-
return namespaces;
|
|
627
|
-
}
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/** Create a mock handler for the request that tries to do a bulk upload of assets to a KV namespace. */
|
|
632
|
-
function mockUploadAssetsToKVRequest(
|
|
633
|
-
expectedNamespaceId: string,
|
|
634
|
-
assets: { filePath: string; content: string }[]
|
|
635
|
-
) {
|
|
636
|
-
setMockResponse(
|
|
637
|
-
"/accounts/:accountId/storage/kv/namespaces/:namespaceId/bulk",
|
|
638
|
-
"PUT",
|
|
639
|
-
([_url, accountId, namespaceId], { body }) => {
|
|
640
|
-
expect(accountId).toEqual("some-account-id");
|
|
641
|
-
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
642
|
-
const uploads = JSON.parse(body as string);
|
|
643
|
-
expect(assets.length).toEqual(uploads.length);
|
|
644
|
-
for (let i = 0; i < uploads.length; i++) {
|
|
645
|
-
const asset = assets[i];
|
|
646
|
-
const upload = uploads[i];
|
|
647
|
-
// The asset key consists of:
|
|
648
|
-
// - the basename of the filepath
|
|
649
|
-
// - some hash value
|
|
650
|
-
// - the extension
|
|
651
|
-
const keyMatcher = new RegExp(
|
|
652
|
-
"^" +
|
|
653
|
-
asset.filePath
|
|
654
|
-
.replace(/(\.[^.]+)$/, ".[a-z0-9]+$1")
|
|
655
|
-
.replace(/\./g, "\\.")
|
|
656
|
-
);
|
|
657
|
-
expect(upload.key).toMatch(keyMatcher);
|
|
658
|
-
// The asset value is base64 encoded.
|
|
659
|
-
expect(upload.base64).toBe(true);
|
|
660
|
-
expect(Buffer.from(upload.value, "base64").toString()).toEqual(
|
|
661
|
-
asset.content
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
return null;
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/** Strip timing data out of the stdout, since this is not always deterministic. */
|
|
670
|
-
function stripTimings(stdout: string): string {
|
|
671
|
-
return stdout.replace(/\(\d+\.\d+ sec\)/g, "(TIMINGS)");
|
|
672
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as os from "node:os";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
|
|
5
|
-
const originalCwd = process.cwd();
|
|
6
|
-
|
|
7
|
-
export function runInTempDir() {
|
|
8
|
-
let tmpDir: string;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
|
|
12
|
-
process.chdir(tmpDir);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
process.chdir(originalCwd);
|
|
17
|
-
fs.rmSync(tmpDir, { recursive: true });
|
|
18
|
-
});
|
|
19
|
-
}
|