wrangler 2.9.1 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/miniflare-dist/index.mjs +1 -1
- package/package.json +8 -8
- package/src/__tests__/configuration.test.ts +70 -0
- package/src/__tests__/d1/d1.test.ts +2 -2
- package/src/__tests__/d1/execute.test.ts +64 -0
- package/src/__tests__/d1/migrate.test.ts +14 -0
- package/src/__tests__/deployments.test.ts +40 -16
- package/src/__tests__/dev.test.tsx +3 -3
- package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/index.test.ts +2 -0
- package/src/__tests__/kv.test.ts +8 -8
- package/src/__tests__/middleware.test.ts +65 -0
- package/src/__tests__/mtls-certificates.test.ts +585 -0
- package/src/__tests__/pages/functions-build.test.ts +402 -0
- package/src/__tests__/pages/pages.test.ts +7 -7
- package/src/__tests__/pages/publish.test.ts +525 -1
- package/src/__tests__/publish.test.ts +58 -27
- package/src/__tests__/queues.test.ts +2 -2
- package/src/__tests__/secret.test.ts +4 -4
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +1 -1
- package/src/__tests__/whoami.test.tsx +1 -1
- package/src/api/index.ts +8 -0
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +75 -0
- package/src/api/pages/publish.tsx +52 -8
- package/src/bundle.ts +6 -5
- package/src/config/config.ts +7 -7
- package/src/config/environment.ts +9 -2
- package/src/config/index.ts +13 -0
- package/src/config/validation.ts +50 -3
- package/src/create-worker-upload-form.ts +9 -0
- package/src/d1/execute.tsx +123 -90
- package/src/d1/migrations/apply.tsx +29 -24
- package/src/d1/migrations/create.tsx +7 -7
- package/src/d1/migrations/helpers.ts +63 -38
- package/src/d1/migrations/list.tsx +19 -16
- package/src/d1/migrations/options.ts +6 -1
- package/src/d1/types.ts +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/deployments.ts +62 -39
- package/src/dev/dev.tsx +1 -15
- package/src/dev/remote.tsx +2 -2
- package/src/dev.tsx +9 -6
- package/src/generate/index.ts +1 -1
- package/src/index.ts +15 -5
- package/src/miniflare-cli/assets.ts +1 -1
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +103 -23
- package/src/pages/buildFunctions.ts +32 -31
- package/src/pages/dev.ts +4 -2
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/publish.tsx +12 -1
- package/src/pages/utils.ts +1 -1
- package/src/publish/publish.ts +3 -2
- package/src/secret/index.ts +1 -0
- package/src/sites.ts +1 -1
- package/src/tail/filters.ts +1 -1
- package/src/user/user.ts +4 -3
- package/src/worker.ts +6 -0
- package/templates/format-dev-errors.ts +1 -0
- package/templates/new-worker.ts +3 -0
- package/templates/serve-static-assets.ts +1 -0
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +82 -2
- package/wrangler-dist/cli.js +1501 -1031
|
@@ -71,7 +71,7 @@ describe("deployment create", () => {
|
|
|
71
71
|
--skip-caching Skip asset caching which speeds up builds [boolean]
|
|
72
72
|
--no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: true]
|
|
73
73
|
|
|
74
|
-
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/
|
|
74
|
+
🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose"
|
|
75
75
|
`);
|
|
76
76
|
});
|
|
77
77
|
|
|
@@ -2178,6 +2178,530 @@ and that at least one include rule is provided.
|
|
|
2178
2178
|
|
|
2179
2179
|
expect(std.err).toMatchInlineSnapshot('""');
|
|
2180
2180
|
});
|
|
2181
|
+
|
|
2182
|
+
it("should bundle Functions and resolve its external module imports if the `--experimental-worker-bundle` flag is set", async () => {
|
|
2183
|
+
// set up the directory of static files to upload.
|
|
2184
|
+
mkdirSync("public");
|
|
2185
|
+
writeFileSync("public/README.md", "This is a readme");
|
|
2186
|
+
|
|
2187
|
+
// set up hello.wasm
|
|
2188
|
+
mkdirSync("wasm");
|
|
2189
|
+
writeFileSync("wasm/hello.wasm", "HELLO WORLD");
|
|
2190
|
+
|
|
2191
|
+
// set up Functions
|
|
2192
|
+
mkdirSync("functions");
|
|
2193
|
+
writeFileSync(
|
|
2194
|
+
"functions/hello.js",
|
|
2195
|
+
`
|
|
2196
|
+
import hello from "./../wasm/hello.wasm";
|
|
2197
|
+
export async function onRequest() {
|
|
2198
|
+
const helloModule = await WebAssembly.instantiate(hello);
|
|
2199
|
+
const greeting = helloModule.exports.hello;
|
|
2200
|
+
return new Response(greeting);
|
|
2201
|
+
}
|
|
2202
|
+
`
|
|
2203
|
+
);
|
|
2204
|
+
|
|
2205
|
+
mockGetUploadTokenRequest(
|
|
2206
|
+
"<<funfetti-auth-jwt>>",
|
|
2207
|
+
"some-account-id",
|
|
2208
|
+
"foo"
|
|
2209
|
+
);
|
|
2210
|
+
|
|
2211
|
+
msw.use(
|
|
2212
|
+
// /pages/assets/check-missing
|
|
2213
|
+
rest.post("*/pages/assets/check-missing", async (req, res, ctx) => {
|
|
2214
|
+
const body = (await req.json()) as {
|
|
2215
|
+
hashes: string[];
|
|
2216
|
+
};
|
|
2217
|
+
|
|
2218
|
+
expect(req.headers.get("Authorization")).toBe(
|
|
2219
|
+
"Bearer <<funfetti-auth-jwt>>"
|
|
2220
|
+
);
|
|
2221
|
+
expect(body).toMatchObject({
|
|
2222
|
+
hashes: ["13a03eaf24ae98378acd36ea00f77f2f"],
|
|
2223
|
+
});
|
|
2224
|
+
|
|
2225
|
+
return res.once(
|
|
2226
|
+
ctx.status(200),
|
|
2227
|
+
ctx.json({
|
|
2228
|
+
success: true,
|
|
2229
|
+
errors: [],
|
|
2230
|
+
messages: [],
|
|
2231
|
+
result: body.hashes,
|
|
2232
|
+
})
|
|
2233
|
+
);
|
|
2234
|
+
}),
|
|
2235
|
+
|
|
2236
|
+
// /pages/assets/upload
|
|
2237
|
+
rest.post("*/pages/assets/upload", async (req, res, ctx) => {
|
|
2238
|
+
expect(req.headers.get("Authorization")).toBe(
|
|
2239
|
+
"Bearer <<funfetti-auth-jwt>>"
|
|
2240
|
+
);
|
|
2241
|
+
|
|
2242
|
+
expect(await req.json()).toMatchObject([
|
|
2243
|
+
{
|
|
2244
|
+
key: "13a03eaf24ae98378acd36ea00f77f2f",
|
|
2245
|
+
value: Buffer.from("This is a readme").toString("base64"),
|
|
2246
|
+
metadata: {
|
|
2247
|
+
contentType: "text/markdown",
|
|
2248
|
+
},
|
|
2249
|
+
base64: true,
|
|
2250
|
+
},
|
|
2251
|
+
]);
|
|
2252
|
+
|
|
2253
|
+
return res.once(
|
|
2254
|
+
ctx.status(200),
|
|
2255
|
+
ctx.json({
|
|
2256
|
+
success: true,
|
|
2257
|
+
errors: [],
|
|
2258
|
+
messages: [],
|
|
2259
|
+
result: null,
|
|
2260
|
+
})
|
|
2261
|
+
);
|
|
2262
|
+
}),
|
|
2263
|
+
|
|
2264
|
+
// /accounts/:accountId/pages/projects/<project-name>/deployments
|
|
2265
|
+
rest.post(
|
|
2266
|
+
"*/accounts/:accountId/pages/projects/foo/deployments",
|
|
2267
|
+
async (req, res, ctx) => {
|
|
2268
|
+
const body = await (req as RestRequestWithFormData).formData();
|
|
2269
|
+
const manifest = JSON.parse(body.get("manifest") as string);
|
|
2270
|
+
const workerBundle = body.get("_worker.bundle") as string;
|
|
2271
|
+
|
|
2272
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
2273
|
+
// make sure this is all we uploaded
|
|
2274
|
+
expect([...body.keys()].sort()).toEqual(
|
|
2275
|
+
[
|
|
2276
|
+
"manifest",
|
|
2277
|
+
"_worker.bundle",
|
|
2278
|
+
"functions-filepath-routing-config.json",
|
|
2279
|
+
"_routes.json",
|
|
2280
|
+
].sort()
|
|
2281
|
+
);
|
|
2282
|
+
expect(manifest).toMatchInlineSnapshot(`
|
|
2283
|
+
Object {
|
|
2284
|
+
"/README.md": "13a03eaf24ae98378acd36ea00f77f2f",
|
|
2285
|
+
}
|
|
2286
|
+
`);
|
|
2287
|
+
|
|
2288
|
+
// some fields in workerBundle, such as the undici form boundary
|
|
2289
|
+
// or the file hashes, are randomly generated. Let's replace these
|
|
2290
|
+
// dynamic values with static ones so we can properly test the
|
|
2291
|
+
// contents of `workerBundle`
|
|
2292
|
+
// see https://jestjs.io/docs/snapshot-testing#property-matchers
|
|
2293
|
+
let workerBundleWithConstantData = workerBundle.replace(
|
|
2294
|
+
/------formdata-undici-0.[0-9]*/g,
|
|
2295
|
+
"------formdata-undici-0.test"
|
|
2296
|
+
);
|
|
2297
|
+
workerBundleWithConstantData = workerBundleWithConstantData.replace(
|
|
2298
|
+
/functionsWorker-0.[0-9]*.js/g,
|
|
2299
|
+
"functionsWorker-0.test.js"
|
|
2300
|
+
);
|
|
2301
|
+
workerBundleWithConstantData = workerBundleWithConstantData.replace(
|
|
2302
|
+
/[0-9a-z]*-hello.wasm/g,
|
|
2303
|
+
"test-hello.wasm"
|
|
2304
|
+
);
|
|
2305
|
+
|
|
2306
|
+
// check we appended the metadata
|
|
2307
|
+
expect(workerBundleWithConstantData).toContain(
|
|
2308
|
+
`Content-Disposition: form-data; name="metadata"`
|
|
2309
|
+
);
|
|
2310
|
+
expect(workerBundleWithConstantData).toContain(
|
|
2311
|
+
`{"main_module":"functionsWorker-0.test.js"}`
|
|
2312
|
+
);
|
|
2313
|
+
|
|
2314
|
+
// check we appended the compiled Worker
|
|
2315
|
+
expect(workerBundleWithConstantData).toContain(
|
|
2316
|
+
`Content-Disposition: form-data; name="functionsWorker-0.test.js"; filename="functionsWorker-0.test.js"`
|
|
2317
|
+
);
|
|
2318
|
+
expect(workerBundleWithConstantData).toContain(`
|
|
2319
|
+
import hello from "./test-hello.wasm";
|
|
2320
|
+
async function onRequest() {
|
|
2321
|
+
const helloModule = await WebAssembly.instantiate(hello);
|
|
2322
|
+
const greeting = helloModule.exports.hello;
|
|
2323
|
+
return new Response(greeting);
|
|
2324
|
+
}`);
|
|
2325
|
+
|
|
2326
|
+
// check we appended the wasm module
|
|
2327
|
+
expect(workerBundleWithConstantData).toContain(
|
|
2328
|
+
`Content-Disposition: form-data; name="./test-hello.wasm"; filename="./test-hello.wasm"`
|
|
2329
|
+
);
|
|
2330
|
+
expect(workerBundleWithConstantData).toContain(`HELLO WORLD`);
|
|
2331
|
+
|
|
2332
|
+
return res.once(
|
|
2333
|
+
ctx.status(200),
|
|
2334
|
+
ctx.json({
|
|
2335
|
+
success: true,
|
|
2336
|
+
errors: [],
|
|
2337
|
+
messages: [],
|
|
2338
|
+
result: {
|
|
2339
|
+
url: "https://abcxyz.foo.pages.dev/",
|
|
2340
|
+
},
|
|
2341
|
+
})
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
),
|
|
2345
|
+
|
|
2346
|
+
// /accounts/:accountId/pages/projects/<project-name>
|
|
2347
|
+
rest.get(
|
|
2348
|
+
"*/accounts/:accountId/pages/projects/foo",
|
|
2349
|
+
async (req, res, ctx) => {
|
|
2350
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
2351
|
+
|
|
2352
|
+
return res.once(
|
|
2353
|
+
ctx.status(200),
|
|
2354
|
+
ctx.json({
|
|
2355
|
+
success: true,
|
|
2356
|
+
errors: [],
|
|
2357
|
+
messages: [],
|
|
2358
|
+
result: {
|
|
2359
|
+
deployment_configs: { production: {}, preview: {} },
|
|
2360
|
+
},
|
|
2361
|
+
})
|
|
2362
|
+
);
|
|
2363
|
+
}
|
|
2364
|
+
)
|
|
2365
|
+
);
|
|
2366
|
+
|
|
2367
|
+
await runWrangler(
|
|
2368
|
+
"pages publish public --project-name=foo --experimental-worker-bundle=true"
|
|
2369
|
+
);
|
|
2370
|
+
|
|
2371
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
2372
|
+
"✨ Compiled Worker successfully
|
|
2373
|
+
✨ Success! Uploaded 1 files (TIMINGS)
|
|
2374
|
+
|
|
2375
|
+
✨ Uploading Functions bundle
|
|
2376
|
+
✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
|
|
2377
|
+
`);
|
|
2378
|
+
|
|
2379
|
+
// make sure there were no errors
|
|
2380
|
+
expect(std.err).toMatchInlineSnapshot('""');
|
|
2381
|
+
});
|
|
2382
|
+
|
|
2383
|
+
it("should bundle _worker.js and resolve its external module imports if the `--experimental-worker-bundle` flag is set", async () => {
|
|
2384
|
+
// set up the directory of static files to upload
|
|
2385
|
+
mkdirSync("public");
|
|
2386
|
+
writeFileSync("public/README.md", "This is a readme");
|
|
2387
|
+
|
|
2388
|
+
// set up hello.wasm
|
|
2389
|
+
mkdirSync("wasm");
|
|
2390
|
+
writeFileSync("wasm/hello.wasm", "HELLO");
|
|
2391
|
+
|
|
2392
|
+
// set up _worker.js
|
|
2393
|
+
writeFileSync(
|
|
2394
|
+
"public/_worker.js",
|
|
2395
|
+
`
|
|
2396
|
+
import hello from "./../wasm/hello.wasm";
|
|
2397
|
+
export default {
|
|
2398
|
+
async fetch(request, env) {
|
|
2399
|
+
const url = new URL(request.url);
|
|
2400
|
+
const helloModule = await WebAssembly.instantiate(hello);
|
|
2401
|
+
const greeting = helloModule.exports.hello;
|
|
2402
|
+
return url.pathname.startsWith('/hello') ? new Response(greeting) : env.ASSETS.fetch(request);
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
`
|
|
2406
|
+
);
|
|
2407
|
+
|
|
2408
|
+
mockGetUploadTokenRequest(
|
|
2409
|
+
"<<funfetti-auth-jwt>>",
|
|
2410
|
+
"some-account-id",
|
|
2411
|
+
"foo"
|
|
2412
|
+
);
|
|
2413
|
+
|
|
2414
|
+
msw.use(
|
|
2415
|
+
// /pages/assets/check-missing
|
|
2416
|
+
rest.post("*/pages/assets/check-missing", async (req, res, ctx) => {
|
|
2417
|
+
const body = (await req.json()) as {
|
|
2418
|
+
hashes: string[];
|
|
2419
|
+
};
|
|
2420
|
+
|
|
2421
|
+
expect(req.headers.get("Authorization")).toBe(
|
|
2422
|
+
"Bearer <<funfetti-auth-jwt>>"
|
|
2423
|
+
);
|
|
2424
|
+
expect(body).toMatchObject({
|
|
2425
|
+
hashes: ["13a03eaf24ae98378acd36ea00f77f2f"],
|
|
2426
|
+
});
|
|
2427
|
+
|
|
2428
|
+
return res.once(
|
|
2429
|
+
ctx.status(200),
|
|
2430
|
+
ctx.json({
|
|
2431
|
+
success: true,
|
|
2432
|
+
errors: [],
|
|
2433
|
+
messages: [],
|
|
2434
|
+
result: body.hashes,
|
|
2435
|
+
})
|
|
2436
|
+
);
|
|
2437
|
+
}),
|
|
2438
|
+
|
|
2439
|
+
// /pages/assets/upload
|
|
2440
|
+
rest.post("*/pages/assets/upload", async (req, res, ctx) => {
|
|
2441
|
+
expect(req.headers.get("Authorization")).toBe(
|
|
2442
|
+
"Bearer <<funfetti-auth-jwt>>"
|
|
2443
|
+
);
|
|
2444
|
+
|
|
2445
|
+
expect(await req.json()).toMatchObject([
|
|
2446
|
+
{
|
|
2447
|
+
key: "13a03eaf24ae98378acd36ea00f77f2f",
|
|
2448
|
+
value: Buffer.from("This is a readme").toString("base64"),
|
|
2449
|
+
metadata: {
|
|
2450
|
+
contentType: "text/markdown",
|
|
2451
|
+
},
|
|
2452
|
+
base64: true,
|
|
2453
|
+
},
|
|
2454
|
+
]);
|
|
2455
|
+
|
|
2456
|
+
return res.once(
|
|
2457
|
+
ctx.status(200),
|
|
2458
|
+
ctx.json({
|
|
2459
|
+
success: true,
|
|
2460
|
+
errors: [],
|
|
2461
|
+
messages: [],
|
|
2462
|
+
result: null,
|
|
2463
|
+
})
|
|
2464
|
+
);
|
|
2465
|
+
}),
|
|
2466
|
+
|
|
2467
|
+
// /accounts/:accountId/pages/projects/<project-name>/deployments
|
|
2468
|
+
rest.post(
|
|
2469
|
+
"*/accounts/:accountId/pages/projects/foo/deployments",
|
|
2470
|
+
async (req, res, ctx) => {
|
|
2471
|
+
const body = await (req as RestRequestWithFormData).formData();
|
|
2472
|
+
const manifest = JSON.parse(body.get("manifest") as string);
|
|
2473
|
+
const workerBundle = body.get("_worker.bundle") as string;
|
|
2474
|
+
|
|
2475
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
2476
|
+
// make sure this is all we uploaded
|
|
2477
|
+
expect([...body.keys()].sort()).toEqual(
|
|
2478
|
+
["manifest", "_worker.bundle"].sort()
|
|
2479
|
+
);
|
|
2480
|
+
expect(manifest).toMatchInlineSnapshot(`
|
|
2481
|
+
Object {
|
|
2482
|
+
"/README.md": "13a03eaf24ae98378acd36ea00f77f2f",
|
|
2483
|
+
}
|
|
2484
|
+
`);
|
|
2485
|
+
// some fields in workerBundle, such as the undici form boundary
|
|
2486
|
+
// or the file hashes, are randomly generated. Let's replace these
|
|
2487
|
+
// dynamic values with static ones so we can properly test the
|
|
2488
|
+
// contents of `workerBundle`
|
|
2489
|
+
// see https://jestjs.io/docs/snapshot-testing#property-matchers
|
|
2490
|
+
let workerBundleWithConstantData = workerBundle.replace(
|
|
2491
|
+
/------formdata-undici-0.[0-9]*/g,
|
|
2492
|
+
"------formdata-undici-0.test"
|
|
2493
|
+
);
|
|
2494
|
+
workerBundleWithConstantData = workerBundleWithConstantData.replace(
|
|
2495
|
+
/bundledWorker-0.[0-9]*.mjs/g,
|
|
2496
|
+
"bundledWorker-0.test.mjs"
|
|
2497
|
+
);
|
|
2498
|
+
workerBundleWithConstantData = workerBundleWithConstantData.replace(
|
|
2499
|
+
/[0-9a-z]*-hello.wasm/g,
|
|
2500
|
+
"test-hello.wasm"
|
|
2501
|
+
);
|
|
2502
|
+
|
|
2503
|
+
// we care about a couple of things here, like the presence of `metadata`,
|
|
2504
|
+
// `bundledWorker`, the wasm import, etc., and since `workerBundle` is
|
|
2505
|
+
// small enough, let's go ahead and snapshot test the whole thing
|
|
2506
|
+
expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
|
|
2507
|
+
"------formdata-undici-0.test
|
|
2508
|
+
Content-Disposition: form-data; name=\\"metadata\\"
|
|
2509
|
+
|
|
2510
|
+
{\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
|
|
2511
|
+
------formdata-undici-0.test
|
|
2512
|
+
Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
|
|
2513
|
+
Content-Type: application/javascript+module
|
|
2514
|
+
|
|
2515
|
+
// _worker.js
|
|
2516
|
+
import hello from \\"./test-hello.wasm\\";
|
|
2517
|
+
var worker_default = {
|
|
2518
|
+
async fetch(request, env) {
|
|
2519
|
+
const url = new URL(request.url);
|
|
2520
|
+
const helloModule = await WebAssembly.instantiate(hello);
|
|
2521
|
+
const greeting = helloModule.exports.hello;
|
|
2522
|
+
return url.pathname.startsWith(\\"/hello\\") ? new Response(greeting) : env.ASSETS.fetch(request);
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
export {
|
|
2526
|
+
worker_default as default
|
|
2527
|
+
};
|
|
2528
|
+
//# sourceMappingURL=bundledWorker-0.test.mjs.map
|
|
2529
|
+
|
|
2530
|
+
------formdata-undici-0.test
|
|
2531
|
+
Content-Disposition: form-data; name=\\"./test-hello.wasm\\"; filename=\\"./test-hello.wasm\\"
|
|
2532
|
+
Content-Type: application/wasm
|
|
2533
|
+
|
|
2534
|
+
HELLO
|
|
2535
|
+
------formdata-undici-0.test--"
|
|
2536
|
+
`);
|
|
2537
|
+
|
|
2538
|
+
return res.once(
|
|
2539
|
+
ctx.status(200),
|
|
2540
|
+
ctx.json({
|
|
2541
|
+
success: true,
|
|
2542
|
+
errors: [],
|
|
2543
|
+
messages: [],
|
|
2544
|
+
result: {
|
|
2545
|
+
url: "https://abcxyz.foo.pages.dev/",
|
|
2546
|
+
},
|
|
2547
|
+
})
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
),
|
|
2551
|
+
|
|
2552
|
+
// /accounts/:accountId/pages/projects/<project-name>
|
|
2553
|
+
rest.get(
|
|
2554
|
+
"*/accounts/:accountId/pages/projects/foo",
|
|
2555
|
+
async (req, res, ctx) => {
|
|
2556
|
+
expect(req.params.accountId).toEqual("some-account-id");
|
|
2557
|
+
|
|
2558
|
+
return res.once(
|
|
2559
|
+
ctx.status(200),
|
|
2560
|
+
ctx.json({
|
|
2561
|
+
success: true,
|
|
2562
|
+
errors: [],
|
|
2563
|
+
messages: [],
|
|
2564
|
+
result: {
|
|
2565
|
+
deployment_configs: { production: {}, preview: {} },
|
|
2566
|
+
},
|
|
2567
|
+
})
|
|
2568
|
+
);
|
|
2569
|
+
}
|
|
2570
|
+
)
|
|
2571
|
+
);
|
|
2572
|
+
|
|
2573
|
+
await runWrangler(
|
|
2574
|
+
"pages publish public --project-name=foo --experimental-worker-bundle=true"
|
|
2575
|
+
);
|
|
2576
|
+
|
|
2577
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
2578
|
+
"✨ Success! Uploaded 1 files (TIMINGS)
|
|
2579
|
+
|
|
2580
|
+
✨ Compiled Worker successfully
|
|
2581
|
+
✨ Uploading Worker bundle
|
|
2582
|
+
✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
|
|
2583
|
+
`);
|
|
2584
|
+
|
|
2585
|
+
// make sure there were no errors
|
|
2586
|
+
expect(std.err).toMatchInlineSnapshot('""');
|
|
2587
|
+
});
|
|
2588
|
+
|
|
2589
|
+
describe("_worker.js bundling", () => {
|
|
2590
|
+
beforeEach(() => {
|
|
2591
|
+
mkdirSync("public");
|
|
2592
|
+
writeFileSync(
|
|
2593
|
+
"public/_worker.js",
|
|
2594
|
+
`
|
|
2595
|
+
export default {
|
|
2596
|
+
async fetch(request, env) {
|
|
2597
|
+
return new Response('Ok');
|
|
2598
|
+
}
|
|
2599
|
+
};
|
|
2600
|
+
`
|
|
2601
|
+
);
|
|
2602
|
+
});
|
|
2603
|
+
|
|
2604
|
+
const workerIsBundled = (contents: string) =>
|
|
2605
|
+
contents.includes("worker_default as default");
|
|
2606
|
+
|
|
2607
|
+
const simulateServer = (
|
|
2608
|
+
generatedWorkerJsCheck: (workerJsContent: string) => void
|
|
2609
|
+
) => {
|
|
2610
|
+
mockGetUploadTokenRequest(
|
|
2611
|
+
"<<funfetti-auth-jwt>>",
|
|
2612
|
+
"some-account-id",
|
|
2613
|
+
"foo"
|
|
2614
|
+
);
|
|
2615
|
+
msw.use(
|
|
2616
|
+
rest.post("*/pages/assets/check-missing", async (req, res, ctx) =>
|
|
2617
|
+
res.once(
|
|
2618
|
+
ctx.status(200),
|
|
2619
|
+
ctx.json({
|
|
2620
|
+
success: true,
|
|
2621
|
+
errors: [],
|
|
2622
|
+
messages: [],
|
|
2623
|
+
result: (await req.json()).hashes,
|
|
2624
|
+
})
|
|
2625
|
+
)
|
|
2626
|
+
),
|
|
2627
|
+
rest.post("*/pages/assets/upload", async (_req, res, ctx) =>
|
|
2628
|
+
res.once(
|
|
2629
|
+
ctx.status(200),
|
|
2630
|
+
ctx.json({
|
|
2631
|
+
success: true,
|
|
2632
|
+
errors: [],
|
|
2633
|
+
messages: [],
|
|
2634
|
+
result: null,
|
|
2635
|
+
})
|
|
2636
|
+
)
|
|
2637
|
+
),
|
|
2638
|
+
rest.post(
|
|
2639
|
+
"*/accounts/:accountId/pages/projects/foo/deployments",
|
|
2640
|
+
async (req, res, ctx) => {
|
|
2641
|
+
const body = await (req as RestRequestWithFormData).formData();
|
|
2642
|
+
const generatedWorkerJS = body.get("_worker.js") as string;
|
|
2643
|
+
|
|
2644
|
+
generatedWorkerJsCheck(generatedWorkerJS);
|
|
2645
|
+
|
|
2646
|
+
return res.once(
|
|
2647
|
+
ctx.status(200),
|
|
2648
|
+
ctx.json({
|
|
2649
|
+
success: true,
|
|
2650
|
+
errors: [],
|
|
2651
|
+
messages: [],
|
|
2652
|
+
result: {
|
|
2653
|
+
url: "https://abcxyz.foo.pages.dev/",
|
|
2654
|
+
},
|
|
2655
|
+
})
|
|
2656
|
+
);
|
|
2657
|
+
}
|
|
2658
|
+
),
|
|
2659
|
+
rest.get(
|
|
2660
|
+
"*/accounts/:accountId/pages/projects/foo",
|
|
2661
|
+
async (_req, res, ctx) =>
|
|
2662
|
+
res.once(
|
|
2663
|
+
ctx.status(200),
|
|
2664
|
+
ctx.json({
|
|
2665
|
+
success: true,
|
|
2666
|
+
errors: [],
|
|
2667
|
+
messages: [],
|
|
2668
|
+
result: {
|
|
2669
|
+
deployment_configs: { production: {}, preview: {} },
|
|
2670
|
+
},
|
|
2671
|
+
})
|
|
2672
|
+
)
|
|
2673
|
+
)
|
|
2674
|
+
);
|
|
2675
|
+
};
|
|
2676
|
+
|
|
2677
|
+
it("should not bundle the _worker.js when both `--bundle` and `--no-bundle` are omitted", async () => {
|
|
2678
|
+
simulateServer((generatedWorkerJS) =>
|
|
2679
|
+
expect(workerIsBundled(generatedWorkerJS)).toBeFalsy()
|
|
2680
|
+
);
|
|
2681
|
+
await runWrangler("pages publish public --project-name=foo");
|
|
2682
|
+
expect(std.out).toContain("✨ Uploading _worker.js");
|
|
2683
|
+
});
|
|
2684
|
+
|
|
2685
|
+
it("should bundle the _worker.js when the `--no-bundle` is set to false", async () => {
|
|
2686
|
+
simulateServer((generatedWorkerJS) =>
|
|
2687
|
+
expect(workerIsBundled(generatedWorkerJS)).toBeTruthy()
|
|
2688
|
+
);
|
|
2689
|
+
await runWrangler(
|
|
2690
|
+
"pages publish public --no-bundle=false --project-name=foo"
|
|
2691
|
+
);
|
|
2692
|
+
expect(std.out).toContain("✨ Uploading _worker.js");
|
|
2693
|
+
});
|
|
2694
|
+
|
|
2695
|
+
it("should bundle the _worker.js when the `--bundle` is set to true", async () => {
|
|
2696
|
+
simulateServer((generatedWorkerJS) =>
|
|
2697
|
+
expect(workerIsBundled(generatedWorkerJS)).toBeTruthy()
|
|
2698
|
+
);
|
|
2699
|
+
await runWrangler(
|
|
2700
|
+
"pages publish public --bundle=true --project-name=foo"
|
|
2701
|
+
);
|
|
2702
|
+
expect(std.out).toContain("✨ Uploading _worker.js");
|
|
2703
|
+
});
|
|
2704
|
+
});
|
|
2181
2705
|
});
|
|
2182
2706
|
|
|
2183
2707
|
function mockFormDataToString(this: FormData) {
|