Skip to content

Commit

Permalink
feat: resolve cli arg relative to current working directory (#1335)
Browse files Browse the repository at this point in the history
Before we were resolving the Asset directory relative to the location of  at all times.
Now the  cli arg is resolved relative to current working directory.

resolves #1333
  • Loading branch information
JacobMGEvans committed Jun 22, 2022
1 parent bfbb0be commit 49cf17e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .changeset/lemon-olives-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": patch
---

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

Before we were resolving the Asset directory relative to the location of `wrangler.toml` at all times.
Now the `--assets` cli arg is resolved relative to current working directory.

resolves #1333
44 changes: 43 additions & 1 deletion packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ addEventListener('fetch', event => {});`
expect(std.err).toMatchInlineSnapshot(`""`);
});

it("should use the relative path from current working directory to Worker directory when using --site", async () => {
it("should use the relative path from current working directory to Worker directory when using `--site`", async () => {
writeWranglerToml({
main: "./index.js",
});
Expand Down Expand Up @@ -2617,6 +2617,48 @@ addEventListener('fetch', event => {});`
}
`);
});

it("should use the relative path from current working directory to Worker directory when using `--assets`", 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: "./index.js",
});
writeWorkerSource();
writeAssets(assets, "my-assets");
mockUploadWorkerRequest({
expectedMainModule: "stdin.js",
});
mockSubDomainRequest();
mockListKVNamespacesRequest(kvNamespace);
mockKeyListRequest(kvNamespace.id, []);
mockUploadAssetsToKVRequest(kvNamespace.id, assets);
process.chdir("./my-assets");
await runWrangler("publish --assets .");

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: 52xx KiB / gzip: 13xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
test-name.test-sub-domain.workers.dev",
"warn": "",
}
`);
});
});

describe("workers_dev setting", () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/sites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ export function getAssetPaths(
config: Config,
assetDirectory: string | undefined
): AssetPaths | undefined {
const baseDirectory = path.resolve(
path.dirname(config.configPath ?? "wrangler.toml")
);
const baseDirectory = assetDirectory
? process.cwd()
: path.resolve(path.dirname(config.configPath ?? "wrangler.toml"));

assetDirectory ??=
typeof config.assets === "string"
Expand Down

0 comments on commit 49cf17e

Please sign in to comment.