Skip to content

Commit 529b021

Browse files
committed
Add warning for smart placement
1 parent e224fc2 commit 529b021

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4446,6 +4446,47 @@ addEventListener('fetch', event => {});`
44464446
`);
44474447
});
44484448

4449+
it("should warn when using smart placement with Worker first", async () => {
4450+
const assets = [
4451+
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
4452+
{ filePath: "file-1.txt", content: "Content of file-1" },
4453+
{ filePath: "file-2.bak", content: "Content of file-2" },
4454+
{ filePath: "file-3.txt", content: "Content of file-3" },
4455+
{ filePath: "sub-dir/file-4.bak", content: "Content of file-4" },
4456+
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
4457+
];
4458+
writeAssets(assets, "assets");
4459+
writeWranglerConfig({
4460+
assets: {
4461+
directory: "assets",
4462+
experimental_serve_directly: false,
4463+
},
4464+
placement: {
4465+
mode: "smart",
4466+
},
4467+
});
4468+
const bodies: AssetManifest[] = [];
4469+
await mockAUSRequest(bodies);
4470+
mockSubDomainRequest();
4471+
mockUploadWorkerRequest({
4472+
expectedAssets: {
4473+
jwt: "<<aus-completion-token>>",
4474+
config: {
4475+
serve_directly: true,
4476+
},
4477+
},
4478+
expectedType: "none",
4479+
});
4480+
4481+
await runWrangler("deploy");
4482+
4483+
expect(std.warn).toMatchInlineSnapshot(`
4484+
"▲ [WARNING] Using assets with smart placement enabled may result in poor performance.
4485+
4486+
"
4487+
`);
4488+
});
4489+
44494490
it("should warn if experimental_serve_directly=false but no binding is provided", async () => {
44504491
const assets = [
44514492
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },

packages/wrangler/src/assets.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,16 @@ export function validateAssetsArgsAndConfig(
444444
);
445445
}
446446

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

0 commit comments

Comments
 (0)