Skip to content

Commit

Permalink
Add warning for smart placement
Browse files Browse the repository at this point in the history
  • Loading branch information
WillTaylorDev committed Dec 18, 2024
1 parent c826454 commit b4df55e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,47 @@ addEventListener('fetch', event => {});`
`);
});

it("should warn when using smart placement with Worker first", async () => {
const assets = [
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
{ filePath: "file-1.txt", content: "Content of file-1" },
{ filePath: "file-2.bak", content: "Content of file-2" },
{ filePath: "file-3.txt", content: "Content of file-3" },
{ filePath: "sub-dir/file-4.bak", content: "Content of file-4" },
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
];
writeAssets(assets, "assets");
writeWranglerConfig({
assets: {
directory: "assets",
experimental_serve_directly: false,
},
placement: {
mode: "smart",
},
});
const bodies: AssetManifest[] = [];
await mockAUSRequest(bodies);
mockSubDomainRequest();
mockUploadWorkerRequest({
expectedAssets: {
jwt: "<<aus-completion-token>>",
config: {
serve_directly: true,
},
},
expectedType: "none",
});

await runWrangler("deploy");

expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] Using assets with smart placement enabled may result in poor performance.
"
`);
});

it("should warn if experimental_serve_directly=false but no binding is provided", async () => {
const assets = [
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
Expand Down
10 changes: 10 additions & 0 deletions packages/wrangler/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ export function validateAssetsArgsAndConfig(
);
}

// Smart placement turned on when using assets
if (
config?.placement?.mode === "smart" &&
config?.assets?.experimental_serve_directly === false
) {
logger.warn(
"Using assets with smart placement enabled may result in poor performance."
);
}

// User Worker ahead of assets, but no assets binding provided
if (
"legacy" in args
Expand Down

0 comments on commit b4df55e

Please sign in to comment.