Skip to content

Commit

Permalink
feat: resolve --site cli arg relative to current working directory (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
JacobMGEvans authored Jun 21, 2022
1 parent 7ed5e1a commit 4880d54
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .changeset/large-lizards-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": patch
---

feat: resolve `--site` cli arg relative to current working directory

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
42 changes: 42 additions & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,48 @@ addEventListener('fetch', event => {});`
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});

it("should use the relative path from current working directory to Worker directory when using --site", async () => {
writeWranglerToml({
main: "./index.js",
});
const assets = [
{ filePath: "file-1.txt", content: "Content of file-1" },
{ filePath: "file-2.txt", content: "Content of file-2" },
];
writeAssets(assets, "my-assets");

const kvNamespace = {
title: "__test-name-workers_sites_assets",
id: "__test-name-workers_sites_assets-id",
};

mockSubDomainRequest();
writeWorkerSource();
mockUploadWorkerRequest();
mockListKVNamespacesRequest(kvNamespace);
mockKeyListRequest(kvNamespace.id, []);
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
process.chdir("./my-assets");
await runWrangler("publish --site .");

expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "",
"out": "Reading file-1.txt...
Uploading as file-1.2ca234f380.txt...
Reading file-2.txt...
Uploading as file-2.5938485188.txt...
↗️ Done syncing assets
Total Upload: 0xx KiB / gzip: 0xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
test-name.test-sub-domain.workers.dev",
"warn": "",
}
`);
});
});

describe("workers_dev setting", () => {
Expand Down
30 changes: 17 additions & 13 deletions packages/wrangler/src/sites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,24 @@ export function getAssetPaths(
*/
export function getSiteAssetPaths(
config: Config,
assetDirectory = config.site?.bucket,
assetDirectory?: string,
includePatterns = config.site?.include ?? [],
excludePatterns = config.site?.exclude ?? []
): AssetPaths | undefined {
const baseDirectory = path.resolve(
path.dirname(config.configPath ?? "wrangler.toml")
);

return assetDirectory
? {
baseDirectory,
assetDirectory,
includePatterns,
excludePatterns,
}
: undefined;
const baseDirectory = assetDirectory
? process.cwd()
: path.resolve(path.dirname(config.configPath ?? "wrangler.toml"));

assetDirectory ??= config.site?.bucket;

if (assetDirectory) {
return {
baseDirectory,
assetDirectory,
includePatterns,
excludePatterns,
};
} else {
return undefined;
}
}

0 comments on commit 4880d54

Please sign in to comment.