diff --git a/.changeset/perfect-bikes-type.md b/.changeset/perfect-bikes-type.md new file mode 100644 index 000000000000..1315390b83eb --- /dev/null +++ b/.changeset/perfect-bikes-type.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +chore: rename `experimental_assets` to `assets` diff --git a/fixtures/workers-with-assets-only/README.md b/fixtures/workers-with-assets-only/README.md index 5c1de91af816..110052601c3e 100644 --- a/fixtures/workers-with-assets-only/README.md +++ b/fixtures/workers-with-assets-only/README.md @@ -10,12 +10,6 @@ To start a dev session you can run wrangler dev ``` -or - -``` -wrangler dev --experimental-assets=./public -``` - ## Run tests ``` diff --git a/fixtures/workers-with-assets-only/wrangler.toml b/fixtures/workers-with-assets-only/wrangler.toml index ab54b1a45381..2fc6c3a71bf3 100644 --- a/fixtures/workers-with-assets-only/wrangler.toml +++ b/fixtures/workers-with-assets-only/wrangler.toml @@ -1,5 +1,5 @@ -name = "worker-with-asset-only" +name = "worker-with-assets-only" compatibility_date = "2024-01-01" -[experimental_assets] +[assets] directory = "./public" diff --git a/fixtures/workers-with-assets/README.md b/fixtures/workers-with-assets/README.md index c324609a1e78..6f09e9801742 100644 --- a/fixtures/workers-with-assets/README.md +++ b/fixtures/workers-with-assets/README.md @@ -10,12 +10,6 @@ To start a dev session you can run wrangler dev ``` -or - -``` -wrangler dev --experimental-assets=./public -``` - ## Run tests ``` diff --git a/fixtures/workers-with-assets/wrangler.toml b/fixtures/workers-with-assets/wrangler.toml index fc6955d064db..9431c78feb05 100644 --- a/fixtures/workers-with-assets/wrangler.toml +++ b/fixtures/workers-with-assets/wrangler.toml @@ -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" diff --git a/packages/create-cloudflare/src/__tests__/deploy.test.ts b/packages/create-cloudflare/src/__tests__/deploy.test.ts index 5af57ed1e653..a4a8f6e9ce39 100644 --- a/packages/create-cloudflare/src/__tests__/deploy.test.ts +++ b/packages/create-cloudflare/src/__tests__/deploy.test.ts @@ -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" @@ -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); diff --git a/packages/create-cloudflare/src/deploy.ts b/packages/create-cloudflare/src/deploy.ts index 634226f5fc68..7f9eea53d217 100644 --- a/packages/create-cloudflare/src/deploy.ts +++ b/packages/create-cloudflare/src/deploy.ts @@ -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; } diff --git a/packages/create-cloudflare/templates-experimental/angular/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/angular/templates/wrangler.toml index 845730f49059..51acafa88f3d 100644 --- a/packages/create-cloudflare/templates-experimental/angular/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/angular/templates/wrangler.toml @@ -2,4 +2,4 @@ name = "" compatibility_date = "" main = "./dist/cloudflare/_worker.js" -experimental_assets = { directory = "./dist/cloudflare", binding = "ASSETS" } +assets = { directory = "./dist/cloudflare", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/astro/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/astro/templates/wrangler.toml index f0a68d0bb012..8e9ac0b0ce30 100644 --- a/packages/create-cloudflare/templates-experimental/astro/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/astro/templates/wrangler.toml @@ -3,4 +3,4 @@ name = "" compatibility_date = "" compatibility_flags = ["nodejs_compat_v2"] main = "./dist/_worker.js" -experimental_assets = { directory = "./dist", binding = "ASSETS" } +assets = { directory = "./dist", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/docusaurus/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/docusaurus/templates/wrangler.toml index f533e6a012af..6f04701a8c70 100644 --- a/packages/create-cloudflare/templates-experimental/docusaurus/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/docusaurus/templates/wrangler.toml @@ -1,4 +1,4 @@ #:schema node_modules/wrangler/config-schema.json name = "" compatibility_date = "" -experimental_assets = { directory = "./build" } +assets = { directory = "./build" } diff --git a/packages/create-cloudflare/templates-experimental/gatsby/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/gatsby/templates/wrangler.toml index 99fcccb2bd2a..9592d39127a6 100644 --- a/packages/create-cloudflare/templates-experimental/gatsby/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/gatsby/templates/wrangler.toml @@ -1,4 +1,4 @@ #:schema node_modules/wrangler/config-schema.json name = "" compatibility_date = "" -experimental_assets = { directory = "./public" } +assets = { directory = "./public" } diff --git a/packages/create-cloudflare/templates-experimental/hello-world-assets-only/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-assets-only/templates/wrangler.toml index 99fcccb2bd2a..9592d39127a6 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-assets-only/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-assets-only/templates/wrangler.toml @@ -1,4 +1,4 @@ #:schema node_modules/wrangler/config-schema.json name = "" compatibility_date = "" -experimental_assets = { directory = "./public" } +assets = { directory = "./public" } diff --git a/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/js/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/js/wrangler.toml index 49f8980afa42..de2e8679552b 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/js/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/js/wrangler.toml @@ -2,7 +2,7 @@ name = "" main = "src/index.js" compatibility_date = "" -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. diff --git a/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/ts/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/ts/wrangler.toml index c54b8c4eb91b..100632d3b1fb 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/ts/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-durable-object-with-assets/ts/wrangler.toml @@ -2,7 +2,7 @@ name = "" main = "src/index.ts" compatibility_date = "" -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. diff --git a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/js/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/js/wrangler.toml index a3da42fceec8..d81a2fa5148e 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/js/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/js/wrangler.toml @@ -3,4 +3,4 @@ name = "" main = "src/index.js" compatibility_date = "" compatibility_flags = ["nodejs_compat"] -experimental_assets = { directory = "./public", binding = "ASSETS" } +assets = { directory = "./public", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/py/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/py/wrangler.toml index 95c1777d9075..2a19abb96b60 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/py/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/py/wrangler.toml @@ -3,4 +3,4 @@ name = "" main = "src/entry.py" compatibility_flags = ["python_workers"] compatibility_date = "" -experimental_assets = { directory = "./public", binding = "ASSETS" } +assets = { directory = "./public", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/ts/wrangler.toml b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/ts/wrangler.toml index c9415bf3ec94..1b598b412171 100644 --- a/packages/create-cloudflare/templates-experimental/hello-world-with-assets/ts/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/hello-world-with-assets/ts/wrangler.toml @@ -3,4 +3,4 @@ name = "" main = "src/index.ts" compatibility_date = "" compatibility_flags = ["nodejs_compat"] -experimental_assets = { directory = "./public", binding = "ASSETS" } +assets = { directory = "./public", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/nuxt/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/nuxt/templates/wrangler.toml index b1203c74c4c5..ef30ca1ecd11 100644 --- a/packages/create-cloudflare/templates-experimental/nuxt/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/nuxt/templates/wrangler.toml @@ -2,4 +2,4 @@ name = "" compatibility_date = "" main = "./dist/worker/index.js" -experimental_assets = { directory = "./dist/public", binding = "ASSETS" } +assets = { directory = "./dist/public", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/qwik/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/qwik/templates/wrangler.toml index 2128ee08849d..5c30f81bbe72 100644 --- a/packages/create-cloudflare/templates-experimental/qwik/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/qwik/templates/wrangler.toml @@ -3,4 +3,4 @@ name = "" compatibility_date = "" compatibility_flags = ["nodejs_compat"] main = "./dist/_worker.js" -experimental_assets = { directory = "./dist", binding = "ASSET" } +assets = { directory = "./dist", binding = "ASSET" } diff --git a/packages/create-cloudflare/templates-experimental/remix/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/remix/templates/wrangler.toml index 66763e80a4c3..7e6d216d66d7 100644 --- a/packages/create-cloudflare/templates-experimental/remix/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/remix/templates/wrangler.toml @@ -2,4 +2,4 @@ name = "" compatibility_date = "" main = "./build/worker/index.js" -experimental_assets = { directory = "./build/client" } +assets = { directory = "./build/client" } diff --git a/packages/create-cloudflare/templates-experimental/solid/templates/wrangler.toml b/packages/create-cloudflare/templates-experimental/solid/templates/wrangler.toml index 52347fd94c21..86b57e70638d 100644 --- a/packages/create-cloudflare/templates-experimental/solid/templates/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/solid/templates/wrangler.toml @@ -3,4 +3,4 @@ name = "" compatibility_date = "" compatibility_flags = ["nodejs_compat"] main = "./dist/worker/index.js" -experimental_assets = { directory = "./dist/public", binding = "ASSETS" } +assets = { directory = "./dist/public", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/svelte/js/wrangler.toml b/packages/create-cloudflare/templates-experimental/svelte/js/wrangler.toml index b6cbc9e30304..745564593c46 100644 --- a/packages/create-cloudflare/templates-experimental/svelte/js/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/svelte/js/wrangler.toml @@ -2,4 +2,4 @@ name = "" compatibility_date = "" main = ".svelte-kit/cloudflare/_worker.js" -experimental_assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" } +assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" } diff --git a/packages/create-cloudflare/templates-experimental/svelte/ts/wrangler.toml b/packages/create-cloudflare/templates-experimental/svelte/ts/wrangler.toml index b6cbc9e30304..745564593c46 100644 --- a/packages/create-cloudflare/templates-experimental/svelte/ts/wrangler.toml +++ b/packages/create-cloudflare/templates-experimental/svelte/ts/wrangler.toml @@ -2,4 +2,4 @@ name = "" compatibility_date = "" main = ".svelte-kit/cloudflare/_worker.js" -experimental_assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" } +assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" } diff --git a/packages/wrangler/e2e/dev.test.ts b/packages/wrangler/e2e/dev.test.ts index 49f69a5e44d4..d4a76d66349c 100644 --- a/packages/wrangler/e2e/dev.test.ts +++ b/packages/wrangler/e2e/dev.test.ts @@ -943,7 +943,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -986,7 +986,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -1040,7 +1040,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -1090,7 +1090,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -1116,7 +1116,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public2" `, }); @@ -1175,7 +1175,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -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` @@ -1284,7 +1284,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, "public/index.html": dedent` @@ -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` @@ -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` @@ -1372,7 +1372,7 @@ describe("watch mode", () => { name = "${workerName}" compatibility_date = "2023-01-01" - [experimental_assets] + [assets] directory = "./public" `, }); @@ -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(); diff --git a/packages/wrangler/e2e/versions.test.ts b/packages/wrangler/e2e/versions.test.ts index 8d987a3dacb1..fd9efd1149a6 100644 --- a/packages/wrangler/e2e/versions.test.ts +++ b/packages/wrangler/e2e/versions.test.ts @@ -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 """ `); }); @@ -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`, @@ -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" `); }); diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 22c05974cd94..fa0912fc2912 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -506,7 +506,8 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time." + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead." `); }); @@ -524,7 +525,8 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time." + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead." `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: @@ -555,7 +557,8 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time." + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead." `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: @@ -584,7 +587,8 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.hasWarnings()).toBe(true); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time." + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead." `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: @@ -596,55 +600,6 @@ describe("normalizeAndValidateConfig()", () => { - Expected \\"legacy_assets.serve_single_page_app\\" to be of type boolean but got \\"INVALID\\"." `); }); - - it("saves `assets` values under `legacy_assets`", () => { - const { config, diagnostics } = normalizeAndValidateConfig( - { - assets: "path/to/assets", - } as unknown as RawConfig, - undefined, - { env: undefined } - ); - - expect(config.legacy_assets).toMatchInlineSnapshot(` - Object { - "browser_TTL": undefined, - "bucket": "path/to/assets", - "exclude": Array [], - "include": Array [], - "serve_single_page_app": false, - } - `); - expect(diagnostics.hasWarnings()).toBe(true); - expect(diagnostics.hasErrors()).toBe(false); - - expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` - "Processing wrangler configuration: - - Behavior change: \\"assets\\": - The \`assets\` feature is experimental. We are going to be changing its behavior after August 15th. - Releases of wrangler after this date will no longer support current functionality. - Please shift to \`legacy_assets\` to preserve the current functionality. " - `); - }); - - it("should error if `assets` and `legacy_assets` are both defined", () => { - const { diagnostics } = normalizeAndValidateConfig( - { - assets: "path/to/assets", - legacy_assets: "path/to/assets", - } as unknown as RawConfig, - undefined, - { env: undefined } - ); - - expect(diagnostics.hasWarnings()).toBe(true); - expect(diagnostics.hasErrors()).toBe(true); - - expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` - "Processing wrangler configuration: - - Expected only one of \`assets\` or \`legacy_assets\`." - `); - }); }); it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => { @@ -1788,10 +1743,10 @@ describe("normalizeAndValidateConfig()", () => { }); }); - describe("[experimental_assets]", () => { - it("should override `experimental_assets` config defaults with provided values", () => { + describe("[assets]", () => { + it("should override `assets` config defaults with provided values", () => { const expectedConfig: RawConfig = { - experimental_assets: { + assets: { directory: "public/", binding: "ASSETS", }, @@ -1808,9 +1763,9 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.hasWarnings()).toBe(false); }); - it("should error on invalid `experimental_assets` values", () => { + it("should error on invalid `assets` values", () => { const expectedConfig = { - experimental_assets: { + assets: { binding: 2, notAField: "boop", }, @@ -1826,18 +1781,18 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.hasWarnings()).toBe(true); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - Unexpected fields found in experimental_assets field: \\"notAField\\"" + - Unexpected fields found in assets field: \\"notAField\\"" `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - \\"experimental_assets.directory\\" is a required field. - - Expected \\"experimental_assets.binding\\" to be of type string but got 2." + - \\"assets.directory\\" is a required field. + - Expected \\"assets.binding\\" to be of type string but got 2." `); }); - it("should error on invalid `experimental_assets` config values", () => { + it("should error on invalid `assets` config values", () => { const expectedConfig = { - experimental_assets: { + assets: { directory: "./public", html_handling: "foo", not_found_handling: "bar", @@ -1858,14 +1813,14 @@ describe("normalizeAndValidateConfig()", () => { `); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - Expected \\"experimental_assets.html_handling\\" field to be one of [\\"auto-trailing-slash\\",\\"force-trailing-slash\\",\\"drop-trailing-slash\\",\\"none\\"] but got \\"foo\\". - - Expected \\"experimental_assets.not_found_handling\\" field to be one of [\\"single-page-application\\",\\"404-page\\",\\"none\\"] but got \\"bar\\"." + - Expected \\"assets.html_handling\\" field to be one of [\\"auto-trailing-slash\\",\\"force-trailing-slash\\",\\"drop-trailing-slash\\",\\"none\\"] but got \\"foo\\". + - Expected \\"assets.not_found_handling\\" field to be one of [\\"single-page-application\\",\\"404-page\\",\\"none\\"] but got \\"bar\\"." `); }); - it("should accept valid `experimental_assets` config values", () => { + it("should accept valid `assets` config values", () => { const expectedConfig: RawConfig = { - experimental_assets: { + assets: { directory: "./public", html_handling: "drop-trailing-slash", not_found_handling: "404-page", @@ -1885,7 +1840,7 @@ describe("normalizeAndValidateConfig()", () => { it("should error if `directory` is an empty string", () => { const expectedConfig = { - experimental_assets: { + assets: { directory: "", }, }; @@ -1900,13 +1855,13 @@ describe("normalizeAndValidateConfig()", () => { expect(diagnostics.hasWarnings()).toBeFalsy(); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - Expected \\"experimental_assets.directory\\" to be a non-empty string." + - Expected \\"assets.directory\\" to be a non-empty string." `); }); it("should error on invalid additional fields", () => { const expectedConfig = { - experimental_assets: { + assets: { directory: "./public", invalid_field_1: "this is invalid", invalid_field_2: "this is invalid too", @@ -1922,7 +1877,7 @@ describe("normalizeAndValidateConfig()", () => { expect(config).toEqual(expect.objectContaining(expectedConfig)); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: - - Unexpected fields found in experimental_assets field: \\"invalid_field_1\\",\\"invalid_field_2\\"" + - Unexpected fields found in assets field: \\"invalid_field_1\\",\\"invalid_field_2\\"" `); expect(diagnostics.hasErrors()).toBeFalsy(); }); diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index ff8589e18b81..8e37d17cff19 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -49,9 +49,9 @@ import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; import { writeWorkerSource } from "./helpers/write-worker-source"; import { writeWranglerToml } from "./helpers/write-wrangler-toml"; +import type { AssetManifest } from "../assets"; import type { Config } from "../config"; import type { CustomDomain, CustomDomainChangeset } from "../deploy/deploy"; -import type { AssetManifest } from "../experimental-assets"; import type { KVNamespaceInfo } from "../kv/helpers"; import type { PostQueueBody, @@ -1547,7 +1547,7 @@ Update them to point to this script instead?`, }); }); - it("should error on routes with paths if experimental assets are present", async () => { + it("should error on routes with paths if assets are present", async () => { writeWranglerToml({ routes: [ "simple.co.uk/path", @@ -1568,7 +1568,7 @@ Update them to point to this script instead?`, writeWorkerSource(); writeAssets([{ filePath: "asset.txt", content: "Content of file-1" }]); - await expect(runWrangler(`deploy --experimental-assets="assets"`)).rejects + await expect(runWrangler(`deploy --assets="assets"`)).rejects .toThrowErrorMatchingInlineSnapshot(` [Error: Invalid Routes: simple.co.uk/path: @@ -1604,7 +1604,7 @@ Update them to point to this script instead?`, `); }); - it("shouldn't error on routes with paths if there are no experimental assets", async () => { + it("shouldn't error on routes with paths if there are no assets", async () => { writeWranglerToml({ routes: [ "simple.co.uk/path", @@ -2242,32 +2242,35 @@ addEventListener('fetch', event => {});` "deploy --legacy-assets assets --latest --name test-name" ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "Fetching list of already uploaded assets... + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. + + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. + + + ▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml. + + + + " + `); + expect(std.info).toMatchInlineSnapshot(` + "Fetching list of already uploaded assets... Building list of assets to upload... + file-1.2ca234f380.txt (uploading new version of file-1.txt) + file-2.5938485188.txt (uploading new version of file-2.txt) Uploading 2 new assets... - Uploaded 100% [2 out of 2]", - "out": "↗️ Done syncing assets + Uploaded 100% [2 out of 2]" + `); + expect(std.out).toMatchInlineSnapshot(` + "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms Uploaded test-name (TIMINGS) Deployed test-name triggers (TIMINGS) https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. - - - ▲ [WARNING] Using the latest version of the Workers runtime. To silence this warning, please choose a specific version of the runtime with --compatibility-date, or add a compatibility_date to your wrangler.toml. - - - - ", - } + Current Version ID: Galaxy-Class" `); }); @@ -2454,62 +2457,13 @@ addEventListener('fetch', event => {});` await runWrangler("deploy --legacy-assets assets"); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. - - " - `); - expect(std.out).toMatchInlineSnapshot(` - "↗️ Done syncing assets - Total Upload: xx KiB / gzip: xx KiB - Worker Startup Time: 100 ms - Uploaded test-name (TIMINGS) - Deployed test-name triggers (TIMINGS) - https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class" - `); - - expect(std.info).toMatchInlineSnapshot(` - "Fetching list of already uploaded assets... - Building list of assets to upload... - + file-1.2ca234f380.txt (uploading new version of file-1.txt) - + file-2.5938485188.txt (uploading new version of file-2.txt) - Uploading 2 new assets... - Uploaded 100% [2 out of 2]" - `); - }); - - it("should upload all the files in the directory specified by `--assets` as with `--legacy-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); - mockUploadWorkerRequest({ - expectedMainModule: "index.js", - }); - mockSubDomainRequest(); - mockListKVNamespacesRequest(kvNamespace); - mockKeyListRequest(kvNamespace.id, []); - mockUploadAssetsToKVRequest(kvNamespace.id, assets); - await runWrangler("deploy --assets assets"); - - expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] The --assets argument is experimental. We are going to be changing the behavior of this experimental command after August 15th. + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. - Releases of wrangler after this date will no longer support current functionality. - Please shift to the --legacy-assets command to preserve the current functionality. + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. " `); - expect(std.out).toMatchInlineSnapshot(` "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB @@ -2541,18 +2495,13 @@ addEventListener('fetch', event => {});` `[Error: You cannot use the service-worker format with an \`assets\` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/]` ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "X [ERROR] You cannot use the service-worker format with an \`assets\` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/ + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. - ", - "info": "", - "out": "", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. - ", - } + " `); }); @@ -2564,21 +2513,21 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy --legacy-assets abc --site xyz") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "X [ERROR] Cannot use Legacy Assets and Workers Sites in the same Worker. + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. - ", - "info": "", - "out": "", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. - ", - } + " + `); + expect(std.err).toMatchInlineSnapshot(` + "X [ERROR] Cannot use legacy assets and Workers Sites in the same Worker. + + " `); }); @@ -2593,21 +2542,16 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy --legacy-assets abc") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "X [ERROR] Cannot use Legacy Assets and Workers Sites in the same Worker. + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. - ", - "info": "", - "out": "", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. - ", - } + " `); }); @@ -2620,23 +2564,16 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy --site xyz") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "X [ERROR] Cannot use Legacy Assets and Workers Sites in the same Worker. - - ", - "info": "", - "out": "", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time. + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead. - ", - } + " `); }); @@ -2652,23 +2589,16 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "X [ERROR] Cannot use Legacy Assets and Workers Sites in the same Worker. - - ", - "info": "", - "out": "", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"legacy_assets\\" fields are experimental and may change or break at any time. + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead. - ", - } + " `); }); @@ -2696,27 +2626,32 @@ addEventListener('fetch', event => {});` mockUploadAssetsToKVRequest(kvNamespace.id, assets); await runWrangler("deploy --legacy-assets ./assets"); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "Fetching list of already uploaded assets... + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. + + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. + + " + `); + expect(std.err).toMatchInlineSnapshot(`""`); + expect(std.info).toMatchInlineSnapshot(` + "Fetching list of already uploaded assets... Building list of assets to upload... + subdir/file-1.2ca234f380.txt (uploading new version of subdir/file-1.txt) + subdir/file-2.5938485188.txt (uploading new version of subdir/file-2.txt) Uploading 2 new assets... - Uploaded 100% [2 out of 2]", - "out": "↗️ Done syncing assets + Uploaded 100% [2 out of 2]" + `); + expect(std.out).toMatchInlineSnapshot(` + "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms Uploaded test-name (TIMINGS) Deployed test-name triggers (TIMINGS) https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. - - ", - } + Current Version ID: Galaxy-Class" `); }); @@ -2745,29 +2680,31 @@ addEventListener('fetch', event => {});` mockUploadAssetsToKVRequest(kvNamespace.id, assets); await runWrangler("deploy"); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "Fetching list of already uploaded assets... + + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Processing wrangler.toml configuration: + + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead. + + " + `); + expect(std.info).toMatchInlineSnapshot(` + "Fetching list of already uploaded assets... Building list of assets to upload... + subdir/file-1.2ca234f380.txt (uploading new version of subdir/file-1.txt) + subdir/file-2.5938485188.txt (uploading new version of subdir/file-2.txt) Uploading 2 new assets... - Uploaded 100% [2 out of 2]", - "out": "↗️ Done syncing assets + Uploaded 100% [2 out of 2]" + `); + expect(std.out).toMatchInlineSnapshot(` + "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms Uploaded test-name (TIMINGS) Deployed test-name triggers (TIMINGS) https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class", - "warn": "▲ [WARNING] Processing wrangler.toml configuration: - - - \\"legacy_assets\\" fields are experimental and may change or break at any time. - - ", - } + Current Version ID: Galaxy-Class" `); }); @@ -3928,27 +3865,30 @@ addEventListener('fetch', event => {});` process.chdir("./my-assets"); await runWrangler("deploy --legacy-assets ."); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "Fetching list of already uploaded assets... + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. + + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. + + " + `); + expect(std.info).toMatchInlineSnapshot(` + "Fetching list of already uploaded assets... Building list of assets to upload... + file-1.2ca234f380.txt (uploading new version of file-1.txt) + file-2.5938485188.txt (uploading new version of file-2.txt) Uploading 2 new assets... - Uploaded 100% [2 out of 2]", - "out": "↗️ Done syncing assets + Uploaded 100% [2 out of 2]" + `); + expect(std.out).toMatchInlineSnapshot(` + "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms Uploaded test-name (TIMINGS) Deployed test-name triggers (TIMINGS) https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. - - ", - } + Current Version ID: Galaxy-Class" `); }); @@ -4298,7 +4238,7 @@ addEventListener('fetch', event => {});` }); }); - describe("--experimental-assets", () => { + describe("--assets", () => { it("should use the directory specified in the CLI over wrangler.toml", async () => { const cliAssets = [ { filePath: "cliAsset.txt", content: "Content of file-1" }, @@ -4309,19 +4249,19 @@ addEventListener('fetch', event => {});` ]; writeAssets(configAssets, "config-assets"); writeWranglerToml({ - experimental_assets: { directory: "config-assets" }, + assets: { directory: "config-assets" }, }); const bodies: AssetManifest[] = []; await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, expectedType: "none", }); - await runWrangler("deploy --experimental-assets cli-assets"); + await runWrangler("deploy --assets cli-assets"); expect(bodies.length).toBe(1); expect(bodies[0]).toEqual({ manifest: { @@ -4333,10 +4273,10 @@ addEventListener('fetch', event => {});` }); }); - it("should error if config.site and config.experimental_assets are used together", async () => { + it("should error if config.site and config.assets are used together", async () => { writeWranglerToml({ main: "./index.js", - experimental_assets: { directory: "abd" }, + assets: { directory: "abd" }, site: { bucket: "xyz", }, @@ -4345,12 +4285,12 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy") ).rejects.toThrowErrorMatchingInlineSnapshot( - dedent`[Error: Cannot use Experimental Assets and Workers Sites in the same Worker. - Please remove either the \`site\` or \`experimental_assets\` field from your configuration file.]` + dedent`[Error: Cannot use assets and Workers Sites in the same Worker. + Please remove either the \`site\` or \`assets\` field from your configuration file.]` ); }); - it("should error if --experimental-assets and config.site are used together", async () => { + it("should error if --assets and config.site are used together", async () => { writeWranglerToml({ main: "./index.js", site: { @@ -4359,44 +4299,42 @@ addEventListener('fetch', event => {});` }); writeWorkerSource(); await expect( - runWrangler("deploy --experimental-assets abc") + runWrangler("deploy --assets abc") ).rejects.toThrowErrorMatchingInlineSnapshot( - dedent`[Error: Cannot use Experimental Assets and Workers Sites in the same Worker. - Please remove either the \`site\` or \`experimental_assets\` field from your configuration file.]` + dedent`[Error: Cannot use assets and Workers Sites in the same Worker. + Please remove either the \`site\` or \`assets\` field from your configuration file.]` ); }); - it("should error if directory specified by flag --experimental-assets does not exist", async () => { - await expect( - runWrangler("deploy --experimental-assets abc") - ).rejects.toThrow( + it("should error if directory specified by flag --assets does not exist", async () => { + await expect(runWrangler("deploy --assets abc")).rejects.toThrow( new RegExp( - '^The directory specified by the "--experimental-assets" command line argument does not exist:[Ss]*' + '^The directory specified by the "--assets" command line argument does not exist:[Ss]*' ) ); }); - it("should error if directory specified by config experimental_assets does not exist", async () => { + it("should error if directory specified by config assets does not exist", async () => { writeWranglerToml({ - experimental_assets: { directory: "abc" }, + assets: { directory: "abc" }, }); await expect(runWrangler("deploy")).rejects.toThrow( new RegExp( - '^The directory specified by the "experimental_assets.directory" field in your configuration file does not exist:[Ss]*' + '^The directory specified by the "assets.directory" field in your configuration file does not exist:[Ss]*' ) ); }); it("should error if an ASSET binding is provided without a user Worker", async () => { writeWranglerToml({ - experimental_assets: { + assets: { directory: "xyz", binding: "ASSET", }, }); await expect(runWrangler("deploy")).rejects .toThrowErrorMatchingInlineSnapshot(` - [Error: Cannot use Experimental Assets with a binding in an assets-only Worker. + [Error: Cannot use assets with a binding in an assets-only Worker. Please remove the asset binding from your configuration file, or provide a Worker script in your configuration file (\`main\`).] `); }); @@ -4410,7 +4348,7 @@ addEventListener('fetch', event => {});` ]; writeAssets(assets); writeWranglerToml({ - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }); const manifestBodies: AssetManifest[] = []; @@ -4433,7 +4371,7 @@ addEventListener('fetch', event => {});` ); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4501,7 +4439,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4509,7 +4447,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4539,7 +4477,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4547,7 +4485,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4578,7 +4516,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4586,7 +4524,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4615,7 +4553,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4623,7 +4561,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4646,7 +4584,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4654,7 +4592,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4685,7 +4623,7 @@ addEventListener('fetch', event => {});` writeAssets(assets, "some/path/assets"); writeWranglerToml( { - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }, "some/path/wrangler.toml" ); @@ -4693,7 +4631,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4721,7 +4659,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(bodies); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4729,7 +4667,7 @@ addEventListener('fetch', event => {});` }); process.chdir("some/path"); await runWrangler( - "deploy --name test-name --compatibility-date 2024-07-31 --experimental-assets assets" + "deploy --name test-name --compatibility-date 2024-07-31 --assets assets" ); expect(bodies.length).toBe(1); expect(bodies[0]).toEqual({ @@ -4742,7 +4680,7 @@ addEventListener('fetch', event => {});` }); }); - it("should upload an asset manifest of the files in the directory specified by --experimental-assets", async () => { + it("should upload an asset manifest of the files in the directory specified by --assets", async () => { const assets = [ { filePath: "file-1.txt", content: "Content of file-1" }, { filePath: "boop/file-2.txt", content: "Content of file-2" }, @@ -4753,14 +4691,14 @@ addEventListener('fetch', event => {});` // skips asset uploading since empty buckets returned mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, expectedType: "none", }); await runWrangler( - "deploy --name test-name --compatibility-date 2024-07-31 --experimental-assets assets" + "deploy --name test-name --compatibility-date 2024-07-31 --assets assets" ); expect(bodies.length).toBe(1); expect(bodies[0]).toStrictEqual({ @@ -4777,21 +4715,21 @@ addEventListener('fetch', event => {});` }); }); - it("should upload an asset manifest of the files in the directory specified by [experimental_assets] config", async () => { + it("should upload an asset manifest of the files in the directory specified by [assets] config", async () => { const assets = [ { filePath: "file-1.txt", content: "Content of file-1" }, { filePath: "boop/file-2.txt", content: "Content of file-2" }, ]; writeAssets(assets); writeWranglerToml({ - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }); const bodies: AssetManifest[] = []; await mockAUSRequest(bodies); // skips asset uploading since empty buckets returned mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4827,7 +4765,7 @@ addEventListener('fetch', event => {});` ]; writeAssets(assets); writeWranglerToml({ - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }); const mockBuckets = [ [ @@ -4850,7 +4788,7 @@ addEventListener('fetch', event => {});` ); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: {}, }, @@ -4935,7 +4873,7 @@ addEventListener('fetch', event => {});` main: "index.js", compatibility_date: "2024-09-27", compatibility_flags: ["nodejs_compat"], - experimental_assets: { + assets: { directory: "assets", binding: "ASSETS", html_handling: "none", @@ -4945,7 +4883,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: { html_handling: "none", not_found_handling: "404-page" }, }, @@ -4967,7 +4905,7 @@ addEventListener('fetch', event => {});` writeWranglerToml({ compatibility_date: "2024-09-27", compatibility_flags: ["nodejs_compat"], - experimental_assets: { + assets: { directory: "assets", html_handling: "none", }, @@ -4975,7 +4913,7 @@ addEventListener('fetch', event => {});` await mockAUSRequest(); mockSubDomainRequest(); mockUploadWorkerRequest({ - expectedExperimentalAssets: { + expectedAssets: { jwt: "<>", config: { html_handling: "none" }, }, @@ -9185,27 +9123,22 @@ addEventListener('fetch', event => {});` ); expect(fs.existsSync("some-dir/index.js")).toBe(true); expect(fs.existsSync("some-dir/index.js.map")).toBe(true); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "Fetching list of already uploaded assets... + expect(std.info).toMatchInlineSnapshot(` + "Fetching list of already uploaded assets... Building list of assets to upload... + file-1.2ca234f380.txt (uploading new version of file-1.txt) + file-2.5938485188.txt (uploading new version of file-2.txt) Uploading 2 new assets... - Uploaded 100% [2 out of 2]", - "out": "↗️ Done syncing assets + Uploaded 100% [2 out of 2]" + `); + expect(std.out).toMatchInlineSnapshot(` + "↗️ Done syncing assets Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms Uploaded test-name (TIMINGS) Deployed test-name triggers (TIMINGS) https://test-name.test-sub-domain.workers.dev - Current Version ID: Galaxy-Class", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. - - ", - } + Current Version ID: Galaxy-Class" `); }); diff --git a/packages/wrangler/src/__tests__/dev.test.tsx b/packages/wrangler/src/__tests__/dev.test.tsx index 8bbf271a7816..7ca8d43c4d97 100644 --- a/packages/wrangler/src/__tests__/dev.test.tsx +++ b/packages/wrangler/src/__tests__/dev.test.tsx @@ -324,7 +324,7 @@ describe("wrangler dev", () => { Paths are not allowed in Custom Domains] `); }); - it("should error on routes with paths if experimental assets are present", async () => { + it("should error on routes with paths if assets are present", async () => { writeWranglerToml({ routes: [ "simple.co.uk/path", @@ -341,7 +341,7 @@ describe("wrangler dev", () => { { pattern: "custom.co.uk/*", custom_domain: true }, { pattern: "custom.co.uk", custom_domain: true }, ], - experimental_assets: { + assets: { directory: "assets", }, }); @@ -1341,10 +1341,11 @@ describe("wrangler dev", () => { OPTIONS --name Name of the worker [string] - --no-bundle Skip internal build steps and directly deploy script [boolean] [default: false] --compatibility-date Date to use for compatibility checks [string] --compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array] --latest Use the latest version of the worker runtime [boolean] [default: true] + --assets Static assets to be served. Replaces Workers Sites. [string] + --no-bundle Skip internal build steps and directly deploy script [boolean] [default: false] --ip IP address to listen on [string] --port Port to listen on [number] --inspector-port Port for devtools to connect to [number] @@ -1354,10 +1355,6 @@ describe("wrangler dev", () => { --https-key-path Path to a custom certificate key [string] --https-cert-path Path to a custom certificate [string] --local-upstream Host to act as origin in local mode, defaults to dev.host or route [string] - --legacy-assets (Experimental) Static assets to be served [string] - --site Root folder of static assets for Workers Sites [string] - --site-include Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. [array] - --site-exclude Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded. [array] --upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"] --var A key-value pair to be injected into the script as a variable [array] --define A key-value pair to be substituted in the script [array] @@ -1388,7 +1385,7 @@ describe("wrangler dev", () => { await expect( runWrangler("dev --legacy-assets abc --site xyz") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); }); @@ -1403,7 +1400,7 @@ describe("wrangler dev", () => { await expect( runWrangler("dev --legacy-assets abc") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); }); @@ -1416,7 +1413,7 @@ describe("wrangler dev", () => { await expect( runWrangler("dev --site xyz") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); }); @@ -1432,7 +1429,7 @@ describe("wrangler dev", () => { await expect( runWrangler("dev --legacy-assets abc") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Legacy Assets and Workers Sites in the same Worker.]` + `[Error: Cannot use legacy assets and Workers Sites in the same Worker.]` ); }); @@ -1452,71 +1449,57 @@ describe("wrangler dev", () => { expect((Dev as Mock).mock.calls[2][0].isWorkersSite).toEqual(false); }); - it("should point to --legacy-assets if --assets is used", async () => { + it("should warn if --legacy-assets is used", async () => { writeWranglerToml({ main: "./index.js", }); fs.writeFileSync("index.js", `export default {};`); - await runWrangler('dev --assets "./assets"'); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "", - "out": "", - "warn": "▲ [WARNING] The --assets argument is experimental. We are going to be changing the behavior of this experimental command after August 15th. + await runWrangler('dev --legacy-assets "./assets"'); + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] The --legacy-assets argument has been deprecated. Please use --assets instead. - Releases of wrangler after this date will no longer support current functionality. - Please shift to the --legacy-assets command to preserve the current functionality. + To learn more about Workers with assets, visit our documentation at + https://developers.cloudflare.com/workers/frameworks/. - ", - } + " `); }); - it("should warn if --legacy-assets is used", async () => { + it("should warn if config.legacy_assets is used", async () => { writeWranglerToml({ main: "./index.js", + legacy_assets: "./assets", }); + fs.writeFileSync("index.js", `export default {};`); - await runWrangler('dev --legacy-assets "./assets"'); - expect(std).toMatchInlineSnapshot(` - Object { - "debug": "", - "err": "", - "info": "", - "out": "", - "warn": "▲ [WARNING] The --legacy-assets argument is experimental and may change or break at any time. + await runWrangler("dev"); + expect(std.warn).toMatchInlineSnapshot(` + "▲ [WARNING] Processing wrangler.toml configuration: - ", - } - `); - }); + - Deprecation: \\"legacy_assets\\": + The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead. - it("should warn if config.legacy_assets is used", async () => { - writeWranglerToml({ - main: "./index.js", - legacy_assets: "./assets", - }); + " + `); }); }); - describe("--experimental-assets", () => { - it("should not require entry point if using --experimental-assets", async () => { + describe("--assets", () => { + it("should not require entry point if using --assets", async () => { fs.mkdirSync("assets"); writeWranglerToml({ - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, }); await runWrangler("dev"); }); - it("should error if config.site and config.experimental_assets are used together", async () => { + it("should error if config.site and config.assets are used together", async () => { writeWranglerToml({ main: "./index.js", - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, site: { bucket: "xyz", }, @@ -1527,13 +1510,13 @@ describe("wrangler dev", () => { runWrangler("dev") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Workers Sites in the same Worker. - Please remove either the \`site\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and Workers Sites in the same Worker. + Please remove either the \`site\` or \`assets\` field from your configuration file.] ` ); }); - it("should error if config.site and --experimental-assets are used together", async () => { + it("should error if config.site and --assets are used together", async () => { writeWranglerToml({ main: "./index.js", site: { @@ -1543,19 +1526,19 @@ describe("wrangler dev", () => { fs.writeFileSync("index.js", `export default {};`); fs.mkdirSync("assets"); await expect( - runWrangler("dev --experimental-assets assets") + runWrangler("dev --assets assets") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Workers Sites in the same Worker. - Please remove either the \`site\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and Workers Sites in the same Worker. + Please remove either the \`site\` or \`assets\` field from your configuration file.] ` ); }); - it("should error if config.experimental_assets and config.legacy_assets are used together", async () => { + it("should error if config.assets and config.legacy_assets are used together", async () => { writeWranglerToml({ main: "./index.js", - experimental_assets: { directory: "assets" }, + assets: { directory: "assets" }, legacy_assets: { bucket: "xyz", include: [], @@ -1570,26 +1553,26 @@ describe("wrangler dev", () => { runWrangler("dev") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Legacy Assets in the same Worker. - Please remove either the \`legacy_assets\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and legacy assets in the same Worker. + Please remove either the \`legacy_assets\` or \`assets\` field from your configuration file.] ` ); }); - it("should error if --experimental-assets and --legacy-assets are used together", async () => { + it("should error if --assets and --legacy-assets are used together", async () => { fs.writeFileSync("index.js", `export default {};`); fs.mkdirSync("assets"); await expect( - runWrangler("dev --experimental-assets assets --legacy-assets assets") + runWrangler("dev --assets assets --legacy-assets assets") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Legacy Assets in the same Worker. - Please remove either the \`legacy_assets\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and legacy assets in the same Worker. + Please remove either the \`legacy_assets\` or \`assets\` field from your configuration file.] ` ); }); - it("should error if --experimental-assets and config.legacy_assets are used together", async () => { + it("should error if --assets and config.legacy_assets are used together", async () => { writeWranglerToml({ main: "./index.js", legacy_assets: { @@ -1603,19 +1586,19 @@ describe("wrangler dev", () => { fs.writeFileSync("index.js", `export default {};`); fs.mkdirSync("assets"); await expect( - runWrangler("dev --experimental-assets assets") + runWrangler("dev --assets assets") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Legacy Assets in the same Worker. - Please remove either the \`legacy_assets\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and legacy assets in the same Worker. + Please remove either the \`legacy_assets\` or \`assets\` field from your configuration file.] ` ); }); - it("should error if config.experimental_assets and --legacy-assets are used together", async () => { + it("should error if config.assets and --legacy-assets are used together", async () => { writeWranglerToml({ main: "./index.js", - experimental_assets: { + assets: { directory: "xyz", }, }); @@ -1625,98 +1608,96 @@ describe("wrangler dev", () => { runWrangler("dev --legacy-assets xyz") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets and Legacy Assets in the same Worker. - Please remove either the \`legacy_assets\` or \`experimental_assets\` field from your configuration file.] + [Error: Cannot use assets and legacy assets in the same Worker. + Please remove either the \`legacy_assets\` or \`assets\` field from your configuration file.] ` ); }); it("should error if an ASSET binding is provided without a user Worker", async () => { writeWranglerToml({ - experimental_assets: { directory: "assets", binding: "ASSETS" }, + assets: { directory: "assets", binding: "ASSETS" }, }); await expect( runWrangler("dev") ).rejects.toThrowErrorMatchingInlineSnapshot( ` - [Error: Cannot use Experimental Assets with a binding in an assets-only Worker. + [Error: Cannot use assets with a binding in an assets-only Worker. Please remove the asset binding from your configuration file, or provide a Worker script in your configuration file (\`main\`).] ` ); }); - it("should error if directory specified by '--experimental-assets' command line argument does not exist", async () => { + it("should error if directory specified by '--assets' command line argument does not exist", async () => { writeWranglerToml({ main: "./index.js", }); fs.writeFileSync("index.js", `export default {};`); - await expect( - runWrangler("dev --experimental-assets abc") - ).rejects.toThrow( + await expect(runWrangler("dev --assets abc")).rejects.toThrow( new RegExp( - '^The directory specified by the "--experimental-assets" command line argument does not exist:[Ss]*' + '^The directory specified by the "--assets" command line argument does not exist:[Ss]*' ) ); }); - it("should error if directory specified by '[experimental_assets]' configuration key does not exist", async () => { + it("should error if directory specified by '[assets]' configuration key does not exist", async () => { writeWranglerToml({ main: "./index.js", - experimental_assets: { + assets: { directory: "abc", }, }); fs.writeFileSync("index.js", `export default {};`); await expect(runWrangler("dev")).rejects.toThrow( new RegExp( - '^The directory specified by the "experimental_assets.directory" field in your configuration file does not exist:[Ss]*' + '^The directory specified by the "assets.directory" field in your configuration file does not exist:[Ss]*' ) ); }); - it("should error if --experimental-assets and config.tail_consumers are used together", async () => { + it("should error if --assets and config.tail_consumers are used together", async () => { writeWranglerToml({ tail_consumers: [{ service: "" }], }); fs.mkdirSync("public"); await expect( - runWrangler("dev --experimental-assets public") + runWrangler("dev --assets public") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Experimental Assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets.]` + `[Error: Cannot use assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets.]` ); }); - it("should error if config.experimental_assets and config.tail_consumers are used together", async () => { + it("should error if config.assets and config.tail_consumers are used together", async () => { writeWranglerToml({ - experimental_assets: { directory: "./public" }, + assets: { directory: "./public" }, tail_consumers: [{ service: "" }], }); fs.mkdirSync("public"); await expect( runWrangler("dev") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Experimental Assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets.]` + `[Error: Cannot use assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets.]` ); }); - it("should error if --experimental-assets and --remote are used together", async () => { + it("should error if --assets and --remote are used together", async () => { fs.mkdirSync("public"); await expect( - runWrangler("dev --experimental-assets public --remote") + runWrangler("dev --assets public --remote") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]` + `[Error: Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]` ); }); - it("should error if config.experimental_assets and --remote are used together", async () => { + it("should error if config.assets and --remote are used together", async () => { writeWranglerToml({ - experimental_assets: { directory: "./public" }, + assets: { directory: "./public" }, }); fs.mkdirSync("public"); await expect( runWrangler("dev --remote") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]` + `[Error: Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use \`wrangler dev\`.]` ); }); }); diff --git a/packages/wrangler/src/__tests__/helpers/mock-upload-worker.ts b/packages/wrangler/src/__tests__/helpers/mock-upload-worker.ts index ae86fd27b0be..691299b6156e 100644 --- a/packages/wrangler/src/__tests__/helpers/mock-upload-worker.ts +++ b/packages/wrangler/src/__tests__/helpers/mock-upload-worker.ts @@ -30,7 +30,7 @@ export function mockUploadWorkerRequest( tag?: string; expectedDispatchNamespace?: string; expectedScriptName?: string; - expectedExperimentalAssets?: { + expectedAssets?: { jwt: string; config: AssetConfig; }; @@ -112,8 +112,8 @@ export function mockUploadWorkerRequest( if ("expectedLimits" in options) { expect(metadata.limits).toEqual(expectedLimits); } - if ("expectedExperimentalAssets" in options) { - expect(metadata.assets).toEqual(expectedExperimentalAssets); + if ("expectedAssets" in options) { + expect(metadata.assets).toEqual(expectedAssets); } if ("expectedObservability" in options) { expect(metadata.observability).toEqual(expectedObservability); @@ -158,9 +158,9 @@ export function mockUploadWorkerRequest( const { available_on_subdomain = true, expectedEntry, - expectedExperimentalAssets, + expectedAssets, // Allow setting expectedMainModule to undefined to test static-asset only uploads - expectedMainModule = expectedExperimentalAssets + expectedMainModule = expectedAssets ? options.expectedMainModule : "index.js", expectedType = "esm", diff --git a/packages/wrangler/src/__tests__/type-generation.test.ts b/packages/wrangler/src/__tests__/type-generation.test.ts index 78079533aa27..c41cd5ff2090 100644 --- a/packages/wrangler/src/__tests__/type-generation.test.ts +++ b/packages/wrangler/src/__tests__/type-generation.test.ts @@ -218,7 +218,7 @@ const bindingsConfigMock: Omit< { type: "CompiledWasm", globs: ["**/*.wasm"], fallthrough: true }, ], pipelines: [], - experimental_assets: { + assets: { binding: "ASSETS_BINDING", directory: "/assets", }, diff --git a/packages/wrangler/src/api/dev.ts b/packages/wrangler/src/api/dev.ts index dedd5313691d..ecf5dcc506e3 100644 --- a/packages/wrangler/src/api/dev.ts +++ b/packages/wrangler/src/api/dev.ts @@ -23,7 +23,7 @@ export interface UnstableDevOptions { localProtocol?: "http" | "https"; // Protocol to listen to requests on, defaults to http. httpsKeyPath?: string; httpsCertPath?: string; - experimentalAssets?: string; // Static assets to be served + assets?: string; // Static assets to be served legacyAssets?: string; // Static assets to be served site?: string; // Root folder of static assets for Workers Sites siteInclude?: string[]; // Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. @@ -189,7 +189,7 @@ export async function unstable_dev( localProtocol: options?.localProtocol, httpsKeyPath: options?.httpsKeyPath, httpsCertPath: options?.httpsCertPath, - experimentalAssets: undefined, + assets: undefined, legacyAssets: options?.legacyAssets, site: options?.site, // Root folder of static assets for Workers Sites siteInclude: options?.siteInclude, // Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded. diff --git a/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts b/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts index 06334fdd24d1..be4af53339ba 100644 --- a/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts +++ b/packages/wrangler/src/api/pages/create-worker-bundle-contents.ts @@ -69,7 +69,7 @@ function createWorkerBundleFormData( pipelines: undefined, logfwdr: undefined, unsafe: undefined, - experimental_assets: undefined, + assets: undefined, }; // The upload API only accepts an empty string or no specified placement for the "off" mode. @@ -96,7 +96,7 @@ function createWorkerBundleFormData( placement: placement, tail_consumers: undefined, limits: config?.limits, - experimental_assets: undefined, + assets: undefined, observability: undefined, }; diff --git a/packages/wrangler/src/api/startDevWorker/ConfigController.ts b/packages/wrangler/src/api/startDevWorker/ConfigController.ts index 15663ad1e277..fa9891a65947 100644 --- a/packages/wrangler/src/api/startDevWorker/ConfigController.ts +++ b/packages/wrangler/src/api/startDevWorker/ConfigController.ts @@ -9,6 +9,7 @@ import { getScriptName, isLegacyEnv, } from "../.."; +import { processAssetsArg } from "../../assets"; import { printBindings, readConfig } from "../../config"; import { getEntry } from "../../deployment-bundle/entry"; import { @@ -21,7 +22,6 @@ import { import { getLocalPersistencePath } from "../../dev/get-local-persistence-path"; import { getClassNamesWhichUseSQLite } from "../../dev/validate-dev-props"; import { UserError } from "../../errors"; -import { processExperimentalAssetsArg } from "../../experimental-assets"; import { logger } from "../../logger"; import { getAccountId, requireApiToken } from "../../user"; import { memoizeGetPort } from "../../utils/memoizeGetPort"; @@ -63,7 +63,7 @@ async function resolveDevConfig( routes: input.triggers?.filter( (t): t is Extract => t.type === "route" ), - experimentalAssets: input.experimental?.assets?.directory, + assets: input?.assets?.directory, }, config ); @@ -165,7 +165,7 @@ async function resolveTriggers( routes: input.triggers?.filter( (t): t is Extract => t.type === "route" ), - experimentalAssets: input.experimental?.assets?.directory, + assets: input?.assets?.directory, }, config ); @@ -209,10 +209,10 @@ async function resolveConfig( legacyAssets: Boolean(legacyAssets), script: input.entrypoint, moduleRoot: input.build?.moduleRoot, - // getEntry only needs to know if experimental_assets was specified. + // getEntry only needs to know if assets was specified. // The actualy value is not relevant here, which is why not passing - // the entire ExperimentalAssets object is fine. - experimentalAssets: input?.experimental?.assets?.directory, + // the entire Assets object is fine. + assets: input?.assets?.directory, }, config, "dev" @@ -222,9 +222,9 @@ async function resolveConfig( const { bindings, unsafe } = await resolveBindings(config, input); - const experimentalAssetsOptions = processExperimentalAssetsArg( + const assetsOptions = processAssetsArg( { - experimentalAssets: input?.experimental?.assets?.directory, + assets: input?.assets?.directory, script: input.entrypoint, }, config @@ -275,9 +275,7 @@ async function resolveConfig( capnp: input.unsafe?.capnp ?? unsafe?.capnp, metadata: input.unsafe?.metadata ?? unsafe?.metadata, }, - experimental: { - assets: experimentalAssetsOptions, - }, + assets: assetsOptions, } satisfies StartDevWorkerOptions; if (resolved.legacy.legacyAssets && resolved.legacy.site) { @@ -421,12 +419,12 @@ export class ConfigController extends Controller { void this.#ensureWatchingConfig(fileConfig.configPath); - const experimentalAssets = processExperimentalAssetsArg( - { experimentalAssets: input.experimental?.assets?.directory }, + const assets = processAssetsArg( + { assets: input?.assets?.directory }, fileConfig ); - if (experimentalAssets) { - void this.#ensureWatchingAssets(experimentalAssets.directory); + if (assets) { + void this.#ensureWatchingAssets(assets.directory); } const resolvedConfig = await resolveConfig(fileConfig, input); diff --git a/packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts b/packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts index 10dcd4e30d6e..be72911bbb70 100644 --- a/packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts +++ b/packages/wrangler/src/api/startDevWorker/LocalRuntimeController.ts @@ -101,7 +101,7 @@ async function convertToConfigBundle( includePatterns: event.config.legacy?.site?.include ?? [], } : undefined, - experimentalAssets: event.config.experimental?.assets, + assets: event.config?.assets, initialPort: undefined, initialIp: "127.0.0.1", rules: [], diff --git a/packages/wrangler/src/api/startDevWorker/types.ts b/packages/wrangler/src/api/startDevWorker/types.ts index e2a02e40bb0f..433b4b4f2ba7 100644 --- a/packages/wrangler/src/api/startDevWorker/types.ts +++ b/packages/wrangler/src/api/startDevWorker/types.ts @@ -1,3 +1,4 @@ +import type { AssetsOptions } from "../../assets"; import type { Config } from "../../config"; import type { CustomDomainRoute, @@ -29,7 +30,6 @@ import type { import type { WorkerRegistry } from "../../dev-registry"; import type { CfAccount } from "../../dev/create-worker-preview"; import type { EsbuildBundle } from "../../dev/use-esbuild"; -import type { ExperimentalAssetsOptions } from "../../experimental-assets"; import type { ConfigController } from "./ConfigController"; import type { DispatchFetch, @@ -165,9 +165,7 @@ export interface StartDevWorkerInput { enableServiceEnvironments?: boolean; }; unsafe?: Omit; - experimental?: { - assets?: Omit; - }; + assets?: Omit; } export type StartDevWorkerOptions = StartDevWorkerInput & { diff --git a/packages/wrangler/src/api/startDevWorker/utils.ts b/packages/wrangler/src/api/startDevWorker/utils.ts index 383bf71b4f85..e3d3f019b59b 100644 --- a/packages/wrangler/src/api/startDevWorker/utils.ts +++ b/packages/wrangler/src/api/startDevWorker/utils.ts @@ -240,7 +240,7 @@ export function convertCfWorkerInitBindingstoBindings( } break; } - case "experimental_assets": { + case "assets": { output[info["binding"]] = { type: "assets" }; break; } @@ -287,7 +287,7 @@ export async function convertBindingsToCfWorkerInitBindings( mtls_certificates: undefined, logfwdr: undefined, unsafe: undefined, - experimental_assets: undefined, + assets: undefined, pipelines: undefined, }; diff --git a/packages/wrangler/src/experimental-assets.ts b/packages/wrangler/src/assets.ts similarity index 83% rename from packages/wrangler/src/experimental-assets.ts rename to packages/wrangler/src/assets.ts index f2d871ee3b3b..09f3b9a58e15 100644 --- a/packages/wrangler/src/experimental-assets.ts +++ b/packages/wrangler/src/assets.ts @@ -22,7 +22,7 @@ import { APIError } from "./parse"; import { dedent } from "./utils/dedent"; import { createPatternMatcher } from "./utils/filesystem"; import type { Config } from "./config"; -import type { ExperimentalAssets } from "./config/environment"; +import type { Assets } from "./config/environment"; import type { DeployArgs } from "./deploy"; import type { StartDevOptions } from "./dev"; import type { AssetConfig, RoutingConfig } from "@cloudflare/workers-shared"; @@ -44,7 +44,7 @@ const BULK_UPLOAD_CONCURRENCY = 3; const MAX_UPLOAD_ATTEMPTS = 5; const MAX_UPLOAD_GATEWAY_ERRORS = 5; -export const syncExperimentalAssets = async ( +export const syncAssets = async ( accountId: string | undefined, scriptName: string, assetDirectory: string @@ -296,70 +296,59 @@ function logAssetUpload(line: string, diffCount: number) { } /** - * Returns the base path of the experimental assets to upload. + * Returns the base path of the assets to upload. * */ -export function getExperimentalAssetsBasePath( +export function getAssetsBasePath( config: Config, - experimentalAssetsCommandLineArg: string | undefined + assetsCommandLineArg: string | undefined ): string { - return experimentalAssetsCommandLineArg + return assetsCommandLineArg ? process.cwd() : path.resolve(path.dirname(config.configPath ?? "wrangler.toml")); } -export type ExperimentalAssetsOptions = Pick< - ExperimentalAssets, - "directory" | "binding" -> & { +export type AssetsOptions = Pick & { routingConfig: RoutingConfig; assetConfig: AssetConfig; }; -export function processExperimentalAssetsArg( - args: { experimentalAssets: string | undefined; script?: string }, +export function processAssetsArg( + args: { assets: string | undefined; script?: string }, config: Config -): ExperimentalAssetsOptions | undefined { - const experimentalAssets = args.experimentalAssets - ? { directory: args.experimentalAssets } - : config.experimental_assets; +): AssetsOptions | undefined { + const assets = args.assets ? { directory: args.assets } : config.assets; - if (!experimentalAssets) { + if (!assets) { return; } - const experimentalAssetsBasePath = getExperimentalAssetsBasePath( - config, - args.experimentalAssets - ); - const resolvedExperimentalAssetsPath = path.resolve( - experimentalAssetsBasePath, - experimentalAssets.directory - ); + const assetsBasePath = getAssetsBasePath(config, args.assets); + const resolvedAssetsPath = path.resolve(assetsBasePath, assets.directory); - if (!existsSync(resolvedExperimentalAssetsPath)) { - const sourceOfTruthMessage = args.experimentalAssets - ? '"--experimental-assets" command line argument' - : '"experimental_assets.directory" field in your configuration file'; + if (!existsSync(resolvedAssetsPath)) { + const sourceOfTruthMessage = args.assets + ? '"--assets" command line argument' + : '"assets.directory" field in your configuration file'; throw new UserError( `The directory specified by the ${sourceOfTruthMessage} does not exist:\n` + - `${resolvedExperimentalAssetsPath}` + `${resolvedAssetsPath}` ); } - experimentalAssets.directory = resolvedExperimentalAssetsPath; + assets.directory = resolvedAssetsPath; const routingConfig = { has_user_worker: Boolean(args.script || config.main), }; // defaults are set in asset worker const assetConfig = { - html_handling: config.experimental_assets?.html_handling, - not_found_handling: config.experimental_assets?.not_found_handling, + html_handling: config.assets?.html_handling, + not_found_handling: config.assets?.not_found_handling, }; return { - ...experimentalAssets, + ...assets, routingConfig, assetConfig, }; @@ -374,14 +363,8 @@ export function processExperimentalAssetsArg( */ export function validateAssetsArgsAndConfig( args: - | Pick< - StartDevOptions, - "legacyAssets" | "site" | "experimentalAssets" | "script" - > - | Pick< - DeployArgs, - "legacyAssets" | "site" | "experimentalAssets" | "script" - >, + | Pick + | Pick, config: Config ) { /* @@ -389,37 +372,31 @@ export function validateAssetsArgsAndConfig( * - `args.legacyAssets` conflates `legacy-assets` and `assets` */ if ( - (args.experimentalAssets || config.experimental_assets) && + (args.assets || config.assets) && (args.legacyAssets || config.legacy_assets) ) { throw new UserError( - "Cannot use Experimental Assets and Legacy Assets in the same Worker.\n" + - "Please remove either the `legacy_assets` or `experimental_assets` field from your configuration file." + "Cannot use assets and legacy assets in the same Worker.\n" + + "Please remove either the `legacy_assets` or `assets` field from your configuration file." ); } - if ( - (args.experimentalAssets || config.experimental_assets) && - (args.site || config.site) - ) { + if ((args.assets || config.assets) && (args.site || config.site)) { throw new UserError( - "Cannot use Experimental Assets and Workers Sites in the same Worker.\n" + - "Please remove either the `site` or `experimental_assets` field from your configuration file." + "Cannot use assets and Workers Sites in the same Worker.\n" + + "Please remove either the `site` or `assets` field from your configuration file." ); } - if ( - (args.experimentalAssets || config.experimental_assets) && - config.tail_consumers?.length - ) { + if ((args.assets || config.assets) && config.tail_consumers?.length) { throw new UserError( - "Cannot use Experimental Assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets." + "Cannot use assets and tail consumers in the same Worker. Tail Workers are not yet supported for Workers with assets." ); } - if (!(args.script || config.main) && config.experimental_assets?.binding) { + if (!(args.script || config.main) && config.assets?.binding) { throw new UserError( - "Cannot use Experimental Assets with a binding in an assets-only Worker.\n" + + "Cannot use assets with a binding in an assets-only Worker.\n" + "Please remove the asset binding from your configuration file, or provide a Worker script in your configuration file (`main`)." ); } diff --git a/packages/wrangler/src/config/config.ts b/packages/wrangler/src/config/config.ts index e0aa3332c917..e535efb98752 100644 --- a/packages/wrangler/src/config/config.ts +++ b/packages/wrangler/src/config/config.ts @@ -115,9 +115,11 @@ export interface ConfigFields { | undefined; /** - * Serve a folder of static assets with your Worker, without any additional code. - * This can either be a string, or an object with additional config fields. - * Only one of assets and legacy_assets can be used. + * Old behaviour of serving a folder of static assets with your Worker, + * without any additional code. + * This can either be a string, or an object with additional config + * fields. + * Will be deprecated in the near future in favor of `assets`. */ legacy_assets: | { @@ -265,22 +267,6 @@ export interface DeprecatedConfigFields { * @deprecated */ miniflare?: unknown; - - /** - * Serve a folder of static assets with your Worker, without any additional code. - * This can either be a string, or an object with additional config fields. - * Only one of assets and legacy_assets can be used. - */ - assets?: - | { - bucket: string; - include: string[]; - exclude: string[]; - browser_TTL: number | undefined; - serve_single_page_app: boolean; - } - | string - | undefined; } interface EnvironmentMap { @@ -389,7 +375,7 @@ export const defaultWranglerConfig: Config = { logfwdr: { bindings: [] }, logpush: undefined, upload_source_maps: undefined, - experimental_assets: undefined, + assets: undefined, observability: { enabled: true }, /** NON-INHERITABLE ENVIRONMENT FIELDS **/ diff --git a/packages/wrangler/src/config/environment.ts b/packages/wrangler/src/config/environment.ts index d23dd0aee148..1066efae3106 100644 --- a/packages/wrangler/src/config/environment.ts +++ b/packages/wrangler/src/config/environment.ts @@ -347,9 +347,11 @@ interface EnvironmentInheritable { /** * Specify the directory of static assets to deploy/serve * + * More details at https://developers.cloudflare.com/workers/frameworks/ + * * @inheritable */ - experimental_assets: ExperimentalAssets | undefined; + assets: Assets | undefined; /** * Specify the observability behavior of the Worker. @@ -905,7 +907,7 @@ export interface UserLimits { cpu_ms: number; } -export type ExperimentalAssets = { +export type Assets = { /** Absolute path to assets directory */ directory: string; binding?: string; diff --git a/packages/wrangler/src/config/validation.ts b/packages/wrangler/src/config/validation.ts index 3c41a1d50337..80b2ac2774f9 100644 --- a/packages/wrangler/src/config/validation.ts +++ b/packages/wrangler/src/config/validation.ts @@ -31,10 +31,10 @@ import { } from "./validation-helpers"; import type { Config, DevConfig, RawConfig, RawDevConfig } from "./config"; import type { + Assets, DeprecatedUpload, DispatchNamespaceOutbound, Environment, - ExperimentalAssets, Observability, RawEnvironment, Rule, @@ -248,22 +248,11 @@ export function normalizeAndValidateConfig( deprecated( diagnostics, rawConfig, - "assets", - `The \`assets\` feature is experimental. We are going to be changing its behavior after August 15th.\n` + - `Releases of wrangler after this date will no longer support current functionality.\n` + - `Please shift to \`legacy_assets\` to preserve the current functionality. `, - false, - "Behavior change" + "legacy_assets", + `The \`legacy_assets\` feature has been deprecated. Please use \`assets\` instead.`, + false ); - experimental(diagnostics, rawConfig, "legacy_assets"); - - if (rawConfig.assets && rawConfig.legacy_assets) { - diagnostics.errors.push( - "Expected only one of `assets` or `legacy_assets`." - ); - } - // Process the top-level default environment configuration. const config: Config = { configPath, @@ -314,7 +303,7 @@ export function normalizeAndValidateConfig( diagnostics, "top-level", Object.keys(rawConfig), - [...Object.keys(config), "env", "$schema", "assets"] + [...Object.keys(config), "env", "$schema"] ); return { config, diagnostics }; @@ -682,15 +671,14 @@ function normalizeAndValidateLegacyAssets( configPath: string | undefined, rawConfig: RawConfig ): Config["legacy_assets"] { - // So that the final config object only has the one legacy_assets property - const mergedAssetsConfig = rawConfig["legacy_assets"] ?? rawConfig["assets"]; + const legacyAssetsConfig = rawConfig["legacy_assets"]; // Even though the type doesn't say it, // we allow for a string input in the config, // so let's normalise it - if (typeof mergedAssetsConfig === "string") { + if (typeof legacyAssetsConfig === "string") { return { - bucket: mergedAssetsConfig, + bucket: legacyAssetsConfig, include: [], exclude: [], browser_TTL: undefined, @@ -698,15 +686,13 @@ function normalizeAndValidateLegacyAssets( }; } - if (mergedAssetsConfig === undefined) { + if (legacyAssetsConfig === undefined) { return undefined; } - const fieldName = rawConfig["assets"] ? "assets" : "legacy_assets"; - - if (typeof mergedAssetsConfig !== "object") { + if (typeof legacyAssetsConfig !== "object") { diagnostics.errors.push( - `Expected the \`${fieldName}\` field to be a string or an object, but got ${typeof mergedAssetsConfig}.` + `Expected the \`legacy_assets\` field to be a string or an object, but got ${typeof legacyAssetsConfig}.` ); return undefined; } @@ -718,17 +704,28 @@ function normalizeAndValidateLegacyAssets( browser_TTL, serve_single_page_app, ...rest - } = mergedAssetsConfig; + } = legacyAssetsConfig; - validateAdditionalProperties(diagnostics, fieldName, Object.keys(rest), []); + validateAdditionalProperties( + diagnostics, + "legacy_assets", + Object.keys(rest), + [] + ); - validateRequiredProperty(diagnostics, fieldName, "bucket", bucket, "string"); - validateTypedArray(diagnostics, `${fieldName}.include`, include, "string"); - validateTypedArray(diagnostics, `${fieldName}.exclude`, exclude, "string"); + validateRequiredProperty( + diagnostics, + "legacy_assets", + "bucket", + bucket, + "string" + ); + validateTypedArray(diagnostics, `legacy_assets.include`, include, "string"); + validateTypedArray(diagnostics, `legacy_assets.exclude`, exclude, "string"); validateOptionalProperty( diagnostics, - fieldName, + "legacy_assets", "browser_TTL", browser_TTL, "number" @@ -736,7 +733,7 @@ function normalizeAndValidateLegacyAssets( validateOptionalProperty( diagnostics, - fieldName, + "legacy_assets", "serve_single_page_app", serve_single_page_app, "boolean" @@ -1236,11 +1233,11 @@ function normalizeAndValidateEnvironment( isObjectWith("crons"), { crons: [] } ), - experimental_assets: inheritable( + assets: inheritable( diagnostics, topLevelEnv, rawEnv, - "experimental_assets", + "assets", validateAssetsConfig, undefined ), @@ -2090,7 +2087,7 @@ const validateAssetsConfig: ValidatorFn = (diagnostics, field, value) => { diagnostics, field, "directory", - (value as ExperimentalAssets).directory, + (value as Assets).directory, "string" ) && isValid; @@ -2098,7 +2095,7 @@ const validateAssetsConfig: ValidatorFn = (diagnostics, field, value) => { isNonEmptyString( diagnostics, `${field}.directory`, - (value as ExperimentalAssets).directory, + (value as Assets).directory, undefined ) && isValid; @@ -2107,7 +2104,7 @@ const validateAssetsConfig: ValidatorFn = (diagnostics, field, value) => { diagnostics, field, "binding", - (value as ExperimentalAssets).binding, + (value as Assets).binding, "string" ) && isValid; @@ -2116,7 +2113,7 @@ const validateAssetsConfig: ValidatorFn = (diagnostics, field, value) => { diagnostics, field, "html_handling", - (value as ExperimentalAssets).html_handling, + (value as Assets).html_handling, "string", [ "auto-trailing-slash", @@ -2131,7 +2128,7 @@ const validateAssetsConfig: ValidatorFn = (diagnostics, field, value) => { diagnostics, field, "not_found_handling", - (value as ExperimentalAssets).not_found_handling, + (value as Assets).not_found_handling, "string", ["single-page-application", "404-page", "none"] ) && isValid; diff --git a/packages/wrangler/src/deploy/deploy.ts b/packages/wrangler/src/deploy/deploy.ts index b180c5eda373..2c3c4bc21b18 100644 --- a/packages/wrangler/src/deploy/deploy.ts +++ b/packages/wrangler/src/deploy/deploy.ts @@ -3,6 +3,7 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { URLSearchParams } from "node:url"; import { cancel } from "@cloudflare/cli"; +import { syncAssets } from "../assets"; import { fetchListResult, fetchResult } from "../cfetch"; import { printBindings } from "../config"; import { bundleWorker } from "../deployment-bundle/bundle"; @@ -26,7 +27,6 @@ import { loadSourceMaps } from "../deployment-bundle/source-maps"; import { confirm } from "../dialogs"; import { getMigrationsToUpload } from "../durable"; import { UserError } from "../errors"; -import { syncExperimentalAssets } from "../experimental-assets"; import { logger } from "../logger"; import { getMetricsUsageHeaders } from "../metrics"; import { isNavigatorDefined } from "../navigator-user-agent"; @@ -52,6 +52,7 @@ import { } from "../versions/api"; import { confirmLatestDeploymentOverwrite } from "../versions/deploy"; import { getZoneForRoute } from "../zones"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { CustomDomainRoute, @@ -66,7 +67,6 @@ import type { CfPlacement, CfWorkerInit, } from "../deployment-bundle/worker"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import type { PostQueueBody, PostTypedConsumerBody } from "../queues/client"; import type { LegacyAssetPaths } from "../sites"; import type { RetrieveSourceMapFunction } from "../sourcemap"; @@ -82,7 +82,7 @@ type Props = { compatibilityDate: string | undefined; compatibilityFlags: string[] | undefined; legacyAssetPaths: LegacyAssetPaths | undefined; - experimentalAssetsOptions: ExperimentalAssetsOptions | undefined; + assetsOptions: AssetsOptions | undefined; vars: Record | undefined; defines: Record | undefined; alias: Record | undefined; @@ -171,10 +171,7 @@ function errIsStartupErr(err: unknown): err is ParseError & { code: 10021 } { return false; } -export const validateRoutes = ( - routes: Route[], - hasExperimentalAssets: boolean -) => { +export const validateRoutes = (routes: Route[], hasAssets: boolean) => { const invalidRoutes: Record = {}; for (const route of routes) { if (typeof route !== "string" && route.custom_domain) { @@ -190,7 +187,7 @@ export const validateRoutes = ( `Paths are not allowed in Custom Domains` ); } - } else if (hasExperimentalAssets) { + } else if (hasAssets) { const pattern = typeof route === "string" ? route : route.pattern; const components = pattern.split("/"); @@ -435,7 +432,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m const routes = props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? []; - validateRoutes(routes, Boolean(props.experimentalAssetsOptions)); + validateRoutes(routes, Boolean(props.assetsOptions)); const jsxFactory = props.jsxFactory || config.jsx_factory; const jsxFragment = props.jsxFragment || config.jsx_fragment; @@ -630,14 +627,10 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m }) : undefined; - // Upload assets if experimental assets is being used - const experimentalAssetsJwt = - props.experimentalAssetsOptions && !props.dryRun - ? await syncExperimentalAssets( - accountId, - scriptName, - props.experimentalAssetsOptions.directory - ) + // Upload assets if assets is being used + const assetsJwt = + props.assetsOptions && !props.dryRun + ? await syncAssets(accountId, scriptName, props.assetsOptions.directory) : undefined; const legacyAssets = await syncLegacyAssets( @@ -687,8 +680,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m mtls_certificates: config.mtls_certificates, pipelines: config.pipelines, logfwdr: config.logfwdr, - experimental_assets: config.experimental_assets?.binding - ? { binding: config.experimental_assets.binding } + assets: config.assets?.binding + ? { binding: config.assets.binding } : undefined, unsafe: { bindings: config.unsafe.bindings, @@ -736,12 +729,12 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m placement, tail_consumers: config.tail_consumers, limits: config.limits, - experimental_assets: - props.experimentalAssetsOptions && experimentalAssetsJwt + assets: + props.assetsOptions && assetsJwt ? { - jwt: experimentalAssetsJwt, - routingConfig: props.experimentalAssetsOptions.routingConfig, - assetConfig: props.experimentalAssetsOptions.assetConfig, + jwt: assetsJwt, + routingConfig: props.assetsOptions.routingConfig, + assetConfig: props.assetsOptions.assetConfig, } : undefined, observability: config.observability, diff --git a/packages/wrangler/src/deploy/index.ts b/packages/wrangler/src/deploy/index.ts index ec35c0097f19..5797def1e47f 100644 --- a/packages/wrangler/src/deploy/index.ts +++ b/packages/wrangler/src/deploy/index.ts @@ -1,12 +1,9 @@ import assert from "node:assert"; import path from "node:path"; +import { processAssetsArg, validateAssetsArgsAndConfig } from "../assets"; import { findWranglerToml, readConfig } from "../config"; import { getEntry } from "../deployment-bundle/entry"; import { UserError } from "../errors"; -import { - processExperimentalAssetsArg, - validateAssetsArgsAndConfig, -} from "../experimental-assets"; import { getRules, getScriptName, @@ -67,12 +64,6 @@ export function deployOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, }) - .option("format", { - choices: ["modules", "service-worker"] as const, - describe: "Choose an entry type", - deprecated: true, - hidden: true, - }) .option("compatibility-date", { describe: "Date to use for compatibility checks", type: "string", @@ -90,42 +81,44 @@ export function deployOptions(yargs: CommonYargsArgv) { type: "boolean", default: false, }) - .option("experimental-public", { - describe: "(Deprecated) Static assets to be served", + .option("assets", { + describe: "Static assets to be served. Replaces Workers Sites.", type: "string", requiresArg: true, + }) + .option("format", { + choices: ["modules", "service-worker"] as const, + describe: "Choose an entry type", deprecated: true, hidden: true, }) - .option("public", { + .option("experimental-public", { describe: "(Deprecated) Static assets to be served", type: "string", requiresArg: true, deprecated: true, hidden: true, }) - .option("legacy-assets", { - describe: "(Experimental) Static assets to be served", - type: "string", - requiresArg: true, - }) - .option("assets", { - describe: "(Experimental) Static assets to be served", + .option("public", { + describe: "(Deprecated) Static assets to be served", type: "string", requiresArg: true, + deprecated: true, hidden: true, }) - .option("experimental-assets", { + .option("legacy-assets", { describe: "Static assets to be served", type: "string", - alias: "x-assets", requiresArg: true, + deprecated: true, hidden: true, }) .option("site", { describe: "Root folder of static assets for Workers Sites", type: "string", requiresArg: true, + hidden: true, + deprecated: true, }) .option("site-include", { describe: @@ -133,6 +126,8 @@ export function deployOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, array: true, + hidden: true, + deprecated: true, }) .option("site-exclude", { describe: @@ -140,6 +135,8 @@ export function deployOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, array: true, + hidden: true, + deprecated: true, }) .option("var", { describe: @@ -246,26 +243,13 @@ export async function deployHandler(args: DeployArgs) { ); } - if (args.assets) { - logger.warn( - `The --assets argument is experimental. We are going to be changing the behavior of this experimental command after August 15th.\n` + - `Releases of wrangler after this date will no longer support current functionality.\n` + - `Please shift to the --legacy-assets command to preserve the current functionality.` - ); - } - if (args.legacyAssets) { logger.warn( - `The --legacy-assets argument is experimental and may change or break at any time.` + `The --legacy-assets argument has been deprecated. Please use --assets instead.\n` + + `To learn more about Workers with assets, visit our documentation at https://developers.cloudflare.com/workers/frameworks/.` ); } - if (args.legacyAssets && args.assets) { - throw new UserError("Cannot use both --assets and --legacy-assets."); - } - - args.legacyAssets = args.legacyAssets ?? args.assets; - const configPath = args.config || (args.script && findWranglerToml(path.dirname(args.script))); const projectRoot = configPath && path.dirname(configPath); @@ -288,13 +272,13 @@ export async function deployHandler(args: DeployArgs) { (args.site || config.site) ) { throw new UserError( - "Cannot use Legacy Assets and Workers Sites in the same Worker." + "Cannot use legacy assets and Workers Sites in the same Worker." ); } validateAssetsArgsAndConfig(args, config); - const experimentalAssetsOptions = processExperimentalAssetsArg(args, config); + const assetsOptions = processAssetsArg(args, config); if (args.latest) { logger.warn( @@ -356,7 +340,7 @@ export async function deployHandler(args: DeployArgs) { jsxFragment: args.jsxFragment, tsconfig: args.tsconfig, routes: args.routes, - experimentalAssetsOptions, + assetsOptions, legacyAssetPaths, legacyEnv: isLegacyEnv(config), minify: args.minify, diff --git a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts index 3ce7b598a751..111936e25b71 100644 --- a/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts +++ b/packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts @@ -141,7 +141,7 @@ export type WorkerMetadataPut = { placement?: CfPlacement; tail_consumers?: CfTailConsumer[]; limits?: CfUserLimits; - // experimental assets (EWC will expect 'assets') + assets?: { jwt: string; config?: AssetConfig; @@ -180,25 +180,22 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { limits, annotations, keep_assets, - experimental_assets, + assets, observability, } = worker; const assetConfig = { - html_handling: experimental_assets?.assetConfig?.html_handling, - not_found_handling: experimental_assets?.assetConfig?.not_found_handling, + html_handling: assets?.assetConfig?.html_handling, + not_found_handling: assets?.assetConfig?.not_found_handling, }; // short circuit if static assets upload only - if ( - experimental_assets && - !experimental_assets.routingConfig.has_user_worker - ) { + if (assets && !assets.routingConfig.has_user_worker) { formData.set( "metadata", JSON.stringify({ assets: { - jwt: experimental_assets.jwt, + jwt: assets.jwt, config: assetConfig, }, ...(compatibility_date && { compatibility_date }), @@ -397,9 +394,9 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { }); } - if (bindings.experimental_assets !== undefined) { + if (bindings.assets !== undefined) { metadataBindings.push({ - name: bindings.experimental_assets.binding, + name: bindings.assets.binding, type: "assets", }); } @@ -589,9 +586,9 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData { ...(limits && { limits }), ...(annotations && { annotations }), ...(keep_assets !== undefined && { keep_assets }), - ...(experimental_assets && { + ...(assets && { assets: { - jwt: experimental_assets.jwt, + jwt: assets.jwt, config: assetConfig, }, }), diff --git a/packages/wrangler/src/deployment-bundle/entry.ts b/packages/wrangler/src/deployment-bundle/entry.ts index 109b8a87a97b..6ded3b4f6a8d 100644 --- a/packages/wrangler/src/deployment-bundle/entry.ts +++ b/packages/wrangler/src/deployment-bundle/entry.ts @@ -37,7 +37,7 @@ export async function getEntry( format?: CfScriptFormat | undefined; legacyAssets?: string | undefined | boolean; moduleRoot?: string; - experimentalAssets?: string | undefined; + assets?: string | undefined; }, config: Config, command: "dev" | "deploy" | "versions upload" | "types" @@ -58,8 +58,8 @@ export async function getEntry( } else if ( args.legacyAssets || config.legacy_assets || - args.experimentalAssets || - config.experimental_assets + args.assets || + config.assets ) { file = path.resolve(getBasePath(), "templates/no-op-worker.js"); } else { diff --git a/packages/wrangler/src/deployment-bundle/worker.ts b/packages/wrangler/src/deployment-bundle/worker.ts index 50fbd57a7e1d..e1d772407bb0 100644 --- a/packages/wrangler/src/deployment-bundle/worker.ts +++ b/packages/wrangler/src/deployment-bundle/worker.ts @@ -222,7 +222,7 @@ export interface CfLogfwdrBinding { destination: string; } -export interface CfExperimentalAssetBinding { +export interface CfAssetsBinding { binding: string; } @@ -284,7 +284,7 @@ export interface CfUserLimits { cpu_ms?: number; } -export interface CfExperimentalAssets { +export interface CfAssets { jwt: string; routingConfig: RoutingConfig; assetConfig?: AssetConfig; @@ -335,7 +335,7 @@ export interface CfWorkerInit { logfwdr: CfLogfwdr | undefined; pipelines: CfPipeline[] | undefined; unsafe: CfUnsafe | undefined; - experimental_assets: CfExperimentalAssetBinding | undefined; + assets: CfAssetsBinding | undefined; }; /** * The raw bindings - this is basically never provided and it'll be the bindings above @@ -356,7 +356,7 @@ export interface CfWorkerInit { limits: CfUserLimits | undefined; annotations?: Record; keep_assets?: boolean | undefined; - experimental_assets: CfExperimentalAssets | undefined; + assets: CfAssets | undefined; observability: Observability | undefined; } diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 2798c47fb7fb..53c98cb7482f 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -10,6 +10,7 @@ import { convertCfWorkerInitBindingstoBindings, extractBindingsOfType, } from "./api/startDevWorker/utils"; +import { processAssetsArg, validateAssetsArgsAndConfig } from "./assets"; import { findWranglerToml, printBindings, readConfig } from "./config"; import { validateRoutes } from "./deploy/deploy"; import { getEntry } from "./deployment-bundle/entry"; @@ -22,10 +23,6 @@ import registerDevHotKeys from "./dev/hotkeys"; import { maybeRegisterLocalWorker } from "./dev/local"; import { startDevServer } from "./dev/start-server"; import { UserError } from "./errors"; -import { - processExperimentalAssetsArg, - validateAssetsArgsAndConfig, -} from "./experimental-assets"; import { run } from "./experimental-flags"; import isInteractive from "./is-interactive"; import { logger } from "./logger"; @@ -88,6 +85,28 @@ export function devOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, }) + .option("compatibility-date", { + describe: "Date to use for compatibility checks", + type: "string", + requiresArg: true, + }) + .option("compatibility-flags", { + describe: "Flags to use for compatibility checks", + alias: "compatibility-flag", + type: "string", + requiresArg: true, + array: true, + }) + .option("latest", { + describe: "Use the latest version of the worker runtime", + type: "boolean", + default: true, + }) + .option("assets", { + describe: "Static assets to be served. Replaces Workers Sites.", + type: "string", + requiresArg: true, + }) // We want to have a --no-bundle flag, but yargs requires that // we also have a --bundle flag (that it adds the --no to by itself) // So we make a --bundle flag, but hide it, and then add a --no-bundle flag @@ -108,23 +127,6 @@ export function devOptions(yargs: CommonYargsArgv) { hidden: true, deprecated: true, }) - .option("compatibility-date", { - describe: "Date to use for compatibility checks", - type: "string", - requiresArg: true, - }) - .option("compatibility-flags", { - describe: "Flags to use for compatibility checks", - alias: "compatibility-flag", - type: "string", - requiresArg: true, - array: true, - }) - .option("latest", { - describe: "Use the latest version of the worker runtime", - type: "boolean", - default: true, - }) .option("ip", { describe: "IP address to listen on", type: "string", @@ -177,23 +179,13 @@ export function devOptions(yargs: CommonYargsArgv) { hidden: true, }) .option("legacy-assets", { - describe: "(Experimental) Static assets to be served", - type: "string", - requiresArg: true, - }) - .option("assets", { - describe: "(Experimental) Static assets to be served", - type: "string", - requiresArg: true, - hidden: true, - }) - .option("experimental-assets", { describe: "Static assets to be served", type: "string", - alias: "x-assets", requiresArg: true, + deprecated: true, hidden: true, }) + .option("public", { describe: "(Deprecated) Static assets to be served", type: "string", @@ -205,6 +197,8 @@ export function devOptions(yargs: CommonYargsArgv) { describe: "Root folder of static assets for Workers Sites", type: "string", requiresArg: true, + hidden: true, + deprecated: true, }) .option("site-include", { describe: @@ -212,6 +206,8 @@ export function devOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, array: true, + hidden: true, + deprecated: true, }) .option("site-exclude", { describe: @@ -219,6 +215,8 @@ export function devOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, array: true, + hidden: true, + deprecated: true, }) .option("upstream-protocol", { describe: "Protocol to forward requests to host on, defaults to https.", @@ -379,26 +377,13 @@ This is currently not supported 😭, but we think that we'll get it to work soo } } - if (args.assets) { - logger.warn( - `The --assets argument is experimental. We are going to be changing the behavior of this experimental command after August 15th.\n` + - `Releases of wrangler after this date will no longer support current functionality.\n` + - `Please shift to the --legacy-assets command to preserve the current functionality.` - ); - } - if (args.legacyAssets) { logger.warn( - `The --legacy-assets argument is experimental and may change or break at any time.` + `The --legacy-assets argument has been deprecated. Please use --assets instead.\n` + + `To learn more about Workers with assets, visit our documentation at https://developers.cloudflare.com/workers/frameworks/.` ); } - if (args.legacyAssets && args.assets) { - throw new UserError("Cannot use both --assets and --legacy-assets."); - } - - args.legacyAssets = args.legacyAssets ?? args.assets; - // use separate watchers for config file and assets directory since // behaviour will be different between the two let configFileWatcher; @@ -471,7 +456,7 @@ export type AdditionalDevProps = { showInteractiveDevSession?: boolean; }; -export type StartDevOptions = Omit & +export type StartDevOptions = DevArguments & // These options can be passed in directly when called with the `wrangler.dev()` API. // They aren't exposed as CLI arguments. AdditionalDevProps & { @@ -608,23 +593,20 @@ export async function startDev(args: StartDevOptions) { (args.site || config.site) ) { throw new UserError( - "Cannot use Legacy Assets and Workers Sites in the same Worker." + "Cannot use legacy assets and Workers Sites in the same Worker." ); } - if ( - (args.experimentalAssets || config.experimental_assets) && - args.remote - ) { + if ((args.assets || config.assets) && args.remote) { throw new UserError( - "Cannot use Experimental Assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`." + "Cannot use assets in remote mode. Workers with assets are only supported in local mode. Please use `wrangler dev`." ); } validateAssetsArgsAndConfig(args, config); - let experimentalAssetsOptions = processExperimentalAssetsArg(args, config); - if (experimentalAssetsOptions) { + let assetsOptions = processAssetsArg(args, config); + if (assetsOptions) { args.forceLocal = true; } @@ -739,7 +721,7 @@ export async function startDev(args: StartDevOptions) { pipelines: undefined, logfwdr: undefined, unsafe: undefined, - experimental_assets: undefined, + assets: undefined, }), }, dev: { @@ -804,14 +786,10 @@ export async function startDev(args: StartDevOptions) { legacyAssets: (configParam) => configParam.legacy_assets, enableServiceEnvironments: !(args.legacyEnv ?? true), }, - experimental: { - // only pass `experimentalAssetsOptions` if it came from args not from config - // otherwise config at startup ends up overriding future config changes in the - // ConfigController - assets: args.experimentalAssets - ? experimentalAssetsOptions - : undefined, - }, + // only pass `assetsOptions` if it came from args not from config + // otherwise config at startup ends up overriding future config changes in the + // ConfigController + assets: args.assets ? assetsOptions : undefined, } satisfies StartDevWorkerInput); void metrics.sendMetricsEvent( @@ -851,35 +829,32 @@ export async function startDev(args: StartDevOptions) { legacyAssets: args.legacyAssets, script: args.script, moduleRoot: args.moduleRoot, - experimentalAssets: args.experimentalAssets, + assets: args.assets, }, config, "dev" ); - experimentalAssetsOptions = processExperimentalAssetsArg( - args, - config - ); + assetsOptions = processAssetsArg(args, config); /* - * Handle experimental assets watching on config file changes + * Handle static assets watching on config file changes * - * 1. if experimental assets was specified via CLI args, only config file + * 1. if assets was specified via CLI args, only config file * changes related to `main` will matter. In this case, re-running - * `processExperimentalAssetsArg` is enough (see above) - * 2. if experimental_assets was not specififed via the configuration + * `processAssetsArg` is enough (see above) + * 2. if assets was not specififed via the configuration * file, but it is now, we should start watching the assets * directory - * 3. if experimental_assets was specified via the configuration + * 3. if assets was specified via the configuration * file, we should ensure we're still watching the correct * directory */ - if (experimentalAssetsOptions && !args.experimentalAssets) { + if (assetsOptions && !args.assets) { await assetsWatcher?.close(); - if (experimentalAssetsOptions) { - assetsWatcher = watch(experimentalAssetsOptions.directory, { + if (assetsOptions) { + assetsWatcher = watch(assetsOptions.directory, { persistent: true, ignoreInitial: true, }).on("all", async (eventName, changedPath) => { @@ -974,7 +949,7 @@ export async function startDev(args: StartDevOptions) { } legacyAssetPaths={legacyAssetPaths} legacyAssetsConfig={configParam.legacy_assets} - experimentalAssets={experimentalAssetsOptions} + assets={assetsOptions} initialPort={ args.port ?? configParam.dev.port ?? (await getLocalPort()) } @@ -1017,8 +992,8 @@ export async function startDev(args: StartDevOptions) { const devReactElement = render(await getDevReactElement(config)); rerender = devReactElement.rerender; - if (experimentalAssetsOptions && !args.experimentalDevEnv) { - assetsWatcher = watch(experimentalAssetsOptions.directory, { + if (assetsOptions && !args.experimentalDevEnv) { + assetsWatcher = watch(assetsOptions.directory, { persistent: true, ignoreInitial: true, }).on("all", async (eventName, filePath) => { @@ -1159,7 +1134,7 @@ export async function startApiDev(args: StartDevOptions) { args.accountId ?? configParam.account_id ?? getAccountFromCache()?.id, legacyAssetPaths: legacyAssetPaths, legacyAssetsConfig: configParam.legacy_assets, - experimentalAssets: undefined, + assets: undefined, //port can be 0, which means to use a random port initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()), initialIp: args.ip ?? configParam.dev.ip, @@ -1240,13 +1215,13 @@ export function maskVars( export async function getHostAndRoutes( args: - | Pick + | Pick | { host?: string; routes?: Extract[]; - experimentalAssets?: string; + assets?: string; }, - config: Pick & { + config: Pick & { dev: Pick; } ) { @@ -1269,10 +1244,7 @@ export async function getHostAndRoutes( } }); if (routes) { - validateRoutes( - routes, - Boolean(args.experimentalAssets || config.experimental_assets) - ); + validateRoutes(routes, Boolean(args.assets || config.assets)); } return { host, routes }; } @@ -1309,7 +1281,7 @@ export async function validateDevServerSettings( legacyAssets: args.legacyAssets, script: args.script, moduleRoot: args.moduleRoot, - experimentalAssets: args.experimentalAssets, + assets: args.assets, }, config, "dev" @@ -1605,8 +1577,8 @@ export function getBindings( mtls_certificates: configParam.mtls_certificates, pipelines: configParam.pipelines, send_email: configParam.send_email, - experimental_assets: configParam.experimental_assets?.binding - ? { binding: configParam.experimental_assets?.binding } + assets: configParam.assets?.binding + ? { binding: configParam.assets?.binding } : undefined, }; diff --git a/packages/wrangler/src/dev/dev.tsx b/packages/wrangler/src/dev/dev.tsx index 1747a08d778f..1cde8802c37f 100644 --- a/packages/wrangler/src/dev/dev.tsx +++ b/packages/wrangler/src/dev/dev.tsx @@ -44,6 +44,7 @@ import type { StartDevWorkerOptions, Trigger, } from "../api"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { Route } from "../config/environment"; import type { Entry } from "../deployment-bundle/entry"; @@ -51,7 +52,6 @@ import type { NodeJSCompatMode } from "../deployment-bundle/node-compat"; import type { CfModule, CfWorkerInit } from "../deployment-bundle/worker"; import type { StartDevOptions } from "../dev"; import type { WorkerRegistry } from "../dev-registry"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types"; import type { EphemeralDirectory } from "../paths"; import type { LegacyAssetPaths } from "../sites"; @@ -238,7 +238,7 @@ export type DevProps = { isWorkersSite: boolean; legacyAssetPaths: LegacyAssetPaths | undefined; legacyAssetsConfig: Config["legacy_assets"]; - experimentalAssets: ExperimentalAssetsOptions | undefined; + assets: AssetsOptions | undefined; compatibilityDate: string; compatibilityFlags: string[] | undefined; usageModel: "bundled" | "unbound" | undefined; @@ -485,9 +485,7 @@ function DevSession(props: DevSessionProps) { capnp: props.bindings.unsafe?.capnp, metadata: props.bindings.unsafe?.metadata, }, - experimental: { - assets: props.experimentalAssets, - }, + assets: props.assets, } satisfies StartDevWorkerOptions; }, [ props.routes, @@ -503,7 +501,7 @@ function DevSession(props: DevSessionProps) { props.isWorkersSite, props.local, props.legacyAssetsConfig, - props.experimentalAssets, + props.assets, props.processEntrypoint, props.additionalModules, props.env, @@ -708,7 +706,7 @@ function DevSession(props: DevSessionProps) { migrations={props.migrations} workerDefinitions={workerDefinitions} legacyAssetPaths={props.legacyAssetPaths} - experimentalAssets={props.experimentalAssets} + assets={props.assets} initialPort={undefined} // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value initialIp={"127.0.0.1"} // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value rules={props.rules} diff --git a/packages/wrangler/src/dev/local.tsx b/packages/wrangler/src/dev/local.tsx index c98e2d2cd14d..60a9a58410cf 100644 --- a/packages/wrangler/src/dev/local.tsx +++ b/packages/wrangler/src/dev/local.tsx @@ -6,6 +6,7 @@ import { registerWorker } from "../dev-registry"; import { logger } from "../logger"; import { DEFAULT_WORKER_NAME, MiniflareServer } from "./miniflare"; import type { ProxyData } from "../api"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { CfDurableObject, @@ -16,7 +17,6 @@ import type { WorkerEntrypointsDefinition, WorkerRegistry, } from "../dev-registry"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types"; import type { LegacyAssetPaths } from "../sites"; import type { ConfigBundle } from "./miniflare"; @@ -33,7 +33,7 @@ export interface LocalProps { migrations: Config["migrations"] | undefined; workerDefinitions: WorkerRegistry | undefined; legacyAssetPaths: LegacyAssetPaths | undefined; - experimentalAssets: ExperimentalAssetsOptions | undefined; + assets: AssetsOptions | undefined; initialPort: number | undefined; initialIp: string; rules: Config["rules"]; @@ -94,7 +94,7 @@ export async function localPropsToConfigBundle( migrations: props.migrations, workerDefinitions: props.workerDefinitions, legacyAssetPaths: props.legacyAssetPaths, - experimentalAssets: props.experimentalAssets, + assets: props.assets, initialPort: props.initialPort, initialIp: props.initialIp, rules: props.rules, diff --git a/packages/wrangler/src/dev/miniflare.ts b/packages/wrangler/src/dev/miniflare.ts index 7eacc25b9ba2..87b8c8ee54a0 100644 --- a/packages/wrangler/src/dev/miniflare.ts +++ b/packages/wrangler/src/dev/miniflare.ts @@ -24,6 +24,7 @@ import { getSourceMappedString } from "../sourcemap"; import { updateCheck } from "../update-check"; import { getClassNamesWhichUseSQLite } from "./validate-dev-props"; import type { ServiceFetch } from "../api"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { CfD1Database, @@ -40,7 +41,6 @@ import type { WorkerEntrypointsDefinition, WorkerRegistry, } from "../dev-registry"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import type { LoggerLevel } from "../logger"; import type { LegacyAssetPaths } from "../sites"; import type { EsbuildBundle } from "./use-esbuild"; @@ -175,7 +175,7 @@ export interface ConfigBundle { migrations: Config["migrations"] | undefined; workerDefinitions: WorkerRegistry | undefined; legacyAssetPaths: LegacyAssetPaths | undefined; - experimentalAssets: ExperimentalAssetsOptions | undefined; + assets: AssetsOptions | undefined; initialPort: Port; initialIp: string; rules: Config["rules"]; @@ -379,7 +379,7 @@ type MiniflareBindingsConfig = Pick< | "services" | "serviceBindings" > & - Partial>; + Partial>; // TODO(someday): would be nice to type these methods more, can we export types for // each plugin options schema and use those @@ -697,14 +697,14 @@ export function buildPersistOptions( } function buildAssetOptions(config: Omit) { - if (config.experimentalAssets) { + if (config.assets) { return { assets: { workerName: config.name, - path: config.experimentalAssets.directory, - bindingName: config.experimentalAssets.binding, - routingConfig: config.experimentalAssets.routingConfig, - assetConfig: config.experimentalAssets.assetConfig, + path: config.assets.directory, + bindingName: config.assets.binding, + routingConfig: config.assets.routingConfig, + assetConfig: config.assets.assetConfig, }, }; } diff --git a/packages/wrangler/src/dev/remote.tsx b/packages/wrangler/src/dev/remote.tsx index 1cb2d31f6320..a410a86be0ab 100644 --- a/packages/wrangler/src/dev/remote.tsx +++ b/packages/wrangler/src/dev/remote.tsx @@ -620,7 +620,7 @@ export async function createRemoteWorkerInit(props: { props.modules ); - const assets = await syncLegacyAssets( + const legacyAssets = await syncLegacyAssets( props.accountId, // When we're using the newer service environments, we wouldn't // have added the env name on to the script name. However, we must @@ -633,11 +633,11 @@ export async function createRemoteWorkerInit(props: { undefined ); // TODO: cancellable? - if (assets.manifest) { + if (legacyAssets.manifest) { modules.push({ name: "__STATIC_CONTENT_MANIFEST", filePath: undefined, - content: JSON.stringify(assets.manifest), + content: JSON.stringify(legacyAssets.manifest), type: "text", }); } @@ -654,13 +654,13 @@ export async function createRemoteWorkerInit(props: { bindings: { ...props.bindings, kv_namespaces: (props.bindings.kv_namespaces || []).concat( - assets.namespace - ? { binding: "__STATIC_CONTENT", id: assets.namespace } + legacyAssets.namespace + ? { binding: "__STATIC_CONTENT", id: legacyAssets.namespace } : [] ), text_blobs: { ...props.bindings.text_blobs, - ...(assets.manifest && + ...(legacyAssets.manifest && props.format === "service-worker" && { __STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST", }), @@ -676,7 +676,7 @@ export async function createRemoteWorkerInit(props: { placement: undefined, // no placement in dev tail_consumers: undefined, // no tail consumers in dev - TODO revisit? limits: undefined, // no limits in preview - not supported yet but can be added - experimental_assets: undefined, // no remote mode for assets + assets: undefined, // no remote mode for assets observability: undefined, // no observability in dev }; diff --git a/packages/wrangler/src/dev/start-server.ts b/packages/wrangler/src/dev/start-server.ts index 5058b78a521a..29ef74065922 100644 --- a/packages/wrangler/src/dev/start-server.ts +++ b/packages/wrangler/src/dev/start-server.ts @@ -268,7 +268,7 @@ export async function startDevServer( bindings: props.bindings, migrations: props.migrations, legacyAssetPaths: props.legacyAssetPaths, - experimentalAssets: props.experimentalAssets, + assets: props.assets, initialPort: undefined, // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value initialIp: "127.0.0.1", // hard-code for userworker, DevEnv-ProxyWorker now uses this prop value rules: props.rules, diff --git a/packages/wrangler/src/secret/index.ts b/packages/wrangler/src/secret/index.ts index 95b90f9bbdd6..9dee2548351b 100644 --- a/packages/wrangler/src/secret/index.ts +++ b/packages/wrangler/src/secret/index.ts @@ -94,7 +94,7 @@ async function createDraftWorker({ mtls_certificates: [], pipelines: [], logfwdr: { bindings: [] }, - experimental_assets: undefined, + assets: undefined, unsafe: { bindings: undefined, metadata: undefined, @@ -112,7 +112,7 @@ async function createDraftWorker({ placement: undefined, tail_consumers: undefined, limits: undefined, - experimental_assets: undefined, + assets: undefined, observability: undefined, }), } diff --git a/packages/wrangler/src/triggers/deploy.ts b/packages/wrangler/src/triggers/deploy.ts index 8d6f55c33d24..50f1016056be 100644 --- a/packages/wrangler/src/triggers/deploy.ts +++ b/packages/wrangler/src/triggers/deploy.ts @@ -15,10 +15,10 @@ import { logger } from "../logger"; import { ensureQueuesExistByConfig } from "../queues/client"; import { getWorkersDevSubdomain } from "../routes"; import { getZoneForRoute } from "../zones"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { Route } from "../config/environment"; import type { RouteObject } from "../deploy/deploy"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; type Props = { config: Config; @@ -30,7 +30,7 @@ type Props = { legacyEnv: boolean | undefined; dryRun: boolean | undefined; experimentalVersions: boolean | undefined; - experimentalAssetsOptions: ExperimentalAssetsOptions | undefined; + assetsOptions: AssetsOptions | undefined; }; export default async function triggersDeploy( @@ -43,7 +43,7 @@ export default async function triggersDeploy( props.routes ?? config.routes ?? (config.route ? [config.route] : []) ?? []; const routesOnly: Array = []; const customDomainsOnly: Array = []; - validateRoutes(routes, Boolean(props.experimentalAssetsOptions)); + validateRoutes(routes, Boolean(props.assetsOptions)); for (const route of routes) { if (typeof route !== "string" && route.custom_domain) { customDomainsOnly.push(route); diff --git a/packages/wrangler/src/triggers/index.ts b/packages/wrangler/src/triggers/index.ts index 7480c90c9c9b..9617dfba7812 100644 --- a/packages/wrangler/src/triggers/index.ts +++ b/packages/wrangler/src/triggers/index.ts @@ -1,5 +1,5 @@ +import { processAssetsArg } from "../assets"; import { readConfig } from "../config"; -import { processExperimentalAssetsArg } from "../experimental-assets"; import { getScriptName, isLegacyEnv, printWranglerBanner } from "../index"; import * as metrics from "../metrics"; import { requireAuth } from "../user"; @@ -58,10 +58,7 @@ export async function triggersDeployHandler( await printWranglerBanner(); const config = readConfig(undefined, args); - const experimentalAssetsOptions = processExperimentalAssetsArg( - { experimentalAssets: undefined }, - config - ); + const assetsOptions = processAssetsArg({ assets: undefined }, config); await metrics.sendMetricsEvent( "deploy worker triggers", {}, @@ -82,6 +79,6 @@ export async function triggersDeployHandler( legacyEnv: isLegacyEnv(config), dryRun: args.dryRun, experimentalVersions: args.experimentalJsonConfig, - experimentalAssetsOptions, + assetsOptions, }); } diff --git a/packages/wrangler/src/type-generation/index.ts b/packages/wrangler/src/type-generation/index.ts index 2911836a8e47..4a1dd513af05 100644 --- a/packages/wrangler/src/type-generation/index.ts +++ b/packages/wrangler/src/type-generation/index.ts @@ -134,7 +134,7 @@ export async function typesHandler( ai: config.ai, version_metadata: config.version_metadata, secrets, - experimental_assets: config.experimental_assets, + assets: config.assets, }; await generateTypes( @@ -407,10 +407,8 @@ async function generateTypes( ); } - if (configToDTS.experimental_assets?.binding) { - envTypeStructure.push( - constructType(configToDTS.experimental_assets.binding, "Fetcher") - ); + if (configToDTS.assets?.binding) { + envTypeStructure.push(constructType(configToDTS.assets.binding, "Fetcher")); } const modulesTypeStructure: string[] = []; diff --git a/packages/wrangler/src/versions/index.ts b/packages/wrangler/src/versions/index.ts index 492d8682f861..3c7cb353fa80 100644 --- a/packages/wrangler/src/versions/index.ts +++ b/packages/wrangler/src/versions/index.ts @@ -1,12 +1,9 @@ import assert from "node:assert"; import path from "node:path"; +import { processAssetsArg, validateAssetsArgsAndConfig } from "../assets"; import { findWranglerToml, readConfig } from "../config"; import { getEntry } from "../deployment-bundle/entry"; import { UserError } from "../errors"; -import { - processExperimentalAssetsArg, - validateAssetsArgsAndConfig, -} from "../experimental-assets"; import { getRules, getScriptName, @@ -71,12 +68,6 @@ export function versionsUploadOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, }) - .option("format", { - choices: ["modules", "service-worker"] as const, - describe: "Choose an entry type", - deprecated: true, - hidden: true, - }) .option("compatibility-date", { describe: "Date to use for compatibility checks", type: "string", @@ -94,23 +85,22 @@ export function versionsUploadOptions(yargs: CommonYargsArgv) { type: "boolean", default: false, }) - .option("legacy-assets", { - describe: "(Experimental) Static assets to be served", - type: "string", - requiresArg: true, - hidden: true, - }) .option("assets", { - describe: "(Experimental) Static assets to be served", + describe: "Static assets to be served. Replaces Workers Sites.", type: "string", requiresArg: true, + }) + .option("format", { + choices: ["modules", "service-worker"] as const, + describe: "Choose an entry type", + deprecated: true, hidden: true, }) - .option("experimental-assets", { + .option("legacy-assets", { describe: "Static assets to be served", type: "string", - alias: "x-assets", requiresArg: true, + deprecated: true, hidden: true, }) .option("site", { @@ -118,6 +108,7 @@ export function versionsUploadOptions(yargs: CommonYargsArgv) { type: "string", requiresArg: true, hidden: true, + deprecated: true, }) .option("site-include", { describe: @@ -126,6 +117,7 @@ export function versionsUploadOptions(yargs: CommonYargsArgv) { requiresArg: true, array: true, hidden: true, + deprecated: true, }) .option("site-exclude", { describe: @@ -134,6 +126,7 @@ export function versionsUploadOptions(yargs: CommonYargsArgv) { requiresArg: true, array: true, hidden: true, + deprecated: true, }) .option("var", { describe: @@ -221,8 +214,6 @@ export async function versionsUploadHandler( } ); - args.legacyAssets = args.legacyAssets ?? args.assets; - if (args.site || config.site) { throw new UserError( "Workers Sites does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead." @@ -230,7 +221,7 @@ export async function versionsUploadHandler( } if (args.legacyAssets || config.legacy_assets) { throw new UserError( - "Legacy Assets does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead." + "Legacy assets does not support uploading versions through `wrangler versions upload`. You must use `wrangler deploy` instead." ); } @@ -241,13 +232,13 @@ export async function versionsUploadHandler( // skip the corresponding mutual exclusivity validation legacyAssets: undefined, site: undefined, - experimentalAssets: args.experimentalAssets, + assets: args.assets, script: args.script, }, config ); - const experimentalAssetsOptions = processExperimentalAssetsArg(args, config); + const assetsOptions = processAssetsArg(args, config); if (args.latest) { logger.warn( @@ -297,7 +288,7 @@ export async function versionsUploadHandler( jsxFactory: args.jsxFactory, jsxFragment: args.jsxFragment, tsconfig: args.tsconfig, - experimentalAssetsOptions, + assetsOptions, minify: args.minify, uploadSourceMaps: args.uploadSourceMaps, nodeCompat: args.nodeCompat, diff --git a/packages/wrangler/src/versions/secrets/index.ts b/packages/wrangler/src/versions/secrets/index.ts index 1908980d2dfb..09530fd47b80 100644 --- a/packages/wrangler/src/versions/secrets/index.ts +++ b/packages/wrangler/src/versions/secrets/index.ts @@ -210,7 +210,7 @@ export async function copyWorkerVersionWithNewSecrets({ "workers/tag": versionTag, }, keep_assets: true, - experimental_assets: undefined, + assets: undefined, observability: scriptSettings.observability, }; @@ -259,7 +259,7 @@ async function parseModules( // Workers Sites is not supported if (formData.get("__STATIC_CONTENT_MANIFEST") !== null) { throw new UserError( - "Workers Sites and Legacy Assets do not support updating secrets through `wrangler versions secret put`. You must use `wrangler secret put` instead." + "Workers Sites and legacy assets do not support updating secrets through `wrangler versions secret put`. You must use `wrangler secret put` instead." ); } diff --git a/packages/wrangler/src/versions/upload.ts b/packages/wrangler/src/versions/upload.ts index 3c6edaf3a8cb..32163ce108cf 100644 --- a/packages/wrangler/src/versions/upload.ts +++ b/packages/wrangler/src/versions/upload.ts @@ -1,6 +1,7 @@ import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { blue, gray } from "@cloudflare/cli/colors"; +import { syncAssets } from "../assets"; import { fetchResult } from "../cfetch"; import { printBindings } from "../config"; import { bundleWorker } from "../deployment-bundle/bundle"; @@ -23,7 +24,6 @@ import { loadSourceMaps } from "../deployment-bundle/source-maps"; import { confirm } from "../dialogs"; import { getMigrationsToUpload } from "../durable"; import { UserError } from "../errors"; -import { syncExperimentalAssets } from "../experimental-assets"; import { logger } from "../logger"; import { getMetricsUsageHeaders } from "../metrics"; import { isNavigatorDefined } from "../navigator-user-agent"; @@ -35,11 +35,11 @@ import { getSourceMappedString, maybeRetrieveFileSourceMap, } from "../sourcemap"; +import type { AssetsOptions } from "../assets"; import type { Config } from "../config"; import type { Rule } from "../config/environment"; import type { Entry } from "../deployment-bundle/entry"; import type { CfPlacement, CfWorkerInit } from "../deployment-bundle/worker"; -import type { ExperimentalAssetsOptions } from "../experimental-assets"; import type { RetrieveSourceMapFunction } from "../sourcemap"; type Props = { @@ -52,7 +52,7 @@ type Props = { env: string | undefined; compatibilityDate: string | undefined; compatibilityFlags: string[] | undefined; - experimentalAssetsOptions: ExperimentalAssetsOptions | undefined; + assetsOptions: AssetsOptions | undefined; vars: Record | undefined; defines: Record | undefined; alias: Record | undefined; @@ -348,14 +348,10 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m }) : undefined; - // Upload assets if experimental assets is being used - const experimentalAssetsJwt = - props.experimentalAssetsOptions && !props.dryRun - ? await syncExperimentalAssets( - accountId, - scriptName, - props.experimentalAssetsOptions.directory - ) + // Upload assets if assets is being used + const assetsJwt = + props.assetsOptions && !props.dryRun + ? await syncAssets(accountId, scriptName, props.assetsOptions.directory) : undefined; const bindings: CfWorkerInit["bindings"] = { @@ -382,8 +378,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m mtls_certificates: config.mtls_certificates, pipelines: config.pipelines, logfwdr: config.logfwdr, - experimental_assets: config.experimental_assets?.binding - ? { binding: config.experimental_assets?.binding } + assets: config.assets?.binding + ? { binding: config.assets?.binding } : undefined, unsafe: { bindings: config.unsafe.bindings, @@ -425,12 +421,12 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m "workers/message": props.message, "workers/tag": props.tag, }, - experimental_assets: - props.experimentalAssetsOptions && experimentalAssetsJwt + assets: + props.assetsOptions && assetsJwt ? { - jwt: experimentalAssetsJwt, - routingConfig: props.experimentalAssetsOptions.routingConfig, - assetConfig: props.experimentalAssetsOptions.assetConfig, + jwt: assetsJwt, + routingConfig: props.assetsOptions.routingConfig, + assetConfig: props.assetsOptions.assetConfig, } : undefined, logpush: undefined, // both logpush and observability are not supported in versions upload