Skip to content

Commit

Permalink
fix: generate site assets manifest relative to site.bucket (#1236)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
threepointone authored Jun 14, 2022
1 parent 4eb70f9 commit 891d128
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .changeset/odd-trains-bake.md
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/wrangler/src/sites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 891d128

Please sign in to comment.