Skip to content

Commit 31be8e9

Browse files
WillTaylorDevCarmenPopoviciu
authored andcommitted
Provide validation around experimental_serve_directly usage in dev and deploy
1 parent 8757579 commit 31be8e9

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,88 @@ addEventListener('fetch', event => {});`
46874687
`);
46884688
});
46894689

4690+
it("should warn when using smart placement with assets-first", async () => {
4691+
const assets = [
4692+
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
4693+
{ filePath: "file-1.txt", content: "Content of file-1" },
4694+
{ filePath: "file-2.bak", content: "Content of file-2" },
4695+
{ filePath: "file-3.txt", content: "Content of file-3" },
4696+
{ filePath: "sub-dir/file-4.bak", content: "Content of file-4" },
4697+
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
4698+
];
4699+
writeAssets(assets, "assets");
4700+
writeWranglerConfig({
4701+
assets: {
4702+
directory: "assets",
4703+
experimental_serve_directly: true,
4704+
},
4705+
placement: {
4706+
mode: "smart",
4707+
},
4708+
});
4709+
const bodies: AssetManifest[] = [];
4710+
await mockAUSRequest(bodies);
4711+
mockSubDomainRequest();
4712+
mockUploadWorkerRequest({
4713+
expectedAssets: {
4714+
jwt: "<<aus-completion-token>>",
4715+
config: {
4716+
serve_directly: true,
4717+
},
4718+
},
4719+
expectedType: "none",
4720+
});
4721+
4722+
await runWrangler("deploy");
4723+
4724+
expect(std.warn).toMatchInlineSnapshot(`
4725+
"▲ [WARNING] Using assets with smart placement turned on may result in poor performance.
4726+
4727+
"
4728+
`);
4729+
});
4730+
4731+
it("should warn when using smart placement with assets-first", async () => {
4732+
const assets = [
4733+
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
4734+
{ filePath: "file-1.txt", content: "Content of file-1" },
4735+
{ filePath: "file-2.bak", content: "Content of file-2" },
4736+
{ filePath: "file-3.txt", content: "Content of file-3" },
4737+
{ filePath: "sub-dir/file-4.bak", content: "Content of file-4" },
4738+
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
4739+
];
4740+
writeAssets(assets, "assets");
4741+
writeWranglerConfig({
4742+
assets: {
4743+
directory: "assets",
4744+
experimental_serve_directly: true,
4745+
},
4746+
placement: {
4747+
mode: "smart",
4748+
},
4749+
});
4750+
const bodies: AssetManifest[] = [];
4751+
await mockAUSRequest(bodies);
4752+
mockSubDomainRequest();
4753+
mockUploadWorkerRequest({
4754+
expectedAssets: {
4755+
jwt: "<<aus-completion-token>>",
4756+
config: {
4757+
serve_directly: true,
4758+
},
4759+
},
4760+
expectedType: "none",
4761+
});
4762+
4763+
await runWrangler("deploy");
4764+
4765+
expect(std.warn).toMatchInlineSnapshot(`
4766+
"▲ [WARNING] Using assets with smart placement turned on may result in poor performance.
4767+
4768+
"
4769+
`);
4770+
});
4771+
46904772
it("should warn if experimental_serve_directly=false but no binding is provided", async () => {
46914773
const assets = [
46924774
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },

packages/wrangler/src/assets.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,17 @@ export function validateAssetsArgsAndConfig(
444444
);
445445
}
446446

447-
// User Worker ahead of assets, but no assets binding provided
447+
// Smart placement turned on when using assets
448+
if (
449+
config?.placement?.mode === "smart" &&
450+
config?.assets?.experimental_serve_directly
451+
) {
452+
logger.warn(
453+
"Using assets with smart placement turned on may result in poor performance."
454+
);
455+
}
456+
457+
// User worker ahead of assets, but no assets binding provided
448458
if (
449459
"legacy" in args
450460
? args.assets?.assetConfig?.serve_directly === false &&

0 commit comments

Comments
 (0)