Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: resolve cli arg relative to current working directory #1335

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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