Skip to content

Commit 4880d54

Browse files
authored
feat: resolve --site cli arg relative to current working directory (#1327)
Before we were resolving the Site directory relative to the location of `wrangler.toml` at all times. Now the `--site` cli arg is resolved relative to current working directory. resolves #1243
1 parent 7ed5e1a commit 4880d54

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

.changeset/large-lizards-enjoy.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
feat: resolve `--site` cli arg relative to current working directory
6+
7+
Before we were resolving the Site directory relative to the location of `wrangler.toml` at all times.
8+
Now the `--site` cli arg is resolved relative to current working directory.
9+
10+
resolves #1243

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

+42
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,48 @@ addEventListener('fetch', event => {});`
25852585
`);
25862586
expect(std.err).toMatchInlineSnapshot(`""`);
25872587
});
2588+
2589+
it("should use the relative path from current working directory to Worker directory when using --site", async () => {
2590+
writeWranglerToml({
2591+
main: "./index.js",
2592+
});
2593+
const assets = [
2594+
{ filePath: "file-1.txt", content: "Content of file-1" },
2595+
{ filePath: "file-2.txt", content: "Content of file-2" },
2596+
];
2597+
writeAssets(assets, "my-assets");
2598+
2599+
const kvNamespace = {
2600+
title: "__test-name-workers_sites_assets",
2601+
id: "__test-name-workers_sites_assets-id",
2602+
};
2603+
2604+
mockSubDomainRequest();
2605+
writeWorkerSource();
2606+
mockUploadWorkerRequest();
2607+
mockListKVNamespacesRequest(kvNamespace);
2608+
mockKeyListRequest(kvNamespace.id, []);
2609+
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
2610+
process.chdir("./my-assets");
2611+
await runWrangler("publish --site .");
2612+
2613+
expect(std).toMatchInlineSnapshot(`
2614+
Object {
2615+
"debug": "",
2616+
"err": "",
2617+
"out": "Reading file-1.txt...
2618+
Uploading as file-1.2ca234f380.txt...
2619+
Reading file-2.txt...
2620+
Uploading as file-2.5938485188.txt...
2621+
↗️ Done syncing assets
2622+
Total Upload: 0xx KiB / gzip: 0xx KiB
2623+
Uploaded test-name (TIMINGS)
2624+
Published test-name (TIMINGS)
2625+
test-name.test-sub-domain.workers.dev",
2626+
"warn": "",
2627+
}
2628+
`);
2629+
});
25882630
});
25892631

25902632
describe("workers_dev setting", () => {

packages/wrangler/src/sites.tsx

+17-13
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,24 @@ export function getAssetPaths(
349349
*/
350350
export function getSiteAssetPaths(
351351
config: Config,
352-
assetDirectory = config.site?.bucket,
352+
assetDirectory?: string,
353353
includePatterns = config.site?.include ?? [],
354354
excludePatterns = config.site?.exclude ?? []
355355
): AssetPaths | undefined {
356-
const baseDirectory = path.resolve(
357-
path.dirname(config.configPath ?? "wrangler.toml")
358-
);
359-
360-
return assetDirectory
361-
? {
362-
baseDirectory,
363-
assetDirectory,
364-
includePatterns,
365-
excludePatterns,
366-
}
367-
: undefined;
356+
const baseDirectory = assetDirectory
357+
? process.cwd()
358+
: path.resolve(path.dirname(config.configPath ?? "wrangler.toml"));
359+
360+
assetDirectory ??= config.site?.bucket;
361+
362+
if (assetDirectory) {
363+
return {
364+
baseDirectory,
365+
assetDirectory,
366+
includePatterns,
367+
excludePatterns,
368+
};
369+
} else {
370+
return undefined;
371+
}
368372
}

0 commit comments

Comments
 (0)