Skip to content

Commit

Permalink
chore(wrangler): rename experimental_assets to assets (#6802)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarmenPopoviciu authored Sep 24, 2024
1 parent 28cb0d7 commit 17eb8a9
Show file tree
Hide file tree
Showing 58 changed files with 619 additions and 875 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-bikes-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

chore: rename `experimental_assets` to `assets`
6 changes: 0 additions & 6 deletions fixtures/workers-with-assets-only/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ To start a dev session you can run
wrangler dev
```

or

```
wrangler dev --experimental-assets=./public
```

## Run tests

```
Expand Down
4 changes: 2 additions & 2 deletions fixtures/workers-with-assets-only/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "worker-with-asset-only"
name = "worker-with-assets-only"
compatibility_date = "2024-01-01"

[experimental_assets]
[assets]
directory = "./public"
6 changes: 0 additions & 6 deletions fixtures/workers-with-assets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ To start a dev session you can run
wrangler dev
```

or

```
wrangler dev --experimental-assets=./public
```

## Run tests

```
Expand Down
4 changes: 2 additions & 2 deletions fixtures/workers-with-assets/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "worker-with-asset"
name = "worker-with-assets"
main = "src/index.ts"
compatibility_date = "2024-01-01"

[experimental_assets]
[assets]
directory = "./public"
binding="ASSETS"
4 changes: 2 additions & 2 deletions packages/create-cloudflare/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("deploy helpers", async () => {
const ctx = createTestContext();
// Can't deploy things with bindings (yet!)
vi.mocked(readFile).mockReturnValue(`
experimental_assets = { directory = "./dist", binding = "ASSETS" }
assets = { directory = "./dist", binding = "ASSETS" }
[[durable_objects.bindings]]
name = "MY_DURABLE_OBJECT"
Expand All @@ -85,7 +85,7 @@ describe("deploy helpers", async () => {
test("assets project is deployable (no other bindings)", async () => {
const ctx = createTestContext();
vi.mocked(readFile).mockReturnValue(`
experimental_assets = { directory = "./dist", binding = "ASSETS" }
assets = { directory = "./dist", binding = "ASSETS" }
`);
// mock the user selecting yes when asked to deploy
vi.mocked(inputPrompt).mockResolvedValueOnce(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const hasBinding = (node: unknown): boolean => {
return false;
}
for (const key of Object.keys(node)) {
if (key === "experimental_assets" || key === "assets") {
if (key === "assets") {
// Properties called "binding" within "assets" do not count as bindings.
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name = "<TBD>"
compatibility_date = "<TBD>"
main = "./dist/cloudflare/_worker.js"
experimental_assets = { directory = "./dist/cloudflare", binding = "ASSETS" }
assets = { directory = "./dist/cloudflare", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
compatibility_date = "<TBD>"
compatibility_flags = ["nodejs_compat_v2"]
main = "./dist/_worker.js"
experimental_assets = { directory = "./dist", binding = "ASSETS" }
assets = { directory = "./dist", binding = "ASSETS" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#:schema node_modules/wrangler/config-schema.json
name = "<TBD>"
compatibility_date = "<TBD>"
experimental_assets = { directory = "./build" }
assets = { directory = "./build" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#:schema node_modules/wrangler/config-schema.json
name = "<TBD>"
compatibility_date = "<TBD>"
experimental_assets = { directory = "./public" }
assets = { directory = "./public" }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#:schema node_modules/wrangler/config-schema.json
name = "<TBD>"
compatibility_date = "<TBD>"
experimental_assets = { directory = "./public" }
assets = { directory = "./public" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "<TBD>"
main = "src/index.js"
compatibility_date = "<TBD>"
experimental_assets = { directory = "./public", binding = "ASSETS" }
assets = { directory = "./public", binding = "ASSETS" }

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "<TBD>"
main = "src/index.ts"
compatibility_date = "<TBD>"
experimental_assets = { directory = "./public", binding = "ASSETS" }
assets = { directory = "./public", binding = "ASSETS" }

# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
main = "src/index.js"
compatibility_date = "<TBD>"
compatibility_flags = ["nodejs_compat"]
experimental_assets = { directory = "./public", binding = "ASSETS" }
assets = { directory = "./public", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
main = "src/entry.py"
compatibility_flags = ["python_workers"]
compatibility_date = "<TBD>"
experimental_assets = { directory = "./public", binding = "ASSETS" }
assets = { directory = "./public", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
main = "src/index.ts"
compatibility_date = "<TBD>"
compatibility_flags = ["nodejs_compat"]
experimental_assets = { directory = "./public", binding = "ASSETS" }
assets = { directory = "./public", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name = "<TBD>"
compatibility_date = "<TBD>"
main = "./dist/worker/index.js"
experimental_assets = { directory = "./dist/public", binding = "ASSETS" }
assets = { directory = "./dist/public", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
compatibility_date = "<TBD>"
compatibility_flags = ["nodejs_compat"]
main = "./dist/_worker.js"
experimental_assets = { directory = "./dist", binding = "ASSET" }
assets = { directory = "./dist", binding = "ASSET" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name = "<TBD>"
compatibility_date = "<TBD>"
main = "./build/worker/index.js"
experimental_assets = { directory = "./build/client" }
assets = { directory = "./build/client" }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name = "<TBD>"
compatibility_date = "<TBD>"
compatibility_flags = ["nodejs_compat"]
main = "./dist/worker/index.js"
experimental_assets = { directory = "./dist/public", binding = "ASSETS" }
assets = { directory = "./dist/public", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name = "<TBD>"
compatibility_date = "<TBD>"
main = ".svelte-kit/cloudflare/_worker.js"
experimental_assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
name = "<TBD>"
compatibility_date = "<TBD>"
main = ".svelte-kit/cloudflare/_worker.js"
experimental_assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
26 changes: 13 additions & 13 deletions packages/wrangler/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -986,7 +986,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -1040,7 +1040,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -1090,7 +1090,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand All @@ -1116,7 +1116,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public2"
`,
});
Expand Down Expand Up @@ -1175,7 +1175,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -1244,7 +1244,7 @@ describe("watch mode", () => {
main = "src/index.ts"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -1284,7 +1284,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand All @@ -1309,7 +1309,7 @@ describe("watch mode", () => {
main = "src/index.ts"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"src/index.ts": dedent`
Expand Down Expand Up @@ -1341,7 +1341,7 @@ describe("watch mode", () => {
main = "src/index.ts"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/index.html": dedent`
Expand Down Expand Up @@ -1372,7 +1372,7 @@ describe("watch mode", () => {
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
});
Expand All @@ -1392,8 +1392,8 @@ describe("watch mode", () => {
);

describe.each([
{ cmd: "wrangler dev --x-assets=dist" },
{ cmd: "wrangler dev --x-dev-env --x-assets=dist" },
{ cmd: "wrangler dev --assets=dist" },
{ cmd: "wrangler dev --x-dev-env --assets=dist" },
])("Workers + Assets watch mode: $cmd", ({ cmd }) => {
it(`supports modifying assets during dev session`, async () => {
const helper = new WranglerE2ETestHelper();
Expand Down
36 changes: 17 additions & 19 deletions packages/wrangler/e2e/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,11 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {
});

const upload = await helper.run(
`wrangler versions upload --assets='./public' --x-versions`
`wrangler versions upload --legacy-assets='./public' --x-versions`
);

expect(normalize(upload.output)).toMatchInlineSnapshot(`
"X [ERROR] Legacy Assets does not support uploading versions through \`wrangler versions upload\`. You must use \`wrangler deploy\` instead.
"X [ERROR] Legacy assets does not support uploading versions through \`wrangler versions upload\`. You must use \`wrangler deploy\` instead.
🪵 Logs were written to "<LOG>""
`);
});
Expand Down Expand Up @@ -589,14 +589,13 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {
`);
});

// TODO: revisit once AUS stabilises/works
it.skip("currently fails to upload if using experimental assets", async () => {
it("should upload version of Worker with assets", async () => {
await helper.seed({
"wrangler.toml": dedent`
name = "${workerName}"
compatibility_date = "2023-01-01"
[experimental_assets]
[assets]
directory = "./public"
`,
"public/asset.txt": `beep boop`,
Expand All @@ -609,25 +608,24 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {
`,
});

const upload = await helper.run(`wrangler versions upload --x-versions`);
const upload = await helper.run(
`wrangler versions upload --message "Upload via e2e test" --tag "e2e-upload-assets" --x-versions`
);

expect(normalize(upload.output).split("X [ERROR]")[0])
.toMatchInlineSnapshot(`
expect(normalize(upload.stdout)).toMatchInlineSnapshot(`
"🌀 Building list of assets...
🌀 Starting asset upload...
🌀 Found 1 new or modified file to upload. Proceeding with upload...
+ /asset.txt
Asset upload failed. Retrying...
APIError: A request to the Cloudflare API (/accounts/CLOUDFLARE_ACCOUNT_ID/workers/assets/upload) failed.
Asset upload failed. Retrying...
APIError: A request to the Cloudflare API (/accounts/CLOUDFLARE_ACCOUNT_ID/workers/assets/upload) failed.
Asset upload failed. Retrying...
APIError: A request to the Cloudflare API (/accounts/CLOUDFLARE_ACCOUNT_ID/workers/assets/upload) failed.
Asset upload failed. Retrying...
APIError: A request to the Cloudflare API (/accounts/CLOUDFLARE_ACCOUNT_ID/workers/assets/upload) failed.
Asset upload failed. Retrying...
APIError: A request to the Cloudflare API (/accounts/CLOUDFLARE_ACCOUNT_ID/workers/assets/upload) failed.
"
Uploaded 1 of 1 assets
✨ Success! Uploaded 1 file (TIMINGS)
Total Upload: xx KiB / gzip: xx KiB
Worker Startup Time: (TIMINGS)
Uploaded tmp-e2e-worker-00000000-0000-0000-0000-000000000000 (TIMINGS)
Worker Version ID: 00000000-0000-0000-0000-000000000000
To deploy this version to production traffic use the command wrangler versions deploy
Changes to non-versioned settings (config properties 'logpush' or 'tail_consumers') take effect after your next deployment using the command wrangler versions deploy
Changes to triggers (routes, custom domains, cron schedules, etc) must be applied with the command wrangler triggers deploy"
`);
});

Expand Down
Loading

0 comments on commit 17eb8a9

Please sign in to comment.