diff --git a/.changeset/odd-trains-bake.md b/.changeset/odd-trains-bake.md new file mode 100644 index 000000000000..b14a8c3eaa0b --- /dev/null +++ b/.changeset/odd-trains-bake.md @@ -0,0 +1,9 @@ +--- +"wrangler": patch +--- + +fix: generate site assets manifest relative to `site.bucket` + +We had a bug where we were generating asset manifest keys incorrectly if we ran wrangler from a different path to `wrangler.toml`. This fixes the generation of said keys, and adds a test for it. + +Fixes #1235 diff --git a/packages/wrangler/src/__tests__/publish.test.ts b/packages/wrangler/src/__tests__/publish.test.ts index 6ab751fd2d4e..323c57ff58ea 100644 --- a/packages/wrangler/src/__tests__/publish.test.ts +++ b/packages/wrangler/src/__tests__/publish.test.ts @@ -2276,6 +2276,59 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); }); + + it("should generate an asset manifest with keys relative to site.bucket", async () => { + const assets = [ + { filePath: "file-1.txt", content: "Content of file-1" }, + { filePath: "file-2.txt", content: "Content of file-2" }, + ]; + const kvNamespace = { + title: "__test-name-workers_sites_assets", + id: "__test-name-workers_sites_assets-id", + }; + + writeWranglerToml({ + main: "./src/index.js", + site: { + bucket: "assets", + }, + }); + writeWorkerSource({ basePath: "src", type: "esm" }); + writeAssets(assets); + mockUploadWorkerRequest({ + expectedBindings: [ + { + name: "__STATIC_CONTENT", + namespace_id: "__test-name-workers_sites_assets-id", + type: "kv_namespace", + }, + ], + expectedModules: { + __STATIC_CONTENT_MANIFEST: + '{"file-1.txt":"file-1.2ca234f380.txt","file-2.txt":"file-2.5938485188.txt"}', + }, + }); + mockSubDomainRequest(); + mockListKVNamespacesRequest(kvNamespace); + mockKeyListRequest(kvNamespace.id, []); + mockUploadAssetsToKVRequest(kvNamespace.id, assets); + + process.chdir("./src"); + await runWrangler("publish"); + process.chdir("../"); + + expect(std.out).toMatchInlineSnapshot(` + "Reading file-1.txt... + Uploading as file-1.2ca234f380.txt... + Reading file-2.txt... + Uploading as file-2.5938485188.txt... + ↗️ Done syncing assets + Uploaded test-name (TIMINGS) + Published test-name (TIMINGS) + test-name.test-sub-domain.workers.dev" + `); + expect(std.err).toMatchInlineSnapshot(`""`); + }); }); describe("workers_dev setting", () => { diff --git a/packages/wrangler/src/sites.tsx b/packages/wrangler/src/sites.tsx index 281e0cd510dc..7df353a621e3 100644 --- a/packages/wrangler/src/sites.tsx +++ b/packages/wrangler/src/sites.tsx @@ -200,9 +200,7 @@ export async function syncAssets( namespaceKeys.delete(assetKey); // Prevent different manifest keys on windows - const manifestKey = urlSafe( - path.relative(siteAssets.assetDirectory, absAssetFile) - ); + const manifestKey = urlSafe(path.relative(assetDirectory, absAssetFile)); manifest[manifestKey] = assetKey; }