diff --git a/.changeset/brave-paws-build.md b/.changeset/brave-paws-build.md new file mode 100644 index 000000000000..473e5782d077 --- /dev/null +++ b/.changeset/brave-paws-build.md @@ -0,0 +1,23 @@ +--- +"wrangler": minor +--- + +Turn on `wrangler.json(c)` support by default + +Wrangler now supports both JSON (`wrangler.json`) and TOML (`wrangler.toml`) for it's configuration file. The format of Wrangler's configuration file is exactly the same across both languages, except that the syntax is `JSON` rather than `TOML`. e.g. + +```toml +name = "worker-ts" +main = "src/index.ts" +compatibility_date = "2023-05-04" +``` + +would be interpreted the same as the equivalent JSON + +```json +{ + "name": "worker-ts", + "main": "src/index.ts", + "compatibility_date": "2023-05-04" +} +``` diff --git a/packages/wrangler/README.md b/packages/wrangler/README.md index 465b2e331686..dfb151a4fc7a 100644 --- a/packages/wrangler/README.md +++ b/packages/wrangler/README.md @@ -43,7 +43,7 @@ $ npm install wrangler --save-dev ## Configuration: -Wrangler is configured via a `wrangler.toml` file in the project root. When utilizing the `wrangler init` command, a `wrangler.toml` file will be created for you. +Wrangler is configured via a `wrangler.json` or `wrangler.toml` file in the project root. When utilizing the `wrangler init` command, a `wrangler.toml` file will be created for you. Example: diff --git a/packages/wrangler/docs/how-to/add-a-binding.md b/packages/wrangler/docs/how-to/add-a-binding.md index 45d06ff3411e..9cabb2d6d52b 100644 --- a/packages/wrangler/docs/how-to/add-a-binding.md +++ b/packages/wrangler/docs/how-to/add-a-binding.md @@ -1,6 +1,6 @@ # How to register a binding -1. Register `wrangler.toml` section in: `packages/wrangler/src/config/environment.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/config/environment.ts#L431-L451) +1. Register Wrangler configuration section in: `packages/wrangler/src/config/environment.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/config/environment.ts#L431-L451) 1. Register validation functions in: `packages/wrangler/src/config/validation.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/config/validation.ts#L1297-L1306) 1. Add empty state for bindings, as necessary (tip: use typescript to guide you -- either via your editor or run: `pnpm check:type` from within `packages/wrangler`) 1. Add type for deployment bundle to: @@ -14,5 +14,5 @@ - `convertBindingsToCfWorkerInitBindings` in: `packages/wrangler/src/api/startDevWorker/utils.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/api/startDevWorker/utils.ts#L303-L305) 1. Test binding is deployed and printed in: `packages/wrangler/src/**tests**/deploy.test.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/__tests__/deploy.test.ts#L7604) 1. Test your validation in: `packages/wrangler/src/**tests**/configuration.test.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/__tests__/configuration.test.ts#L2234) -1. Enable `wrangler init --from-dash` to include your binding in the `wrangler.toml` it generates in: `packages/wrangler/src/init.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/init.ts#L1036-L1043) +1. Enable `wrangler init --from-dash` to include your binding in the Wrangler configuration file it generates in: `packages/wrangler/src/init.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/init.ts#L1036-L1043) 1. Enable `wrangler types` to emit your binding type in: `packages/src/type-generation/index.ts` [ref](https://github.com/cloudflare/workers-sdk/blob/ce7db9d9cb4f5bcd5a326b86dde051cb54b999fb/packages/wrangler/src/type-generation/index.ts#L115) diff --git a/packages/wrangler/e2e/helpers/e2e-wrangler-test.ts b/packages/wrangler/e2e/helpers/e2e-wrangler-test.ts index 6283c213f500..f1b39b8e5387 100644 --- a/packages/wrangler/e2e/helpers/e2e-wrangler-test.ts +++ b/packages/wrangler/e2e/helpers/e2e-wrangler-test.ts @@ -57,7 +57,9 @@ export class WranglerE2ETestHelper { return name; } const result = await this.run(`wrangler kv namespace create ${name}`); - const match = /id = "([0-9a-f]{32})"/.exec(result.stdout); + const tomlMatch = /id = "([0-9a-f]{32})"/.exec(result.stdout); + const jsonMatch = /"id": "([0-9a-f]{32})"/.exec(result.stdout); + const match = jsonMatch ?? tomlMatch; assert(match !== null, `Cannot find ID in ${JSON.stringify(result)}`); const id = match[1]; onTestFinished(async () => { @@ -84,7 +86,9 @@ export class WranglerE2ETestHelper { return { id: crypto.randomUUID(), name }; } const result = await this.run(`wrangler d1 create ${name}`); - const match = /database_id = "([0-9a-f-]{36})"/.exec(result.stdout); + const tomlMatch = /database_id = "([0-9a-f-]{36})"/.exec(result.stdout); + const jsonMatch = /"database_id": "([0-9a-f-]{36})"/.exec(result.stdout); + const match = jsonMatch ?? tomlMatch; assert(match !== null, `Cannot find ID in ${JSON.stringify(result)}`); const id = match[1]; onTestFinished(async () => { diff --git a/packages/wrangler/e2e/pages-dev.test.ts b/packages/wrangler/e2e/pages-dev.test.ts index 892d4a4c4a8d..48204315f365 100644 --- a/packages/wrangler/e2e/pages-dev.test.ts +++ b/packages/wrangler/e2e/pages-dev.test.ts @@ -31,7 +31,7 @@ describe.each([{ cmd: "wrangler pages dev" }])("Pages $cmd", ({ cmd }) => { `No compatibility_date was specified. Using today's date: .` ); expect(output).toContain( - `❯❯ Add one to your wrangler.toml file: compatibility_date = "", or` + `❯❯ Add one to your Wrangler configuration file: compatibility_date = "", or` ); expect(output).toContain( `❯❯ Pass it in your terminal: wrangler pages dev [] --compatibility-date=` diff --git a/packages/wrangler/e2e/r2.test.ts b/packages/wrangler/e2e/r2.test.ts index 94e5a84565a2..0e3d9b838499 100644 --- a/packages/wrangler/e2e/r2.test.ts +++ b/packages/wrangler/e2e/r2.test.ts @@ -23,9 +23,14 @@ describe("r2", () => { "Creating bucket 'tmp-e2e-r2-00000000-0000-0000-0000-000000000000'... ✅ Created bucket 'tmp-e2e-r2-00000000-0000-0000-0000-000000000000' with default storage class of Standard. Configure your Worker to write objects to this bucket: - [[r2_buckets]] - bucket_name = "tmp-e2e-r2-00000000-0000-0000-0000-000000000000" - binding = "tmp_e2e_r2_00000000_0000_0000_0000_000000000000"" + { + "r2_buckets": [ + { + "bucket_name": "tmp-e2e-r2-00000000-0000-0000-0000-000000000000", + "binding": "tmp_e2e_r2_00000000_0000_0000_0000_000000000000" + } + ] + }" `); }); diff --git a/packages/wrangler/e2e/types.test.ts b/packages/wrangler/e2e/types.test.ts index 9c7c0d8ce3dd..dcd312f03623 100644 --- a/packages/wrangler/e2e/types.test.ts +++ b/packages/wrangler/e2e/types.test.ts @@ -59,7 +59,7 @@ describe("types", () => { `📣 Since you have Node.js compatibility mode enabled, you should consider adding Node.js for TypeScript by running "npm i --save-dev @types/node@20.8.3". Please see the docs for more details: https://developers.cloudflare.com/workers/languages/typescript/#transitive-loading-of-typesnode-overrides-cloudflareworkers-types` ); expect(output.stdout).toContain( - `Remember to run 'wrangler types --x-include-runtime' again if you change 'compatibility_date' or 'compatibility_flags' in your wrangler.toml.` + `Remember to run 'wrangler types --x-include-runtime' again if you change 'compatibility_date' or 'compatibility_flags' in your wrangler.toml file.` ); }); diff --git a/packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap b/packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap new file mode 100644 index 000000000000..bec83c14f4ca --- /dev/null +++ b/packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap @@ -0,0 +1,97 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace 1`] = ` +"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +{ + \\"kv_namespaces\\": [ + { + \\"binding\\": \\"UnitTestNamespace\\", + \\"id\\": \\"some-namespace-id\\" + } + ] +}" +`; + +exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace in an environment if configured to do so 1`] = ` +"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array under [env.customEnv]: +{ + \\"kv_namespaces\\": [ + { + \\"binding\\": \\"UnitTestNamespace\\", + \\"id\\": \\"some-namespace-id\\" + } + ] +}" +`; + +exports[`wrangler > kv namespace > create > wrangler.json > should create a namespace using configured worker name 1`] = ` +"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +{ + \\"kv_namespaces\\": [ + { + \\"binding\\": \\"UnitTestNamespace\\", + \\"id\\": \\"some-namespace-id\\" + } + ] +}" +`; + +exports[`wrangler > kv namespace > create > wrangler.json > should create a preview namespace if configured to do so 1`] = ` +"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +{ + \\"kv_namespaces\\": [ + { + \\"binding\\": \\"UnitTestNamespace\\", + \\"preview_id\\": \\"some-namespace-id\\" + } + ] +}" +`; + +exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace 1`] = ` +"🌀 Creating namespace with title \\"worker-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +[[kv_namespaces]] +binding = \\"UnitTestNamespace\\" +id = \\"some-namespace-id\\" +" +`; + +exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace in an environment if configured to do so 1`] = ` +"🌀 Creating namespace with title \\"worker-customEnv-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array under [env.customEnv]: +[[kv_namespaces]] +binding = \\"UnitTestNamespace\\" +id = \\"some-namespace-id\\" +" +`; + +exports[`wrangler > kv namespace > create > wrangler.toml > should create a namespace using configured worker name 1`] = ` +"🌀 Creating namespace with title \\"other-worker-UnitTestNamespace\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +[[kv_namespaces]] +binding = \\"UnitTestNamespace\\" +id = \\"some-namespace-id\\" +" +`; + +exports[`wrangler > kv namespace > create > wrangler.toml > should create a preview namespace if configured to do so 1`] = ` +"🌀 Creating namespace with title \\"worker-UnitTestNamespace_preview\\" +✨ Success! +Add the following to your configuration file in your kv_namespaces array: +[[kv_namespaces]] +binding = \\"UnitTestNamespace\\" +preview_id = \\"some-namespace-id\\" +" +`; diff --git a/packages/wrangler/src/__tests__/__snapshots__/queues.test.ts.snap b/packages/wrangler/src/__tests__/__snapshots__/queues.test.ts.snap new file mode 100644 index 000000000000..41cad4328609 --- /dev/null +++ b/packages/wrangler/src/__tests__/__snapshots__/queues.test.ts.snap @@ -0,0 +1,93 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`wrangler > queues > create > wrangler.json > should create a queue 1`] = ` +"🌀 Creating queue 'testQueue' +✅ Created queue 'testQueue' + +Configure your Worker to send messages to this queue: + +{ + \\"queues\\": { + \\"producers\\": [ + { + \\"queue\\": \\"testQueue\\", + \\"binding\\": \\"testQueue\\" + } + ] + } +} +Configure your Worker to consume messages from this queue: + +{ + \\"queues\\": { + \\"consumers\\": [ + { + \\"queue\\": \\"testQueue\\" + } + ] + } +}" +`; + +exports[`wrangler > queues > create > wrangler.json > should send queue settings with delivery delay 1`] = ` +"🌀 Creating queue 'testQueue' +✅ Created queue 'testQueue' + +Configure your Worker to send messages to this queue: + +{ + \\"queues\\": { + \\"producers\\": [ + { + \\"queue\\": \\"testQueue\\", + \\"binding\\": \\"testQueue\\" + } + ] + } +} +Configure your Worker to consume messages from this queue: + +{ + \\"queues\\": { + \\"consumers\\": [ + { + \\"queue\\": \\"testQueue\\" + } + ] + } +}" +`; + +exports[`wrangler > queues > create > wrangler.toml > should create a queue 1`] = ` +"🌀 Creating queue 'testQueue' +✅ Created queue 'testQueue' + +Configure your Worker to send messages to this queue: + +[[queues.producers]] +queue = \\"testQueue\\" +binding = \\"testQueue\\" + +Configure your Worker to consume messages from this queue: + +[[queues.consumers]] +queue = \\"testQueue\\" +" +`; + +exports[`wrangler > queues > create > wrangler.toml > should send queue settings with delivery delay 1`] = ` +"🌀 Creating queue 'testQueue' +✅ Created queue 'testQueue' + +Configure your Worker to send messages to this queue: + +[[queues.producers]] +queue = \\"testQueue\\" +binding = \\"testQueue\\" + +Configure your Worker to consume messages from this queue: + +[[queues.consumers]] +queue = \\"testQueue\\" +" +`; diff --git a/packages/wrangler/src/__tests__/__snapshots__/r2.test.ts.snap b/packages/wrangler/src/__tests__/__snapshots__/r2.test.ts.snap new file mode 100644 index 000000000000..a1fe92e792f8 --- /dev/null +++ b/packages/wrangler/src/__tests__/__snapshots__/r2.test.ts.snap @@ -0,0 +1,113 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`r2 > bucket > create > wrangler.json > should create a bucket & check request inputs 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +{ + \\"r2_buckets\\": [ + { + \\"bucket_name\\": \\"testBucket\\", + \\"binding\\": \\"testBucket\\" + } + ] +}" +`; + +exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected default storage class 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with default storage class of InfrequentAccess. + +Configure your Worker to write objects to this bucket: + +{ + \\"r2_buckets\\": [ + { + \\"bucket_name\\": \\"testBucket\\", + \\"binding\\": \\"testBucket\\" + } + ] +}" +`; + +exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected jurisdiction 1`] = ` +"Creating bucket 'testBucket (eu)'... +✅ Created bucket 'testBucket (eu)' with default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +{ + \\"r2_buckets\\": [ + { + \\"bucket_name\\": \\"testBucket\\", + \\"binding\\": \\"testBucket\\" + } + ] +}" +`; + +exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected location hint 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with location hint weur and default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +{ + \\"r2_buckets\\": [ + { + \\"bucket_name\\": \\"testBucket\\", + \\"binding\\": \\"testBucket\\" + } + ] +}" +`; + +exports[`r2 > bucket > create > wrangler.toml > should create a bucket & check request inputs 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +[[r2_buckets]] +bucket_name = \\"testBucket\\" +binding = \\"testBucket\\" +" +`; + +exports[`r2 > bucket > create > wrangler.toml > should create a bucket with the expected default storage class 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with default storage class of InfrequentAccess. + +Configure your Worker to write objects to this bucket: + +[[r2_buckets]] +bucket_name = \\"testBucket\\" +binding = \\"testBucket\\" +" +`; + +exports[`r2 > bucket > create > wrangler.toml > should create a bucket with the expected jurisdiction 1`] = ` +"Creating bucket 'testBucket (eu)'... +✅ Created bucket 'testBucket (eu)' with default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +[[r2_buckets]] +bucket_name = \\"testBucket\\" +binding = \\"testBucket\\" +" +`; + +exports[`r2 > bucket > create > wrangler.toml > should create a bucket with the expected location hint 1`] = ` +"Creating bucket 'testBucket'... +✅ Created bucket 'testBucket' with location hint weur and default storage class of Standard. + +Configure your Worker to write objects to this bucket: + +[[r2_buckets]] +bucket_name = \\"testBucket\\" +binding = \\"testBucket\\" +" +`; diff --git a/packages/wrangler/src/__tests__/ai.test.ts b/packages/wrangler/src/__tests__/ai.test.ts index 5abf40779843..e38a10a1f6df 100644 --- a/packages/wrangler/src/__tests__/ai.test.ts +++ b/packages/wrangler/src/__tests__/ai.test.ts @@ -26,11 +26,10 @@ describe("ai help", () => { wrangler ai finetune Interact with finetune files GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -55,11 +54,10 @@ describe("ai help", () => { wrangler ai finetune Interact with finetune files GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); }); diff --git a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts index 9d8018f9106e..0b23a8993bcd 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/create.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/create.test.ts @@ -86,11 +86,10 @@ describe("cloudchamber create", () => { Create a new deployment GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Return output as clean JSON [boolean] [default: false] diff --git a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts index 77197e4b3ead..4ea32b65cc80 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/curl.test.ts @@ -39,11 +39,10 @@ describe("cloudchamber curl", () => { path [string] [required] [default: \\"/\\"] GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Output json. Use for consistent, machine readable output. [boolean] [default: false] diff --git a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts index 7fc32bd35282..84d3527f408d 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/delete.test.ts @@ -35,11 +35,10 @@ describe("cloudchamber delete", () => { deploymentId deployment you want to delete [string] GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Return output as clean JSON [boolean] [default: false]" diff --git a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts index 4e707a76e48e..5bfebd0d05e0 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/images.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/images.test.ts @@ -36,11 +36,10 @@ describe("cloudchamber image", () => { wrangler cloudchamber registries list list registries configured for this account GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Return output as clean JSON [boolean] [default: false]" diff --git a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts index a86d05067797..4657a264b20d 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/list.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/list.test.ts @@ -36,11 +36,10 @@ describe("cloudchamber list", () => { This means that 'list' will only showcase deployments that contain this ID prefix [string] GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Return output as clean JSON [boolean] [default: false] diff --git a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts index b6d5a59f14ba..4a73783f2c24 100644 --- a/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts +++ b/packages/wrangler/src/__tests__/cloudchamber/modify.test.ts @@ -71,11 +71,10 @@ describe("cloudchamber modify", () => { deploymentId The deployment you want to modify [string] GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --json Return output as clean JSON [boolean] [default: false] diff --git a/packages/wrangler/src/__tests__/config-validation-pages.test.ts b/packages/wrangler/src/__tests__/config-validation-pages.test.ts index 2cfedb6f71f6..e35e833a0610 100644 --- a/packages/wrangler/src/__tests__/config-validation-pages.test.ts +++ b/packages/wrangler/src/__tests__/config-validation-pages.test.ts @@ -31,10 +31,10 @@ describe("validatePagesConfig()", () => { expect(diagnostics.hasWarnings()).toBeFalsy(); expect(diagnostics.hasErrors()).toBeTruthy(); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` - "Running configuration file validation for Pages: - - Missing top-level field \\"name\\" in configuration file. - Pages requires the name of your project to be configured at the top-level of your \`wrangler.toml\` file. This is because, in Pages, environments target the same project." - `); + "Running configuration file validation for Pages: + - Missing top-level field \\"name\\" in configuration file. + Pages requires the name of your project to be configured at the top-level of your Wrangler configuration file. This is because, in Pages, environments target the same project." + `); }); }); diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 0a56c2f9fda0..6979789b260c 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -3,7 +3,7 @@ import { readConfig } from "../config"; import { normalizeAndValidateConfig } from "../config/validation"; import { normalizeString } from "./helpers/normalize"; import { runInTempDir } from "./helpers/run-in-tmp"; -import { writeWranglerToml } from "./helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "./helpers/write-wrangler-config"; import type { ConfigFields, RawConfig, @@ -14,7 +14,7 @@ import type { describe("readConfig()", () => { runInTempDir(); it("should not error if a python entrypoint is used with the right compatibility_flag", () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.py", compatibility_flags: ["python_workers"], }); @@ -31,7 +31,7 @@ describe("readConfig()", () => { `); }); it("should error if a python entrypoint is used without the right compatibility_flag", () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.py", }); try { @@ -1017,24 +1017,26 @@ describe("normalizeAndValidateConfig()", () => { const { config, diagnostics } = normalizeAndValidateConfig( expectedConfig, - undefined, + "wrangler.toml", { env: undefined } ); - expect(config).toEqual( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect({ ...config, tsconfig: normalizePath(config.tsconfig!) }).toEqual( expect.objectContaining({ ...expectedConfig, main: resolvedMain }) ); expect(diagnostics.hasErrors()).toBe(false); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` - "Processing wrangler configuration: + "Processing wrangler.toml configuration: - \\"unsafe\\" fields are experimental and may change or break at any time. - - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS1), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml: + - In your wrangler.toml file, you have configured \`durable_objects\` exported by this Worker (CLASS1), but no \`migrations\` for them. This may not work as expected until you add a \`migrations\` section to your wrangler.toml file. Add the following configuration: + + \`\`\` + [[migrations]] + tag = \\"v1\\" + new_classes = [ \\"CLASS1\\" ] - \`\`\` - [[migrations]] - tag = \\"v1\\" # Should be unique for each entry - new_classes = [\\"CLASS1\\"] - \`\`\` + \`\`\` Refer to https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ for more details." `); @@ -3723,16 +3725,16 @@ describe("normalizeAndValidateConfig()", () => { " `); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` - "Processing wrangler configuration: - - No environment found in configuration with name \\"DEV\\". - Before using \`--env=DEV\` there should be an equivalent environment section in the configuration. - - Consider adding an environment configuration section to the wrangler.toml file: - \`\`\` - [env.DEV] - \`\`\` - " - `); + "Processing wrangler configuration: + - No environment found in configuration with name \\"DEV\\". + Before using \`--env=DEV\` there should be an equivalent environment section in the configuration. + + Consider adding an environment configuration section to the Wrangler configuration file: + \`\`\` + [env.DEV] + \`\`\` + " + `); }); it("should error if we specify an environment that does not match the named environments", () => { @@ -3741,17 +3743,17 @@ describe("normalizeAndValidateConfig()", () => { env: "DEV", }); expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` - "Processing wrangler configuration: - - No environment found in configuration with name \\"DEV\\". - Before using \`--env=DEV\` there should be an equivalent environment section in the configuration. - The available configured environment names are: [\\"ENV1\\"] - - Consider adding an environment configuration section to the wrangler.toml file: - \`\`\` - [env.DEV] - \`\`\` - " - `); + "Processing wrangler configuration: + - No environment found in configuration with name \\"DEV\\". + Before using \`--env=DEV\` there should be an equivalent environment section in the configuration. + The available configured environment names are: [\\"ENV1\\"] + + Consider adding an environment configuration section to the Wrangler configuration file: + \`\`\` + [env.DEV] + \`\`\` + " + `); expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(` "Processing wrangler configuration: " @@ -5885,5 +5887,6 @@ describe("normalizeAndValidateConfig()", () => { function normalizePath(text: string): string { return text .replace("project\\wrangler.toml", "project/wrangler.toml") - .replace("src\\index.ts", "src/index.ts"); + .replace("src\\index.ts", "src/index.ts") + .replace("path\\to\\tsconfig", "path/to/tsconfig"); } diff --git a/packages/wrangler/src/__tests__/core/command-registration.test.ts b/packages/wrangler/src/__tests__/core/command-registration.test.ts index 2308f12e75cf..b6533dca22ea 100644 --- a/packages/wrangler/src/__tests__/core/command-registration.test.ts +++ b/packages/wrangler/src/__tests__/core/command-registration.test.ts @@ -133,6 +133,9 @@ describe("Command Registration", () => { num: 2, bool: true, arr: [ 'first', 'second', 'third' ], + 'experimental-json-config': true, + j: true, + experimentalJsonConfig: true, 'experimental-versions': true, 'x-versions': true, 'experimental-gradual-rollouts': true, @@ -200,11 +203,10 @@ describe("Command Registration", () => { wrangler two namespace 2 GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose" `); @@ -223,11 +225,10 @@ describe("Command Registration", () => { wrangler one two command 1 2 GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -243,11 +244,10 @@ describe("Command Registration", () => { wrangler one two three command 1 2 3 GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -260,11 +260,10 @@ describe("Command Registration", () => { command 1 2 3 GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -285,6 +284,9 @@ describe("Command Registration", () => { num: 3, bool: true, arr: [ '1st', '2nd', '3rd' ], + 'experimental-json-config': true, + j: true, + experimentalJsonConfig: true, 'experimental-versions': true, 'x-versions': true, 'experimental-gradual-rollouts': true, @@ -341,11 +343,10 @@ describe("Command Registration", () => { posNum [number] GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean] + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean] OPTIONS --str [string] [required] diff --git a/packages/wrangler/src/__tests__/custom-build.test.ts b/packages/wrangler/src/__tests__/custom-build.test.ts index 8ff08efb94a0..61175a73114d 100644 --- a/packages/wrangler/src/__tests__/custom-build.test.ts +++ b/packages/wrangler/src/__tests__/custom-build.test.ts @@ -10,7 +10,12 @@ describe("Custom Builds", () => { it("runCustomBuild throws UserError when a command fails", async () => { try { - await runCustomBuild("/", "/", { command: `node -e "process.exit(1)"` }); + await runCustomBuild( + "/", + "/", + { command: `node -e "process.exit(1)"` }, + undefined + ); assert(false, "Unreachable"); } catch (e) { expect(e).toBeInstanceOf(UserError); diff --git a/packages/wrangler/src/__tests__/d1/d1.test.ts b/packages/wrangler/src/__tests__/d1/d1.test.ts index 843d19345afd..92229f8f8333 100644 --- a/packages/wrangler/src/__tests__/d1/d1.test.ts +++ b/packages/wrangler/src/__tests__/d1/d1.test.ts @@ -29,11 +29,10 @@ describe("d1", () => { wrangler d1 migrations Interact with D1 migrations GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -66,11 +65,10 @@ describe("d1", () => { wrangler d1 migrations Interact with D1 migrations GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -96,11 +94,10 @@ describe("d1", () => { wrangler d1 migrations apply Apply D1 migrations GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); @@ -125,11 +122,10 @@ describe("d1", () => { wrangler d1 time-travel restore Restore a database back to a specific point-in-time GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); }); diff --git a/packages/wrangler/src/__tests__/d1/execute.test.ts b/packages/wrangler/src/__tests__/d1/execute.test.ts index b3acb161b594..08530312b210 100644 --- a/packages/wrangler/src/__tests__/d1/execute.test.ts +++ b/packages/wrangler/src/__tests__/d1/execute.test.ts @@ -4,7 +4,7 @@ import { mockConsoleMethods } from "../helpers/mock-console"; import { useMockIsTTY } from "../helpers/mock-istty"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("execute", () => { const std = mockConsoleMethods(); @@ -16,7 +16,7 @@ describe("execute", () => { it("should require login when running against prod", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -31,7 +31,7 @@ describe("execute", () => { it("should expect either --command or --file", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -44,7 +44,7 @@ describe("execute", () => { it("should reject use of both --command and --file", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -64,7 +64,7 @@ describe("execute", () => { it("should reject the use of --remote with --local", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -79,7 +79,7 @@ describe("execute", () => { it("should reject the use of --preview with --local", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -92,7 +92,7 @@ describe("execute", () => { it("should reject the use of --preview with --local with --json", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -115,7 +115,7 @@ describe("execute", () => { it("should reject a binary SQLite DB", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], diff --git a/packages/wrangler/src/__tests__/d1/export.test.ts b/packages/wrangler/src/__tests__/d1/export.test.ts index a7ad293d61e4..4b9809f936e2 100644 --- a/packages/wrangler/src/__tests__/d1/export.test.ts +++ b/packages/wrangler/src/__tests__/d1/export.test.ts @@ -8,7 +8,7 @@ import { mockGetMemberships } from "../helpers/mock-oauth-flow"; import { msw } from "../helpers/msw"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("export", () => { mockAccountId({ accountId: null }); @@ -25,7 +25,7 @@ describe("export", () => { it("should handle local", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -104,7 +104,7 @@ describe("export", () => { it("should handle remote", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], diff --git a/packages/wrangler/src/__tests__/d1/info.test.ts b/packages/wrangler/src/__tests__/d1/info.test.ts index e96ff26d080c..738489446a64 100644 --- a/packages/wrangler/src/__tests__/d1/info.test.ts +++ b/packages/wrangler/src/__tests__/d1/info.test.ts @@ -6,7 +6,7 @@ import { mockGetMemberships } from "../helpers/mock-oauth-flow"; import { msw } from "../helpers/msw"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("info", () => { mockAccountId({ accountId: null }); @@ -21,7 +21,7 @@ describe("info", () => { mockGetMemberships([ { id: "IG-88", account: { id: "1701", name: "enterprise" } }, ]); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DB", @@ -70,7 +70,7 @@ describe("info", () => { mockGetMemberships([ { id: "IG-88", account: { id: "1701", name: "enterprise" } }, ]); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DB", diff --git a/packages/wrangler/src/__tests__/d1/insights.test.ts b/packages/wrangler/src/__tests__/d1/insights.test.ts index 73025b156a51..59ea81c06dae 100644 --- a/packages/wrangler/src/__tests__/d1/insights.test.ts +++ b/packages/wrangler/src/__tests__/d1/insights.test.ts @@ -8,7 +8,7 @@ import { mockGetMemberships } from "../helpers/mock-oauth-flow"; import { msw } from "../helpers/msw"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("getDurationDates()", () => { beforeAll(() => { @@ -112,7 +112,7 @@ describe("insights", () => { mockGetMemberships([ { id: "IG-88", account: { id: "1701", name: "enterprise" } }, ]); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DB", diff --git a/packages/wrangler/src/__tests__/d1/migrate.test.ts b/packages/wrangler/src/__tests__/d1/migrate.test.ts index 2f5fb08ae108..47c7412494c9 100644 --- a/packages/wrangler/src/__tests__/d1/migrate.test.ts +++ b/packages/wrangler/src/__tests__/d1/migrate.test.ts @@ -10,7 +10,7 @@ import { mockSetTimeout } from "../helpers/mock-set-timeout"; import { msw } from "../helpers/msw"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("migrate", () => { runInTempDir(); @@ -22,7 +22,7 @@ describe("migrate", () => { describe("create", () => { it("should reject the --local flag for create", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -39,7 +39,7 @@ describe("migrate", () => { mockApiToken(); it("should not attempt to login in local mode", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -54,17 +54,17 @@ describe("migrate", () => { it("should try to read D1 config from wrangler.toml", async () => { setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); await expect( runWrangler("d1 migrations apply DATABASE --remote") ).rejects.toThrowError( - "Couldn't find a D1 DB with the name or binding 'DATABASE' in wrangler.toml." + "Couldn't find a D1 DB with the name or binding 'DATABASE' in your wrangler.toml file." ); }); it("should not try to read wrangler.toml in local mode", async () => { setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); // If we get to the point where we are checking for migrations then we have not checked wrangler.toml. await expect( runWrangler("d1 migrations apply DATABASE") @@ -75,7 +75,7 @@ describe("migrate", () => { it("should reject the use of --preview with --local", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -90,7 +90,7 @@ describe("migrate", () => { it("multiple accounts: should throw when trying to apply migrations without an account_id in config", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", @@ -172,7 +172,7 @@ Your database may not be available to serve requests during the migration, conti } ) ); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", @@ -213,7 +213,7 @@ Your database may not be available to serve requests during the migration, conti it("should not attempt to login in local mode", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -228,7 +228,7 @@ Your database may not be available to serve requests during the migration, conti it("should use the custom migrations folder when provided", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", @@ -252,11 +252,11 @@ Your database may not be available to serve requests during the migration, conti vi.stubEnv("CLOUDFLARE_API_TOKEN", "api-token"); reinitialiseAuthTokens(); setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); await expect( runWrangler("d1 migrations list DATABASE --remote") ).rejects.toThrowError( - "Couldn't find a D1 DB with the name or binding 'DATABASE' in wrangler.toml." + "Couldn't find a D1 DB with the name or binding 'DATABASE' in your wrangler.toml file." ); }); @@ -272,7 +272,7 @@ Your database may not be available to serve requests during the migration, conti it("should not try to read wrangler.toml in local mode", async () => { setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); // If we get to the point where we are checking for migrations then we have not checked wrangler.toml. await expect( runWrangler("d1 migrations list DATABASE") diff --git a/packages/wrangler/src/__tests__/d1/timeTravel.test.ts b/packages/wrangler/src/__tests__/d1/timeTravel.test.ts index cc064bf33ffb..c5a4e60165f3 100644 --- a/packages/wrangler/src/__tests__/d1/timeTravel.test.ts +++ b/packages/wrangler/src/__tests__/d1/timeTravel.test.ts @@ -7,7 +7,7 @@ import { mockGetMemberships } from "../helpers/mock-oauth-flow"; import { msw } from "../helpers/msw"; import { runInTempDir } from "../helpers/run-in-tmp"; import { runWrangler } from "../helpers/run-wrangler"; -import { writeWranglerToml } from "../helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "../helpers/write-wrangler-config"; describe("time-travel", () => { mockConsoleMethods(); @@ -19,7 +19,7 @@ describe("time-travel", () => { describe("restore", () => { it("should reject the use of --timestamp with --bookmark", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -37,7 +37,7 @@ describe("time-travel", () => { describe("throwIfDatabaseIsAlpha", () => { it("should throw for alpha dbs", async () => { - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], @@ -73,7 +73,7 @@ describe("time-travel", () => { ); }); it("should not throw for non-alpha dbs", async () => { - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "DATABASE", database_name: "db", database_id: "xxxx" }, ], diff --git a/packages/wrangler/src/__tests__/delete.test.ts b/packages/wrangler/src/__tests__/delete.test.ts index d661ff57629f..0af3a787dc09 100644 --- a/packages/wrangler/src/__tests__/delete.test.ts +++ b/packages/wrangler/src/__tests__/delete.test.ts @@ -6,7 +6,7 @@ import { useMockIsTTY } from "./helpers/mock-istty"; import { msw } from "./helpers/msw"; import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; -import { writeWranglerToml } from "./helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "./helpers/write-wrangler-config"; import type { ServiceReferenceResponse, Tail } from "../delete"; import type { KVNamespaceInfo } from "../kv/helpers"; @@ -47,7 +47,7 @@ describe("delete", () => { text: `Are you sure you want to delete test-name? This action cannot be undone.`, result: true, }); - writeWranglerToml(); + writeWranglerConfig(); mockListKVNamespacesRequest(); mockListReferencesRequest("test-name"); mockListTailsByConsumerRequest("test-name"); @@ -230,7 +230,7 @@ describe("delete", () => { }); it("should error helpfully if pages_build_output_dir is set", async () => { - writeWranglerToml({ pages_build_output_dir: "dist", name: "test" }); + writeWranglerConfig({ pages_build_output_dir: "dist", name: "test" }); await expect( runWrangler("delete") ).rejects.toThrowErrorMatchingInlineSnapshot( @@ -259,7 +259,7 @@ You can still delete this Worker, but doing so WILL BREAK the Workers that depen Are you sure you want to continue?`, result: true, }); - writeWranglerToml(); + writeWranglerConfig(); mockListKVNamespacesRequest(); mockListReferencesRequest("test-name", { services: { @@ -340,7 +340,7 @@ You can still delete this Worker, but doing so WILL BREAK the Workers that depen Are you sure you want to continue?`, result: false, }); - writeWranglerToml(); + writeWranglerConfig(); mockListKVNamespacesRequest(); mockListReferencesRequest("test-name", { services: { @@ -369,7 +369,7 @@ Are you sure you want to continue?`, }); it("should not require confirmation when --force is used", async () => { - writeWranglerToml(); + writeWranglerConfig(); mockListKVNamespacesRequest(); mockDeleteWorkerRequest({ force: true }); await runWrangler("delete --force"); diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 427f75c1f089..f9b2776095ff 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -48,7 +48,7 @@ import { normalizeString } from "./helpers/normalize"; 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 { writeWranglerConfig } from "./helpers/write-wrangler-config"; import type { AssetManifest } from "../assets"; import type { Config } from "../config"; import type { CustomDomain, CustomDomainChangeset } from "../deploy/deploy"; @@ -94,7 +94,7 @@ describe("deploy", () => { vi.stubEnv("WRANGLER_OUTPUT_FILE_DIRECTORY", "output"); vi.stubEnv("WRANGLER_OUTPUT_FILE_PATH", ""); writeWorkerSource(); - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], workers_dev: true, }); @@ -146,7 +146,7 @@ describe("deploy", () => { it("should successfully deploy with CI tag match", async () => { vi.stubEnv("WRANGLER_CI_MATCH_TAG", "abc123"); writeWorkerSource(); - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], workers_dev: true, }); @@ -236,7 +236,7 @@ describe("deploy", () => { }); mockSubDomainRequest(); - await runWrangler("deploy ./my-worker/index.js --experimental-json-config"); + await runWrangler("deploy ./my-worker/index.js"); expect(std.out).toMatchInlineSnapshot(` "Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms @@ -310,7 +310,7 @@ describe("deploy", () => { }); mockSubDomainRequest(); - await runWrangler("deploy ./my-worker/index.js --experimental-json-config"); + await runWrangler("deploy ./my-worker/index.js"); expect(std.out).toMatchInlineSnapshot(` "Total Upload: xx KiB / gzip: xx KiB Worker Startup Time: 100 ms @@ -327,7 +327,7 @@ describe("deploy", () => { it("should not deploy if there's any other kind of error when checking deployment source", async () => { writeWorkerSource(); - writeWranglerToml(); + writeWranglerConfig(); mockSubDomainRequest(); mockUploadWorkerRequest(); msw.use(...mswSuccessOauthHandlers, ...mswSuccessUserHandlers); @@ -383,7 +383,7 @@ describe("deploy", () => { }); it("should error helpfully if pages_build_output_dir is set in wrangler.toml", async () => { - writeWranglerToml({ + writeWranglerConfig({ pages_build_output_dir: "public", name: "test-name", }); @@ -450,7 +450,7 @@ describe("deploy", () => { it("drops a user into the login flow if they're unauthenticated", async () => { setIsTTY(true); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockDomainUsesAccess({ usesAccess: false }); mockSubDomainRequest(); @@ -480,7 +480,7 @@ describe("deploy", () => { mockAuthDomain({ domain: "dash.staging.cloudflare.com" }); it("drops a user into the login flow if they're unauthenticated", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockDomainUsesAccess({ usesAccess: false, @@ -519,7 +519,7 @@ describe("deploy", () => { }); it("warns a user when they're authenticated with an API token in wrangler config file", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -553,7 +553,7 @@ describe("deploy", () => { it("should not throw an error in non-TTY if 'CLOUDFLARE_API_TOKEN' & 'account_id' are in scope", async () => { vi.stubEnv("CLOUDFLARE_API_TOKEN", "123456789"); setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ account_id: "some-account-id", }); writeWorkerSource(); @@ -578,7 +578,7 @@ describe("deploy", () => { vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "some-account-id"); setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -602,7 +602,7 @@ describe("deploy", () => { setIsTTY(false); vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", ""); - writeWranglerToml({ + writeWranglerConfig({ account_id: undefined, }); writeWorkerSource(); @@ -617,7 +617,7 @@ describe("deploy", () => { await expect(runWrangler("deploy index.js")).rejects .toMatchInlineSnapshot(` [Error: More than one account available but unable to select one in non-interactive mode. - Please set the appropriate \`account_id\` in your \`wrangler.toml\` file. + Please set the appropriate \`account_id\` in your Wrangler configuration file. Available accounts are (\`\`: \`\`): \`enterprise\`: \`1701\` \`enterprise-nx\`: \`nx01\`] @@ -626,7 +626,7 @@ describe("deploy", () => { it("should throw error in non-TTY if 'CLOUDFLARE_API_TOKEN' is missing", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ account_id: undefined, }); vi.stubEnv("CLOUDFLARE_API_TOKEN", ""); @@ -650,7 +650,7 @@ describe("deploy", () => { }); it("should throw error with no account ID provided and no members retrieved", async () => { setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ account_id: undefined, }); vi.stubEnv("CLOUDFLARE_API_TOKEN", "picard"); @@ -664,13 +664,13 @@ describe("deploy", () => { await expect(runWrangler("deploy index.js")).rejects.toThrowError(); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Failed to automatically retrieve account IDs for the logged in user. + "X [ERROR] Failed to automatically retrieve account IDs for the logged in user. - In a non-interactive environment, it is mandatory to specify an account ID, either by assigning - its value to CLOUDFLARE_ACCOUNT_ID, or as \`account_id\` in your \`wrangler.toml\` file. + In a non-interactive environment, it is mandatory to specify an account ID, either by assigning + its value to CLOUDFLARE_ACCOUNT_ID, or as \`account_id\` in your Wrangler configuration file. - " - `); + " + `); }); }); }); @@ -678,7 +678,7 @@ describe("deploy", () => { describe("warnings", () => { it("should warn user when worker was last deployed from api", async () => { msw.use(...mswSuccessDeploymentScriptAPI); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -699,7 +699,7 @@ describe("deploy", () => { }); it("should warn user when additional properties are passed to a services config", async () => { - writeWranglerToml({ + writeWranglerConfig({ d1_databases: [ { binding: "MY_DB", @@ -718,16 +718,16 @@ describe("deploy", () => { await runWrangler("deploy ./index"); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Unexpected fields found in d1_databases[0] field: \\"tail_consumers\\" + - Unexpected fields found in d1_databases[0] field: \\"tail_consumers\\" - " - `); + " + `); }); it("should log esbuild warnings", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", dedent/* javascript */ ` @@ -757,7 +757,7 @@ describe("deploy", () => { describe("environments", () => { it("should use legacy environments by default", async () => { - writeWranglerToml({ env: { "some-env": {} } }); + writeWranglerConfig({ env: { "some-env": {} } }); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -780,7 +780,7 @@ describe("deploy", () => { describe("legacy", () => { it("uses the script name when no environment is specified", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -801,7 +801,7 @@ describe("deploy", () => { }); it("appends the environment name when provided, and there is associated config", async () => { - writeWranglerToml({ env: { "some-env": {} } }); + writeWranglerConfig({ env: { "some-env": {} } }); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -823,7 +823,7 @@ describe("deploy", () => { }); it("appends the environment name when provided (with a warning), if there are no configured environments", async () => { - writeWranglerToml({}); + writeWranglerConfig({}); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -842,24 +842,24 @@ describe("deploy", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - No environment found in configuration with name \\"some-env\\". - Before using \`--env=some-env\` there should be an equivalent environment section in the - configuration. + - No environment found in configuration with name \\"some-env\\". + Before using \`--env=some-env\` there should be an equivalent environment section in the + configuration. - Consider adding an environment configuration section to the wrangler.toml file: - \`\`\` - [env.some-env] - \`\`\` + Consider adding an environment configuration section to the wrangler.toml file: + \`\`\` + [env.some-env] + \`\`\` - " - `); + " + `); }); it("should throw an error when an environment name when provided, which doesn't match those in the config", async () => { - writeWranglerToml({ env: { "other-env": {} } }); + writeWranglerConfig({ env: { "other-env": {} } }); writeWorkerSource(); mockSubDomainRequest(); await expect( @@ -879,17 +879,17 @@ describe("deploy", () => { }); it("should throw an error w/ helpful message when using --env --name", async () => { - writeWranglerToml({ env: { "some-env": {} } }); + writeWranglerConfig({ env: { "some-env": {} } }); writeWorkerSource(); mockSubDomainRequest(); await runWrangler( "deploy index.js --name voyager --env some-env --legacy-env true" ).catch((err) => expect(err).toMatchInlineSnapshot(` - [Error: In legacy environment mode you cannot use --name and --env together. If you want to specify a Worker name for a specific environment you can add the following to your wrangler.toml config: - [env.some-env] - name = "voyager" - ] + [Error: In legacy environment mode you cannot use --name and --env together. If you want to specify a Worker name for a specific environment you can add the following to your wrangler.toml file: + [env.some-env] + name = "voyager" + ] `) ); }); @@ -897,7 +897,7 @@ describe("deploy", () => { describe("services", () => { it("uses the script name when no environment is specified", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -915,17 +915,17 @@ describe("deploy", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in - the future. DO NOT USE IN PRODUCTION. + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. - " - `); + " + `); }); it("publishes as an environment when provided", async () => { - writeWranglerToml({ env: { "some-env": {} } }); + writeWranglerConfig({ env: { "some-env": {} } }); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -945,13 +945,13 @@ describe("deploy", () => { `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in - the future. DO NOT USE IN PRODUCTION. + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. - " - `); + " + `); }); }); }); @@ -996,7 +996,7 @@ describe("deploy", () => { describe("routes", () => { it("should deploy the worker to a route", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], }); writeWorkerSource(); @@ -1007,7 +1007,7 @@ describe("deploy", () => { }); it("should deploy with an empty string route", async () => { - writeWranglerToml({ + writeWranglerConfig({ route: "", }); writeWorkerSource(); @@ -1037,7 +1037,7 @@ describe("deploy", () => { `); }); it("should deploy to a route with a pattern/{zone_id|zone_name} combo", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [ "some-example.com/some-route/*", { pattern: "*a-boring-website.com", zone_id: "54sdf7fsda" }, @@ -1086,7 +1086,7 @@ describe("deploy", () => { }); it("should deploy to a route with a SaaS domain", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, routes: [ { @@ -1126,7 +1126,7 @@ describe("deploy", () => { }); it("should deploy to a route with a SaaS subdomain", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, routes: [ { @@ -1166,7 +1166,7 @@ describe("deploy", () => { }); it("should deploy to a route with a pattern/{zone_id|zone_name} combo (service environments)", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { staging: { routes: [ @@ -1236,7 +1236,7 @@ describe("deploy", () => { }); it("should deploy to legacy environment specific routes", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], env: { dev: { @@ -1264,7 +1264,7 @@ describe("deploy", () => { }); it("services: should deploy to service environment specific routes", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], env: { dev: { @@ -1286,7 +1286,7 @@ describe("deploy", () => { }); it("should fallback to the Wrangler v1 zone-based API if the bulk-routes API fails", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], }); writeWorkerSource(); @@ -1337,7 +1337,7 @@ describe("deploy", () => { }); it("should error if the bulk-routes API fails and trying to push to a non-production environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["example.com/some-route/*"], legacy_env: false, }); @@ -1367,7 +1367,7 @@ describe("deploy", () => { describe("custom domains", () => { it("should deploy routes marked with 'custom_domain' as separate custom domains", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "api.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1387,7 +1387,7 @@ describe("deploy", () => { }); it("should confirm override if custom domain deploy would override an existing domain", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "api.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1432,7 +1432,7 @@ Update them to point to this script instead?`, }); it("should confirm override if custom domain deploy contains a conflicting DNS record", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "api.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1469,7 +1469,7 @@ Update them to point to this script instead?`, }); it("should confirm for conflicting custom domains and then again for conflicting dns", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "api.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1533,7 +1533,7 @@ Update them to point to this script instead?`, }); it("should throw if an invalid custom domain is requested", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "*.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1544,7 +1544,7 @@ Update them to point to this script instead?`, Wildcard operators (*) are not allowed in Custom Domains] `); - writeWranglerToml({ + writeWranglerConfig({ routes: [ { pattern: "api.example.com/at/a/path", custom_domain: true }, ], @@ -1561,7 +1561,7 @@ Update them to point to this script instead?`, }); it("should not continue with publishing an override if user does not confirm", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [{ pattern: "api.example.com", custom_domain: true }], }); writeWorkerSource(); @@ -1601,7 +1601,7 @@ Update them to point to this script instead?`, }); it("should error on routes with paths if assets are present", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [ "simple.co.uk/path", "simple.co.uk/path/*", @@ -1658,7 +1658,7 @@ Update them to point to this script instead?`, }); it("shouldn't error on routes with paths if there are no assets", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: [ "simple.co.uk/path", "simple.co.uk/path/*", @@ -1694,7 +1694,7 @@ Update them to point to this script instead?`, describe("entry-points", () => { it("should be able to use `index` with no extension as the entry-point (esm)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockUploadWorkerRequest({ expectedType: "esm" }); mockSubDomainRequest(); @@ -1713,7 +1713,7 @@ Update them to point to this script instead?`, }); it("should be able to use `index` with no extension as the entry-point (sw)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource({ type: "sw" }); mockUploadWorkerRequest({ expectedType: "sw", @@ -1735,7 +1735,7 @@ Update them to point to this script instead?`, }); it("should be able to use the `main` config as the entry-point for ESM sources", async () => { - writeWranglerToml({ main: "./index.js" }); + writeWranglerConfig({ main: "./index.js" }); writeWorkerSource(); mockUploadWorkerRequest(); mockSubDomainRequest(); @@ -1754,7 +1754,7 @@ Update them to point to this script instead?`, }); it("should use `main` relative to the wrangler.toml not cwd", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./foo/index.js", }); writeWorkerSource({ basePath: "foo" }); @@ -1775,7 +1775,7 @@ Update them to point to this script instead?`, }); it('should use `build.upload.main` as an entry point, where `build.upload.dir` defaults to "./dist", and log a deprecation warning', async () => { - writeWranglerToml({ build: { upload: { main: "./index.js" } } }); + writeWranglerConfig({ build: { upload: { main: "./index.js" } } }); writeWorkerSource({ basePath: "./dist" }); mockUploadWorkerRequest(); mockSubDomainRequest(); @@ -1792,21 +1792,21 @@ Update them to point to this script instead?`, `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Deprecation: \\"build.upload.main\\": - Delete the \`build.upload.main\` and \`build.upload.dir\` fields. - Then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"dist/index.js\\" - \`\`\` + - Deprecation: \\"build.upload.main\\": + Delete the \`build.upload.main\` and \`build.upload.dir\` fields. + Then add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"dist/index.js\\" + \`\`\` - " - `); + " + `); }); it("should use `build.upload.main` relative to `build.upload.dir`", async () => { - writeWranglerToml({ + writeWranglerConfig({ build: { upload: { main: "./index.js", @@ -1830,24 +1830,24 @@ Update them to point to this script instead?`, `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing ../wrangler.toml configuration: + "▲ [WARNING] Processing ../wrangler.toml configuration: - - Deprecation: \\"build.upload.main\\": - Delete the \`build.upload.main\` and \`build.upload.dir\` fields. - Then add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"foo/index.js\\" - \`\`\` - - Deprecation: \\"build.upload.dir\\": - Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the - Worker. + - Deprecation: \\"build.upload.main\\": + Delete the \`build.upload.main\` and \`build.upload.dir\` fields. + Then add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"foo/index.js\\" + \`\`\` + - Deprecation: \\"build.upload.dir\\": + Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the + Worker. - " - `); + " + `); }); it("should error when both `main` and `build.upload.main` are used", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", build: { upload: { @@ -1866,7 +1866,7 @@ Update them to point to this script instead?`, }); it("should be able to transpile TypeScript (esm)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource({ format: "ts" }); mockUploadWorkerRequest({ expectedEntry: "var foo = 100;" }); mockSubDomainRequest(); @@ -1884,7 +1884,7 @@ Update them to point to this script instead?`, }); it("should be able to transpile TypeScript (sw)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource({ format: "ts", type: "sw" }); mockUploadWorkerRequest({ expectedEntry: "var foo = 100;", @@ -1906,7 +1906,7 @@ Update them to point to this script instead?`, }); it("should add referenced text modules into the form upload", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", ` @@ -1939,7 +1939,7 @@ export default{ }); it("should allow cloudflare module import", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", ` @@ -1966,7 +1966,7 @@ export default{ }); it("should be able to transpile entry-points in sub-directories (esm)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource({ basePath: "./src" }); mockUploadWorkerRequest({ expectedEntry: "var foo = 100;" }); mockSubDomainRequest(); @@ -1985,7 +1985,7 @@ export default{ }); it("should preserve exports on a module format worker", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -2025,7 +2025,7 @@ export default {};` }); it("should not preserve exports on a service-worker format worker", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -2061,7 +2061,7 @@ addEventListener('fetch', event => {});` }); it("should be able to transpile entry-points in sub-directories (sw)", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource({ basePath: "./src", type: "sw" }); mockUploadWorkerRequest({ expectedEntry: "var foo = 100;", @@ -2084,7 +2084,7 @@ addEventListener('fetch', event => {});` }); it('should error if a site definition doesn\'t have a "bucket" field', async () => { - writeWranglerToml({ + writeWranglerConfig({ // @ts-expect-error we're intentionally setting an invalid config site: {}, }); @@ -2100,24 +2100,24 @@ addEventListener('fetch', event => {});` expect(std.out).toMatchInlineSnapshot(`""`); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] Processing wrangler.toml configuration: + "X [ERROR] Processing wrangler.toml configuration: - - \\"site.bucket\\" is a required field. + - \\"site.bucket\\" is a required field. - " - `); + " + `); expect(normalizeString(std.warn)).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Because you've defined a [site] configuration, we're defaulting to \\"workers-site\\" for the - deprecated \`site.entry-point\`field. - Add the top level \`main\` field to your configuration file: - \`\`\` - main = \\"workers-site/index.js\\" - \`\`\` + - Because you've defined a [site] configuration, we're defaulting to \\"workers-site\\" for the + deprecated \`site.entry-point\`field. + Add the top level \`main\` field to your configuration file: + \`\`\` + main = \\"workers-site/index.js\\" + \`\`\` - " - `); + " + `); }); it("should warn if there is a `site.entry-point` configuration", async () => { @@ -2130,7 +2130,7 @@ addEventListener('fetch', event => {});` id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ site: { "entry-point": "./index.js", bucket: "assets", @@ -2187,7 +2187,7 @@ addEventListener('fetch', event => {});` }; fs.mkdirSync("my-site"); process.chdir("my-site"); - writeWranglerToml({ + writeWranglerConfig({ site: { bucket: "assets", "entry-point": "my-entry", @@ -2237,7 +2237,7 @@ addEventListener('fetch', event => {});` }); it("should error if both main and site.entry-point are specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "some-entry", site: { bucket: "some-bucket", @@ -2255,7 +2255,7 @@ addEventListener('fetch', event => {});` }); it("should error if there is no entry-point specified", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockUploadWorkerRequest(); mockSubDomainRequest(); @@ -2302,9 +2302,7 @@ addEventListener('fetch', event => {});` 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. - - + ▲ [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 configuration file. " `); @@ -2342,7 +2340,7 @@ addEventListener('fetch', event => {});` } it("with TypeScript source file", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( `index.ts`, dedent`interface Env { @@ -2366,7 +2364,7 @@ addEventListener('fetch', event => {});` }); it("with additional modules", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, rules: [{ type: "ESModule", globs: ["**/*.js"] }], }); @@ -2407,7 +2405,7 @@ addEventListener('fetch', event => {});` }); it("with inline source map", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, }); @@ -2451,7 +2449,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -2495,7 +2493,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); writeWorkerSource(); @@ -2538,7 +2536,7 @@ addEventListener('fetch', event => {});` }); it("should error when trying to use --legacy-assets with a service-worker Worker", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); writeWorkerSource({ type: "sw" }); @@ -2559,7 +2557,7 @@ addEventListener('fetch', event => {});` }); it("should error if --legacy-assets and --site are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); writeWorkerSource(); @@ -2585,7 +2583,7 @@ addEventListener('fetch', event => {});` }); it("should error if --legacy-assets and config.site are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "xyz", @@ -2609,7 +2607,7 @@ addEventListener('fetch', event => {});` }); it("should error if config.legacy_assets and --site are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", legacy_assets: "abc", }); @@ -2631,7 +2629,7 @@ addEventListener('fetch', event => {});` }); it("should error if config.legacy_assets and config.site are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", legacy_assets: "abc", site: { @@ -2656,7 +2654,7 @@ addEventListener('fetch', event => {});` }); it("should warn if --legacy-assets is used", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); const assets = [ @@ -2709,7 +2707,7 @@ addEventListener('fetch', event => {});` }); it("should warn if config.legacy_assets is used", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", legacy_assets: "./assets", }); @@ -2770,7 +2768,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -2827,7 +2825,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -2893,7 +2891,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3006,7 +3004,7 @@ addEventListener('fetch', event => {});` title: "__test-name-some-env-workers_sites_assets", id: "__test-name-some-env-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3062,7 +3060,7 @@ addEventListener('fetch', event => {});` title: "__test-name-some-env-workers_sites_assets", id: "__test-name-some-env-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3117,7 +3115,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3158,7 +3156,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3205,7 +3203,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3252,7 +3250,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3300,7 +3298,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3348,7 +3346,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3396,7 +3394,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3450,7 +3448,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3504,7 +3502,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3555,7 +3553,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3599,7 +3597,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3691,7 +3689,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3731,7 +3729,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -3798,7 +3796,7 @@ addEventListener('fetch', event => {});` id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./src/index.js", site: { bucket: "assets", @@ -3849,7 +3847,7 @@ addEventListener('fetch', event => {});` }); it("should use the relative path from current working directory to Worker directory when using `--site`", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); const assets = [ @@ -3903,7 +3901,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); writeWorkerSource(); @@ -3957,7 +3955,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -4022,7 +4020,7 @@ addEventListener('fetch', event => {});` title: "__test-name-workers_sites_assets", id: "__test-name-workers_sites_assets-id", }; - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "assets", @@ -4303,7 +4301,7 @@ addEventListener('fetch', event => {});` { filePath: "configAsset.txt", content: "Content of file-2" }, ]; writeAssets(configAssets, "config-assets"); - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "config-assets" }, }); const bodies: AssetManifest[] = []; @@ -4329,7 +4327,7 @@ addEventListener('fetch', event => {});` }); it("should error if config.site and config.assets are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", assets: { directory: "abd" }, site: { @@ -4346,7 +4344,7 @@ addEventListener('fetch', event => {});` }); it("should error if --assets and config.site are used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", site: { bucket: "xyz", @@ -4370,7 +4368,7 @@ addEventListener('fetch', event => {});` }); it("should error if directory specified by config assets does not exist", async () => { - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "abc" }, }); await expect(runWrangler("deploy")).rejects.toThrow( @@ -4381,7 +4379,7 @@ addEventListener('fetch', event => {});` }); it("should error if an ASSET binding is provided without a user Worker", async () => { - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "xyz", binding: "ASSET", @@ -4402,7 +4400,7 @@ addEventListener('fetch', event => {});` { filePath: "béëp/boo^p.txt", content: "Content of file-3" }, ]; writeAssets(assets); - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "assets" }, }); @@ -4492,7 +4490,7 @@ addEventListener('fetch', event => {});` it("should resolve assets directory relative to wrangler.toml if using config", async () => { const assets = [{ filePath: "file-1.txt", content: "Content of file-1" }]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4530,7 +4528,7 @@ addEventListener('fetch', event => {});` { filePath: "sub-dir/file-5.txt", content: "Content of file-5" }, ]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4569,7 +4567,7 @@ addEventListener('fetch', event => {});` { filePath: "_worker.js", content: "// some secret server-side code." }, ]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4606,7 +4604,7 @@ addEventListener('fetch', event => {});` }, ]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4637,7 +4635,7 @@ addEventListener('fetch', event => {});` { filePath: "_worker.js", content: "// some secret server-side code." }, ]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4676,7 +4674,7 @@ addEventListener('fetch', event => {});` }, ]; writeAssets(assets, "some/path/assets"); - writeWranglerToml( + writeWranglerConfig( { assets: { directory: "assets" }, }, @@ -4776,7 +4774,7 @@ addEventListener('fetch', event => {});` { filePath: "boop/file-2.txt", content: "Content of file-2" }, ]; writeAssets(assets); - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "assets" }, }); const bodies: AssetManifest[] = []; @@ -4819,7 +4817,7 @@ addEventListener('fetch', event => {});` }, ]; writeAssets(assets); - writeWranglerToml({ + writeWranglerConfig({ assets: { directory: "assets" }, }); const mockBuckets = [ @@ -4924,7 +4922,7 @@ addEventListener('fetch', event => {});` ]; writeAssets(assets); writeWorkerSource({ format: "js" }); - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", compatibility_date: "2024-09-27", compatibility_flags: ["nodejs_compat"], @@ -4957,7 +4955,7 @@ addEventListener('fetch', event => {});` ]; writeAssets(assets); writeWorkerSource({ format: "js" }); - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2024-09-27", compatibility_flags: ["nodejs_compat"], assets: { @@ -4982,7 +4980,7 @@ addEventListener('fetch', event => {});` describe("workers_dev setting", () => { it("should deploy to a workers.dev domain if workers_dev is undefined", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockUploadWorkerRequest(); mockGetWorkerSubdomain({ enabled: false }); @@ -5003,7 +5001,7 @@ addEventListener('fetch', event => {});` }); it("should deploy to the workers.dev domain if workers_dev is `true`", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, }); writeWorkerSource(); @@ -5026,7 +5024,7 @@ addEventListener('fetch', event => {});` }); it("should not try to enable the workers.dev domain if it has been enabled before", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, }); writeWorkerSource(); @@ -5048,7 +5046,7 @@ addEventListener('fetch', event => {});` }); it("should disable the workers.dev domain if workers_dev is `false`", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, }); writeWorkerSource(); @@ -5069,7 +5067,7 @@ addEventListener('fetch', event => {});` }); it("should not try to disable the workers.dev domain if it is not already available", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, }); writeWorkerSource(); @@ -5091,7 +5089,7 @@ addEventListener('fetch', event => {});` }); it("should disable the workers.dev domain if workers_dev is undefined but overwritten to `false` in environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { dev: { workers_dev: false, @@ -5119,7 +5117,7 @@ addEventListener('fetch', event => {});` }); it("should disable the workers.dev domain if workers_dev is `true` but overwritten to `false` in environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, env: { dev: { @@ -5147,7 +5145,7 @@ addEventListener('fetch', event => {});` }); it("should deploy to a workers.dev domain if workers_dev is undefined but overwritten to `true` in environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { dev: { workers_dev: true, @@ -5177,7 +5175,7 @@ addEventListener('fetch', event => {});` }); it("should deploy to a workers.dev domain if workers_dev is `false` but overwritten to `true` in environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, env: { dev: { @@ -5208,7 +5206,7 @@ addEventListener('fetch', event => {});` }); it("should use the global compatibility_date and compatibility_flags if they are not overwritten by the environment", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2022-01-12", compatibility_flags: ["no_global_navigator"], env: { @@ -5239,7 +5237,7 @@ addEventListener('fetch', event => {});` }); it("should use the environment specific compatibility_date and compatibility_flags", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2022-01-12", compatibility_flags: ["no_global_navigator"], env: { @@ -5273,7 +5271,7 @@ addEventListener('fetch', event => {});` }); it("should use the command line --compatibility-date and --compatibility-flags if they are specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2022-01-12", compatibility_flags: ["no_global_navigator"], env: { @@ -5317,13 +5315,13 @@ addEventListener('fetch', event => {});` } expect(err?.message.replaceAll(/\d/g, "X")).toMatchInlineSnapshot(` - "A compatibility_date is required when publishing. Add the following to your wrangler.toml file:. - \`\`\` - compatibility_date = \\"XXXX-XX-XX\\" - \`\`\` - Or you could pass it in your terminal as \`--compatibility-date XXXX-XX-XX\` - See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information." - `); + "A compatibility_date is required when publishing. Add the following to your Wrangler configuration file: + \`\`\` + {\\"compatibility_date\\":\\"XXXX-XX-XX\\"} + \`\`\` + Or you could pass it in your terminal as \`--compatibility-date XXXX-XX-XX\` + See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information." + `); }); it("should error if a compatibility_date is missing and suggest the correct month", async () => { @@ -5340,17 +5338,17 @@ addEventListener('fetch', event => {});` } expect(err?.message).toMatchInlineSnapshot(` - "A compatibility_date is required when publishing. Add the following to your wrangler.toml file:. - \`\`\` - compatibility_date = \\"2020-12-01\\" - \`\`\` - Or you could pass it in your terminal as \`--compatibility-date 2020-12-01\` - See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information." - `); + "A compatibility_date is required when publishing. Add the following to your Wrangler configuration file: + \`\`\` + {\\"compatibility_date\\":\\"2020-12-01\\"} + \`\`\` + Or you could pass it in your terminal as \`--compatibility-date 2020-12-01\` + See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information." + `); }); it("should enable the workers.dev domain if workers_dev is undefined and subdomain is not already available", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockUploadWorkerRequest(); mockGetWorkerSubdomain({ enabled: false }); @@ -5371,7 +5369,7 @@ addEventListener('fetch', event => {});` }); it("should enable the workers.dev domain if workers_dev is true and subdomain is not already available", async () => { - writeWranglerToml({ workers_dev: true }); + writeWranglerConfig({ workers_dev: true }); writeWorkerSource(); mockUploadWorkerRequest(); mockGetWorkerSubdomain({ enabled: false }); @@ -5392,7 +5390,7 @@ addEventListener('fetch', event => {});` }); it("should fail to deploy to the workers.dev domain if email is unverified", async () => { - writeWranglerToml({ workers_dev: true }); + writeWranglerConfig({ workers_dev: true }); writeWorkerSource(); mockUploadWorkerRequest(); mockGetWorkerSubdomain({ enabled: false }); @@ -5426,7 +5424,7 @@ addEventListener('fetch', event => {});` }); it("should offer to create a new workers.dev subdomain when publishing to workers_dev without one", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, }); writeWorkerSource(); @@ -5441,13 +5439,13 @@ addEventListener('fetch', event => {});` await expect(runWrangler("deploy ./index")).rejects .toThrowErrorMatchingInlineSnapshot(` - [Error: You can either deploy your worker to one or more routes by specifying them in wrangler.toml, or register a workers.dev subdomain here: + [Error: You can either deploy your worker to one or more routes by specifying them in your wrangler.toml file, or register a workers.dev subdomain here: https://dash.cloudflare.com/some-account-id/workers/onboarding] `); }); it("should not deploy to workers.dev if there are any routes defined", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["http://example.com/*"], }); writeWorkerSource(); @@ -5472,7 +5470,7 @@ addEventListener('fetch', event => {});` }); it("should not deploy to workers.dev if there are any routes defined (environments)", async () => { - writeWranglerToml({ + writeWranglerConfig({ routes: ["http://example.com/*"], env: { production: { @@ -5509,7 +5507,7 @@ addEventListener('fetch', event => {});` }); it("should not deploy to workers.dev if there are any routes defined (only in environments)", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { production: { routes: ["http://production.example.com/*"], @@ -5546,7 +5544,7 @@ addEventListener('fetch', event => {});` }); it("can deploy to both workers.dev and routes if both defined ", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, routes: ["http://example.com/*"], }); @@ -5578,7 +5576,7 @@ addEventListener('fetch', event => {});` }); it("can deploy to both workers.dev and routes if both defined (environments: 1)", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: true, env: { production: { @@ -5620,7 +5618,7 @@ addEventListener('fetch', event => {});` }); it("can deploy to both workers.dev and routes if both defined (environments: 2)", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { production: { workers_dev: true, @@ -5662,7 +5660,7 @@ addEventListener('fetch', event => {});` }); it("will deploy only to routes when workers_dev is false (environments 1) ", async () => { - writeWranglerToml({ + writeWranglerConfig({ workers_dev: false, env: { production: { @@ -5700,7 +5698,7 @@ addEventListener('fetch', event => {});` }); it("will deploy only to routes when workers_dev is false (environments 2) ", async () => { - writeWranglerToml({ + writeWranglerConfig({ env: { production: { workers_dev: false, @@ -5740,7 +5738,7 @@ addEventListener('fetch', event => {});` describe("[define]", () => { it("should be able to define values that will be substituted into top-level identifiers", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", define: { abc: "123", @@ -5780,7 +5778,7 @@ addEventListener('fetch', event => {});` }); it("can be overriden in environments", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", define: { abc: "123", @@ -5812,7 +5810,7 @@ addEventListener('fetch', event => {});` }); it("can be overridden with cli args", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", define: { abc: "123", @@ -5834,7 +5832,7 @@ addEventListener('fetch', event => {});` }); it("can be overridden with cli args containing colons", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", define: { abc: "123", @@ -5864,7 +5862,7 @@ addEventListener('fetch', event => {});` vi.unstubAllGlobals(); }); it("should run a custom build before publishing", async () => { - writeWranglerToml({ + writeWranglerConfig({ build: { command: `node -e "4+4; require('fs').writeFileSync('index.js', 'export default { fetch(){ return new Response(123) } }')"`, }, @@ -5891,7 +5889,7 @@ addEventListener('fetch', event => {});` if (process.platform !== "win32") { it("should run a custom build of multiple steps combined by && before publishing", async () => { - writeWranglerToml({ + writeWranglerConfig({ build: { command: `echo "export default { fetch(){ return new Response(123) } }" > index.js`, }, @@ -5918,7 +5916,7 @@ addEventListener('fetch', event => {});` } it("should throw an error if the entry doesn't exist after the build finishes", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", build: { command: `node -e "4+4;"`, @@ -5928,24 +5926,25 @@ addEventListener('fetch', event => {});` await expect(runWrangler("deploy index.js")).rejects .toThrowErrorMatchingInlineSnapshot(` [Error: The expected output file at "index.js" was not found after running custom build: node -e "4+4;". - The \`main\` property in wrangler.toml should point to the file generated by the custom build.] + The \`main\` property in your wrangler.toml file should point to the file generated by the custom build.] `); expect(std.out).toMatchInlineSnapshot(` "Running custom build: node -e \\"4+4;\\" " `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\". + "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"4+4;\\". - The \`main\` property in wrangler.toml should point to the file generated by the custom build. + The \`main\` property in your wrangler.toml file should point to the file generated by the custom + build. - " - `); + " + `); expect(std.warn).toMatchInlineSnapshot(`""`); }); it("should throw an error if the entry is a directory after the build finishes", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./", build: { command: `node -e "4+4;"`, @@ -5959,7 +5958,7 @@ addEventListener('fetch', event => {});` await expect(runWrangler("deploy")).rejects .toThrowErrorMatchingInlineSnapshot(` [Error: The expected output file at "." was not found after running custom build: node -e "4+4;". - The \`main\` property in wrangler.toml should point to the file generated by the custom build. + The \`main\` property in your wrangler.toml file should point to the file generated by the custom build. The provided entry-point path, ".", points to a directory, rather than a file. Did you mean to set the main field to one of: @@ -5973,24 +5972,25 @@ addEventListener('fetch', event => {});` " `); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\". + "X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"4+4;\\". - The \`main\` property in wrangler.toml should point to the file generated by the custom build. - The provided entry-point path, \\".\\", points to a directory, rather than a file. + The \`main\` property in your wrangler.toml file should point to the file generated by the custom + build. + The provided entry-point path, \\".\\", points to a directory, rather than a file. - Did you mean to set the main field to one of: - \`\`\` - main = \\"./worker.js\\" - main = \\"./dist/index.ts\\" - \`\`\` + Did you mean to set the main field to one of: + \`\`\` + main = \\"./worker.js\\" + main = \\"./dist/index.ts\\" + \`\`\` - " - `); + " + `); expect(std.warn).toMatchInlineSnapshot(`""`); }); it("should minify the script when `--minify` is true (sw)", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", }); fs.writeFileSync( @@ -6022,7 +6022,7 @@ addEventListener('fetch', event => {});` }); it("should minify the script when `minify` in config is true (esm)", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "./index.js", legacy_env: false, env: { @@ -6065,7 +6065,7 @@ addEventListener('fetch', event => {});` describe("durable object migrations", () => { it("should warn when you try to deploy durable objects without migrations", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [{ name: "SOMENAME", class_name: "SomeClass" }], }, @@ -6090,28 +6090,29 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass), - but no [migrations] for them. This may not work as expected until you add a [migrations] section - to your wrangler.toml. Add this configuration to your wrangler.toml: + - In your wrangler.toml file, you have configured \`durable_objects\` exported by this Worker + (SomeClass), but no \`migrations\` for them. This may not work as expected until you add a + \`migrations\` section to your wrangler.toml file. Add the following configuration: - \`\`\` - [[migrations]] - tag = \\"v1\\" # Should be unique for each entry - new_classes = [\\"SomeClass\\"] - \`\`\` + \`\`\` + [[migrations]] + tag = \\"v1\\" + new_classes = [ \\"SomeClass\\" ] - Refer to - https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ for more - details. + \`\`\` - " - `); + Refer to + https://developers.cloudflare.com/durable-objects/reference/durable-objects-migrations/ for more + details. + + " + `); }); it("does not warn if all the durable object bindings are to external classes", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -6145,7 +6146,7 @@ addEventListener('fetch', event => {});` }); it("should deploy all migrations on first deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6192,7 +6193,7 @@ addEventListener('fetch', event => {});` }); it("should upload migrations past a previously uploaded tag", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6247,7 +6248,7 @@ addEventListener('fetch', event => {});` }); it("should not send migrations if they've all already been sent", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6295,7 +6296,7 @@ addEventListener('fetch', event => {});` describe("service environments", () => { it("should deploy all migrations on first deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6340,17 +6341,17 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in - the future. DO NOT USE IN PRODUCTION. + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. - " - `); + " + `); }); it("should deploy all migrations on first deploy (--env)", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6406,17 +6407,17 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in - the future. DO NOT USE IN PRODUCTION. + - Experimental: Service environments are in beta, and their behaviour is guaranteed to change in + the future. DO NOT USE IN PRODUCTION. - " - `); + " + `); }); it("should use a script's current migration tag when publishing migrations", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6479,7 +6480,7 @@ addEventListener('fetch', event => {});` }); it("should use an environment's current migration tag when publishing migrations", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6554,7 +6555,7 @@ addEventListener('fetch', event => {});` describe("dispatch namespaces", () => { it("should deploy all migrations on first deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6603,7 +6604,7 @@ addEventListener('fetch', event => {});` }); it("should use a script's current migration tag when publishing migrations", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { name: "SOMENAME", class_name: "SomeClass" }, @@ -6658,7 +6659,7 @@ addEventListener('fetch', event => {});` describe("tail consumers", () => { it("should allow specifying workers as tail consumers", async () => { - writeWranglerToml({ + writeWranglerConfig({ tail_consumers: [ { service: "listener " }, { service: "test-listener", environment: "production" }, @@ -6687,7 +6688,7 @@ addEventListener('fetch', event => {});` describe("user limits", () => { it("should allow specifying a cpu millisecond limit", async () => { - writeWranglerToml({ + writeWranglerConfig({ limits: { cpu_ms: 15_000 }, }); @@ -6711,7 +6712,7 @@ addEventListener('fetch', event => {});` describe("bindings", () => { it("should allow bindings with different names", async () => { - writeWranglerToml({ + writeWranglerConfig({ migrations: [ { tag: "v1", @@ -6970,16 +6971,16 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); it("should error when bindings of different types have the same name", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -7082,16 +7083,16 @@ addEventListener('fetch', event => {});` " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); it("should error when bindings of the same type have the same name", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -7190,16 +7191,16 @@ addEventListener('fetch', event => {});` " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); it("should error correctly when bindings of the same and different types use the same name", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -7346,17 +7347,17 @@ addEventListener('fetch', event => {});` " `); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); describe("[wasm_modules]", () => { it("should be able to define wasm modules for service-worker format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ wasm_modules: { TESTWASMNAME: "./path/to/test.wasm", }, @@ -7391,7 +7392,7 @@ addEventListener('fetch', event => {});` }); it("should error when defining wasm modules for modules format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ wasm_modules: { TESTWASMNAME: "./path/to/test.wasm", }, @@ -7461,7 +7462,7 @@ addEventListener('fetch', event => {});` }); it("should be able to import .wasm modules from service-worker format workers", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", "import TESTWASMNAME from './test.wasm';" @@ -7499,7 +7500,7 @@ addEventListener('fetch', event => {});` describe("[text_blobs]", () => { it("should be able to define text blobs for service-worker format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ text_blobs: { TESTTEXTBLOBNAME: "./path/to/text.file", }, @@ -7537,7 +7538,7 @@ addEventListener('fetch', event => {});` }); it("should error when defining text blobs for modules format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ text_blobs: { TESTTEXTBLOBNAME: "./path/to/text.file", }, @@ -7549,14 +7550,14 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy index.js") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml]` + `[Error: You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml file]` ); expect(std.out).toMatchInlineSnapshot(`""`); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml + "X [ERROR] You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml file - " - `); + " + `); expect(std.warn).toMatchInlineSnapshot(`""`); }); @@ -7613,7 +7614,7 @@ addEventListener('fetch', event => {});` describe("[data_blobs]", () => { it("should be able to define data blobs for service-worker format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ data_blobs: { TESTDATABLOBNAME: "./path/to/data.bin", }, @@ -7651,7 +7652,7 @@ addEventListener('fetch', event => {});` }); it("should error when defining data blobs for modules format workers", async () => { - writeWranglerToml({ + writeWranglerConfig({ data_blobs: { TESTDATABLOBNAME: "./path/to/data.bin", }, @@ -7663,14 +7664,14 @@ addEventListener('fetch', event => {});` await expect( runWrangler("deploy index.js") ).rejects.toThrowErrorMatchingInlineSnapshot( - `[Error: You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml]` + `[Error: You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml file]` ); expect(std.out).toMatchInlineSnapshot(`""`); expect(std.err).toMatchInlineSnapshot(` - "X [ERROR] You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml + "X [ERROR] You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml file - " - `); + " + `); expect(std.warn).toMatchInlineSnapshot(`""`); }); @@ -7727,7 +7728,7 @@ addEventListener('fetch', event => {});` describe("[vars]", () => { it("should support json bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ vars: { text: "plain ol' string", count: 1, @@ -7770,7 +7771,7 @@ addEventListener('fetch', event => {});` }); it("should read vars passed as cli arguments", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -7798,7 +7799,7 @@ addEventListener('fetch', event => {});` describe("[r2_buckets]", () => { it("should support r2 bucket bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ r2_buckets: [{ binding: "FOO", bucket_name: "foo-bucket" }], }); writeWorkerSource(); @@ -7828,7 +7829,7 @@ addEventListener('fetch', event => {});` describe("[logfwdr]", () => { it("should support logfwdr bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ logfwdr: { bindings: [ { @@ -7877,7 +7878,7 @@ addEventListener('fetch', event => {});` }); it("should error when logfwdr schemas are specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ logfwdr: { // @ts-expect-error this property been replaced with the unsafe.capnp section schema: "./message.capnp.compiled", @@ -7904,7 +7905,7 @@ addEventListener('fetch', event => {});` describe("[durable_objects]", () => { it("should support durable object bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -7950,7 +7951,7 @@ addEventListener('fetch', event => {});` }); it("should support durable object bindings to SQLite classes", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -7998,7 +7999,7 @@ addEventListener('fetch', event => {});` }); it("should support service-workers binding to external durable objects", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -8041,7 +8042,7 @@ addEventListener('fetch', event => {});` }); it("should support module workers implementing durable objects", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -8088,7 +8089,7 @@ addEventListener('fetch', event => {});` }); it("should support durable objects and D1", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", durable_objects: { bindings: [ @@ -8146,7 +8147,7 @@ addEventListener('fetch', event => {});` }); it("should error when detecting a service-worker worker implementing durable objects", async () => { - writeWranglerToml({ + writeWranglerConfig({ durable_objects: { bindings: [ { @@ -8162,7 +8163,7 @@ addEventListener('fetch', event => {});` await expect(runWrangler("deploy index.js")).rejects .toThrowErrorMatchingInlineSnapshot(` [Error: You seem to be trying to use Durable Objects in a Worker written as a service-worker. - You can use Durable Objects defined in other Workers by specifying a \`script_name\` in your wrangler.toml, where \`script_name\` is the name of the Worker that implements that Durable Object. For example: + You can use Durable Objects defined in other Workers by specifying a \`script_name\` in your wrangler.toml file, where \`script_name\` is the name of the Worker that implements that Durable Object. For example: { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject } ==> { name = EXAMPLE_DO_BINDING, class_name = ExampleDurableObject, script_name = example-do-binding-worker } Alternatively, migrate your worker to ES Module syntax to implement a Durable Object in this Worker: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/] @@ -8172,7 +8173,7 @@ addEventListener('fetch', event => {});` describe("[services]", () => { it("should support service bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ services: [ { binding: "FOO", @@ -8211,7 +8212,7 @@ addEventListener('fetch', event => {});` }); it("should support service bindings with entrypoints", async () => { - writeWranglerToml({ + writeWranglerConfig({ services: [ { binding: "FOO", @@ -8254,7 +8255,7 @@ addEventListener('fetch', event => {});` describe("[analytics_engine_datasets]", () => { it("should support analytics engine bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ analytics_engine_datasets: [ { binding: "FOO", dataset: "foo-dataset" }, ], @@ -8286,7 +8287,7 @@ addEventListener('fetch', event => {});` describe("[dispatch_namespaces]", () => { it("should support bindings to a dispatch namespace", async () => { - writeWranglerToml({ + writeWranglerConfig({ dispatch_namespaces: [ { binding: "foo", @@ -8322,7 +8323,7 @@ addEventListener('fetch', event => {});` }); it("should support dispatch namespace bindings with an outbound worker", async () => { - writeWranglerToml({ + writeWranglerConfig({ dispatch_namespaces: [ { binding: "foo", @@ -8387,7 +8388,7 @@ addEventListener('fetch', event => {});` }); it("should support dispatch namespace bindings with parameterized outbounds", async () => { - writeWranglerToml({ + writeWranglerConfig({ dispatch_namespaces: [ { binding: "foo", @@ -8446,7 +8447,7 @@ addEventListener('fetch', event => {});` describe("[unsafe]", () => { describe("[unsafe.bindings]", () => { it("should stringify object in unsafe metadata", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { metadata: { stringify: true, @@ -8487,7 +8488,7 @@ addEventListener('fetch', event => {});` }); it("should warn if using unsafe bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { bindings: [ { @@ -8525,16 +8526,16 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); it("should warn if using unsafe bindings already handled by wrangler", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { bindings: [ { @@ -8572,22 +8573,22 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. - - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"} - - The binding type \\"plain_text\\" is directly supported by wrangler. - Consider migrating this unsafe binding to a format for 'plain_text' bindings that is - supported by wrangler for optimal support. - For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration + - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe.bindings[0]\\": {\\"name\\":\\"my-binding\\",\\"type\\":\\"plain_text\\",\\"text\\":\\"text\\"} + - The binding type \\"plain_text\\" is directly supported by wrangler. + Consider migrating this unsafe binding to a format for 'plain_text' bindings that is + supported by wrangler for optimal support. + For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration - " - `); + " + `); }); }); describe("[unsafe.capnp]", () => { it("should accept a pre-compiled capnp schema", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { capnp: { compiled_schema: "./my-compiled-schema", @@ -8612,15 +8613,15 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); it("should error when both pre-compiled and uncompiled-capnp schemas are used", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { capnp: { compiled_schema: "./my-compiled-schema", @@ -8638,7 +8639,7 @@ addEventListener('fetch', event => {});` `); }); it("should error when no schemas are specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ unsafe: { // @ts-expect-error This should error as the types expect something to be present capnp: {}, @@ -8655,7 +8656,7 @@ addEventListener('fetch', event => {});` }); it("should error when the capnp compiler is not present, but is required", async () => { (sync as Mock).mockReturnValue(false); - writeWranglerToml({ + writeWranglerConfig({ unsafe: { capnp: { base_path: "./", @@ -8690,7 +8691,7 @@ addEventListener('fetch', event => {});` }; }); - writeWranglerToml({ + writeWranglerConfig({ unsafe: { capnp: { base_path: "./", @@ -8716,12 +8717,12 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - \\"unsafe\\" fields are experimental and may change or break at any time. + - \\"unsafe\\" fields are experimental and may change or break at any time. - " - `); + " + `); }); }); }); @@ -8729,7 +8730,7 @@ addEventListener('fetch', event => {});` describe("upload rules", () => { it("should be able to define rules for uploading non-js modules (sw)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }], }); fs.writeFileSync("./index.js", `import TEXT from './text.file';`); @@ -8764,7 +8765,7 @@ addEventListener('fetch', event => {});` }); it("should be able to define rules for uploading non-js modules (esm)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }], }); fs.writeFileSync( @@ -8795,7 +8796,7 @@ addEventListener('fetch', event => {});` }); it("should log a deprecation warning when using `build.upload.rules`", async () => { - writeWranglerToml({ + writeWranglerConfig({ build: { upload: { rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }], @@ -8827,24 +8828,24 @@ addEventListener('fetch', event => {});` `); expect(std.err).toMatchInlineSnapshot(`""`); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] Processing wrangler.toml configuration: + "▲ [WARNING] Processing wrangler.toml configuration: - - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be - specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration - file, and add this: - \`\`\` - [[rules]] - type = \\"Text\\" - globs = [ \\"**/*.file\\" ] - fallthrough = true - \`\`\` + - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be + specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration + file, and add this: + \`\`\` + [[rules]] + type = \\"Text\\" + globs = [ \\"**/*.file\\" ] + fallthrough = true + \`\`\` - " - `); + " + `); }); it("should be able to use fallthrough:true for multiple rules", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [ { type: "Text", globs: ["**/*.file"], fallthrough: true }, { type: "Text", globs: ["**/*.other"], fallthrough: true }, @@ -8881,7 +8882,7 @@ addEventListener('fetch', event => {});` }); it("should be able to use fallthrough:false for multiple rules", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [ { type: "Text", globs: ["**/*.file"], fallthrough: false }, { type: "Text", globs: ["**/*.other"] }, @@ -8908,7 +8909,7 @@ addEventListener('fetch', event => {});` }); it("should warn when multiple rules for the same type do not have fallback defined", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [ { type: "Text", globs: ["**/*.file"] }, { type: "Text", globs: ["**/*.other"] }, @@ -8947,7 +8948,7 @@ addEventListener('fetch', event => {});` }); it("should be able to preserve file names when defining rules for uploading non-js modules (sw)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }], preserve_file_names: true, }); @@ -8982,7 +8983,7 @@ addEventListener('fetch', event => {});` }); it("should be able to preserve file names when defining rules for uploading non-js modules (esm)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: true }], preserve_file_names: true, }); @@ -9018,7 +9019,7 @@ addEventListener('fetch', event => {});` }); it("should replace `process.env.NODE_ENV` in scripts", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", `export default { @@ -9048,7 +9049,7 @@ addEventListener('fetch', event => {});` describe("service worker format", () => { it("should error if trying to import a cloudflare prefixed external when in service worker format", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "dep-1.js", dedent` @@ -9094,7 +9095,7 @@ addEventListener('fetch', event => {});` }); it("should error if importing a node.js library when in service worker format", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", dedent` @@ -9125,7 +9126,7 @@ addEventListener('fetch', event => {});` }); it("should error if nodejs_compat (v2) is turned on when in service worker format", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2024-09-23", // Sept 23 to turn on nodejs compat v2 mode compatibility_flags: ["nodejs_compat"], }); @@ -9159,7 +9160,7 @@ addEventListener('fetch', event => {});` describe("legacy module specifiers", () => { it("should work with legacy module specifiers, with a deprecation warning (1)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: false }], }); fs.writeFileSync( @@ -9192,7 +9193,7 @@ addEventListener('fetch', event => {});` }); it("should work with legacy module specifiers, with a deprecation warning (2)", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", `import WASM from 'index.wasm'; export default {};` @@ -9223,7 +9224,7 @@ addEventListener('fetch', event => {});` }); it("should work with legacy module specifiers, with a deprecation warning (3)", async () => { - writeWranglerToml({ + writeWranglerConfig({ rules: [{ type: "Text", globs: ["**/*.file"], fallthrough: false }], }); fs.writeFileSync( @@ -9285,7 +9286,7 @@ addEventListener('fetch', event => {});` describe("tsconfig", () => { it("should use compilerOptions.paths to resolve modules", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.ts", }); fs.writeFileSync( @@ -9327,7 +9328,7 @@ addEventListener('fetch', event => {});` }); it("should output to target es2022 even if tsconfig says otherwise", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); fs.writeFileSync( "./index.js", @@ -9381,7 +9382,7 @@ addEventListener('fetch', event => {});` describe("--outdir", () => { it("should generate built assets at --outdir if specified", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -9405,7 +9406,7 @@ addEventListener('fetch', event => {});` }); it("should preserve the entry point file name, even when using a facade", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -9446,7 +9447,7 @@ addEventListener('fetch', event => {});` }); it("should copy any module imports related assets to --outdir if specified", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "./index.js", ` @@ -9505,7 +9506,7 @@ export default{ describe("--dry-run", () => { it("should not deploy the worker if --dry-run is specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ // add a durable object with migrations // to make sure we _don't_ fetch migration status durable_objects: { @@ -9542,7 +9543,7 @@ export default{ describe("--node-compat", () => { it("should warn when using node compatibility mode", async () => { - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); await runWrangler("deploy index.js --node-compat --dry-run"); expect(std).toMatchInlineSnapshot(` @@ -9560,7 +9561,7 @@ export default{ }); it("should recommend node compatibility flag when using node builtins and no node compat is enabled", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync("index.js", "import path from 'path';"); await expect( @@ -9585,7 +9586,7 @@ export default{ }); it("should recommend node compatibility flag when using node builtins and node compat is set only to nodejs_als", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_flags: ["nodejs_als"], }); fs.writeFileSync("index.js", "import path from 'path';"); @@ -9612,7 +9613,7 @@ export default{ }); it("should recommend node compatibility flag when using node builtins and `node_compat` is true", async () => { - writeWranglerToml({ + writeWranglerConfig({ node_compat: true, }); fs.writeFileSync("index.js", "import fs from 'diagnostics_channel';"); @@ -9639,7 +9640,7 @@ export default{ }); it("should recommend updating the compatibility date when using node builtins and the `nodejs_compat` flag", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2024-09-01", // older than Sept 23rd, 2024 compatibility_flags: ["nodejs_compat"], }); @@ -9667,7 +9668,7 @@ export default{ }); it("should recommend updating the compatibility date flag when using no_nodejs_compat and non-prefixed node builtins", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2024-09-23", compatibility_flags: ["nodejs_compat", "no_nodejs_compat_v2"], }); @@ -9695,7 +9696,7 @@ export default{ }); it("should polyfill node builtins when enabled", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -9722,7 +9723,7 @@ export default{ describe("`nodejs_compat` compatibility flag", () => { it('when absent, should warn on any "external" `node:*` imports', async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -9746,7 +9747,7 @@ export default{ }); it('when present, should support "external" `node:*` imports', async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -9776,7 +9777,7 @@ export default{ }); it(`when present, and compat date is on or after 2024-09-23, should support "external" non-prefixed node imports`, async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_date: "2024-09-23", }); fs.writeFileSync( @@ -9808,7 +9809,7 @@ export default{ }); it("should conflict with the --node-compat option", async () => { - writeWranglerToml(); + writeWranglerConfig(); fs.writeFileSync( "index.js", ` @@ -9858,7 +9859,7 @@ export default{ }, };` ); - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", }); mockSubDomainRequest(); @@ -9923,7 +9924,7 @@ export default{ };` ); - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", }); @@ -9994,7 +9995,7 @@ export default{ }` ); - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", }); @@ -10062,7 +10063,7 @@ export default{ }` ); - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", }); @@ -10164,7 +10165,7 @@ export default{ describe("--no-bundle", () => { it("(cli) should not transform the source code before publishing it", async () => { - writeWranglerToml(); + writeWranglerConfig(); const scriptContent = ` import X from '@cloudflare/no-such-package'; // let's add an import that doesn't exist const xyz = 123; // a statement that would otherwise be compiled out @@ -10175,7 +10176,7 @@ export default{ }); it("(config) should not transform the source code before publishing it", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, }); const scriptContent = ` @@ -10190,7 +10191,7 @@ export default{ describe("--no-bundle --minify", () => { it("should warn that no-bundle and minify can't be used together", async () => { - writeWranglerToml(); + writeWranglerConfig(); const scriptContent = ` const xyz = 123; // a statement that would otherwise be compiled out `; @@ -10206,7 +10207,7 @@ export default{ }); it("should warn that no-bundle and minify can't be used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, minify: true, }); @@ -10225,7 +10226,7 @@ export default{ describe("--no-bundle --node-compat", () => { it("should warn that no-bundle and node-compat can't be used together", async () => { - writeWranglerToml(); + writeWranglerConfig(); const scriptContent = ` const xyz = 123; // a statement that would otherwise be compiled out `; @@ -10244,7 +10245,7 @@ export default{ }); it("should warn that no-bundle and node-compat can't be used together", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, node_compat: true, }); @@ -10268,7 +10269,7 @@ export default{ const queueId = "queue-id"; const queueName = "queue1"; it("should upload producer bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { producers: [{ binding: "QUEUE_ONE", queue: "queue1" }], }, @@ -10316,7 +10317,7 @@ export default{ }); it("should update queue producers on deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { producers: [ { @@ -10363,7 +10364,7 @@ export default{ }); it("should post worker queue consumers on deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10416,7 +10417,7 @@ export default{ it("should post worker queue consumers on deploy, using command line script name arg", async () => { const expectedScriptName = "command-line-arg-script-name"; - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10468,7 +10469,7 @@ export default{ }); it("should update worker queue consumers on deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10528,7 +10529,7 @@ export default{ }); it("should update worker (service) queue consumers with default environment on deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10593,7 +10594,7 @@ export default{ }); it("should post queue http consumers on deploy", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10645,7 +10646,7 @@ export default{ }); it("should update queue http consumers when one already exists for queue", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10705,7 +10706,7 @@ export default{ }); it("should support queue consumer concurrency with a max concurrency specified", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10765,7 +10766,7 @@ export default{ }); it("should support queue consumer concurrency with a null max concurrency", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10826,7 +10827,7 @@ export default{ }); it("should support queue consumer with max_batch_timeout of 0", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { consumers: [ { @@ -10887,7 +10888,7 @@ export default{ }); it("consumer should error when a queue doesn't exist", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { producers: [], consumers: [ @@ -10914,7 +10915,7 @@ export default{ }); it("producer should error when a queue doesn't exist", async () => { - writeWranglerToml({ + writeWranglerConfig({ queues: { producers: [{ queue: queueName, binding: "QUEUE_ONE" }], consumers: [], @@ -10935,7 +10936,7 @@ export default{ describe("source maps", () => { it("should include source map with bundle when upload_source_maps = true", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.ts", upload_source_maps: true, }); @@ -10955,7 +10956,7 @@ export default{ }); it("should not include source map with bundle when upload_source_maps = false", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.ts", upload_source_maps: false, }); @@ -10973,7 +10974,7 @@ export default{ }); it("should include source maps emitted by custom build when upload_source_maps = true", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, main: "index.js", upload_source_maps: true, @@ -11010,7 +11011,7 @@ export default{ }); it("should not include source maps emitted by custom build when upload_source_maps = false", async () => { - writeWranglerToml({ + writeWranglerConfig({ no_bundle: true, main: "index.js", upload_source_maps: false, @@ -11045,7 +11046,7 @@ export default{ }); it("should correctly read sourcemaps with custom wrangler.toml location", async () => { fs.mkdirSync("some/dir", { recursive: true }); - writeWranglerToml( + writeWranglerConfig( { main: "../../index.ts", upload_source_maps: true, @@ -11070,7 +11071,7 @@ export default{ describe("ai", () => { it("should upload ai bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ ai: { binding: "AI_BIND" }, browser: { binding: "MYBROWSER" }, }); @@ -11108,7 +11109,7 @@ export default{ describe("python", () => { it("should upload python module defined in wrangler.toml", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.py", compatibility_flags: ["python_workers"], }); @@ -11145,7 +11146,7 @@ export default{ }); it("should upload python module specified in CLI args", async () => { - writeWranglerToml({ + writeWranglerConfig({ compatibility_flags: ["python_workers"], }); await fs.promises.writeFile( @@ -11183,7 +11184,7 @@ export default{ describe("hyperdrive", () => { it("should upload hyperdrive bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ hyperdrive: [ { binding: "HYPERDRIVE", @@ -11220,7 +11221,7 @@ export default{ describe("mtls_certificates", () => { it("should upload mtls_certificate bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ mtls_certificates: [{ binding: "CERT_ONE", certificate_id: "1234" }], }); await fs.promises.writeFile("index.js", `export default {};`); @@ -11252,7 +11253,7 @@ export default{ describe("pipelines", () => { it("should upload pipelines bindings", async () => { - writeWranglerToml({ + writeWranglerConfig({ pipelines: [ { binding: "MY_PIPELINE", @@ -11292,7 +11293,7 @@ export default{ vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "some-account-id"); setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest({ keepVars: true, keepSecrets: true }); @@ -11316,7 +11317,7 @@ export default{ vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "some-account-id"); setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -11340,7 +11341,7 @@ export default{ vi.stubEnv("CLOUDFLARE_API_TOKEN", "hunter2"); vi.stubEnv("CLOUDFLARE_ACCOUNT_ID", "some-account-id"); setIsTTY(false); - writeWranglerToml({ + writeWranglerConfig({ keep_vars: true, }); writeWorkerSource(); @@ -11365,7 +11366,7 @@ export default{ describe("--dispatch-namespace", () => { it("should upload to dispatch namespace", async () => { - writeWranglerToml(); + writeWranglerConfig(); const scriptContent = ` export default { fetch() { @@ -11394,7 +11395,7 @@ export default{ describe("[observability]", () => { it("should allow uploading workers with observability", async () => { - writeWranglerToml({ + writeWranglerConfig({ observability: { enabled: true, head_sampling_rate: 0.5, @@ -11421,7 +11422,7 @@ export default{ }); it("should allow uploading workers with nested observability logs setting", async () => { - writeWranglerToml({ + writeWranglerConfig({ observability: { enabled: true, head_sampling_rate: 0.5, @@ -11458,7 +11459,7 @@ export default{ }); it("should disable observability if not explicitly defined", async () => { - writeWranglerToml({}); + writeWranglerConfig({}); await fs.promises.writeFile("index.js", `export default {};`); mockSubDomainRequest(); mockUploadWorkerRequest({ @@ -11498,7 +11499,7 @@ export default{ } it("should log open-beta warning when deploying a workflow", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", workflows: [ { diff --git a/packages/wrangler/src/__tests__/deployments.test.ts b/packages/wrangler/src/__tests__/deployments.test.ts index 8328aa5bff5c..1eaebd6cd189 100644 --- a/packages/wrangler/src/__tests__/deployments.test.ts +++ b/packages/wrangler/src/__tests__/deployments.test.ts @@ -15,7 +15,7 @@ import { } from "./helpers/msw"; import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; -import { writeWranglerToml } from "./helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "./helpers/write-wrangler-config"; function isFileNotFound(e: unknown) { return ( @@ -66,18 +66,17 @@ describe("deployments", () => { wrangler deployments status View the current state of your production GLOBAL FLAGS - -j, --experimental-json-config Experimental: support wrangler.json [boolean] - -c, --config Path to .toml configuration file [string] - -e, --env Environment to use for operations and .env files [string] - -h, --help Show help [boolean] - -v, --version Show version number [boolean]" + -c, --config Path to Wrangler configuration file [string] + -e, --env Environment to use for operations and .env files [string] + -h, --help Show help [boolean] + -v, --version Show version number [boolean]" `); }); describe("deployments subcommands", () => { describe("deployments list", () => { it("should log deployments", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler("deployments list --no-x-versions"); expect(std.out).toMatchInlineSnapshot(` @@ -144,14 +143,14 @@ describe("deployments", () => { await expect( runWrangler("deployments list --no-x-versions") ).rejects.toMatchInlineSnapshot( - `[Error: Required Worker name missing. Please specify the Worker name in wrangler.toml, or pass it as an argument with \`--name\`]` + `[Error: Required Worker name missing. Please specify the Worker name in your Wrangler configuration file, or pass it as an argument with \`--name\`]` ); }); }); describe("deployment view", () => { it("should error with no --no-x-versions flag", async () => { - writeWranglerToml(); + writeWranglerConfig(); await expect( runWrangler("deployments view 1701-E") @@ -161,7 +160,7 @@ describe("deployments", () => { }); it("should log deployment details", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler("deployments view 1701-E --no-x-versions"); @@ -182,7 +181,7 @@ describe("deployments", () => { }); it("should log deployment details with bindings", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler("deployments view bindings-tag --no-x-versions"); @@ -206,7 +205,7 @@ describe("deployments", () => { }); it("should automatically log latest deployment details", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler("deployments view --no-x-versions"); @@ -284,7 +283,7 @@ describe("deployments", () => { result: "", }); - writeWranglerToml(); + writeWranglerConfig(); await runWrangler( "rollback 3mEgaU1T-Intrepid-someThing-tag:test-name --no-x-versions" ); @@ -303,7 +302,7 @@ describe("deployments", () => { result: false, }); - writeWranglerToml(); + writeWranglerConfig(); await runWrangler( "rollback 3mEgaU1T-Intrpid-someThing-tag:test-name --no-x-versions" ); @@ -315,7 +314,7 @@ describe("deployments", () => { it("should skip prompt automatically in rollback if in a non-TTY environment", async () => { setIsTTY(false); - writeWranglerToml(); + writeWranglerConfig(); await runWrangler( "rollback 3mEgaU1T-Intrepid-someThing-tag:test-name --no-x-versions" ); @@ -333,7 +332,7 @@ describe("deployments", () => { }); it("should skip prompt automatically in rollback if message flag is provided", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler( `rollback 3mEgaU1T-Intrepid-someThing-tag:test-name --message "test" --no-x-versions` ); @@ -347,7 +346,7 @@ describe("deployments", () => { }); it("should skip prompt automatically in rollback with empty message", async () => { - writeWranglerToml(); + writeWranglerConfig(); await runWrangler( `rollback 3mEgaU1T-Intrepid-someThing-tag:test-name --message "test" --no-x-versions` ); @@ -371,7 +370,7 @@ describe("deployments", () => { result: "", }); - writeWranglerToml(); + writeWranglerConfig(); await runWrangler("rollback --no-x-versions"); expect(std.out).toMatchInlineSnapshot(` " diff --git a/packages/wrangler/src/__tests__/deprecated-usage-model.test.ts b/packages/wrangler/src/__tests__/deprecated-usage-model.test.ts index 118bfe4e6408..cb7c254888e6 100644 --- a/packages/wrangler/src/__tests__/deprecated-usage-model.test.ts +++ b/packages/wrangler/src/__tests__/deprecated-usage-model.test.ts @@ -8,7 +8,7 @@ import { mswListNewDeploymentsLatestFull } from "./helpers/msw/handlers/versions 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 { writeWranglerConfig } from "./helpers/write-wrangler-config"; describe("deprecated-usage-model", () => { mockAccountId(); @@ -31,7 +31,7 @@ describe("deprecated-usage-model", () => { ...mswSuccessDeploymentScriptMetadata, ...mswListNewDeploymentsLatestFull ); - writeWranglerToml({ usage_model: "bundled" }); + writeWranglerConfig({ usage_model: "bundled" }); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); @@ -39,17 +39,17 @@ describe("deprecated-usage-model", () => { await runWrangler("deploy ./index"); expect(std.warn).toMatchInlineSnapshot(` - "▲ [WARNING] The \`usage_model\` defined in wrangler.toml is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model + "▲ [WARNING] The \`usage_model\` defined in your wrangler.toml file is deprecated and no longer used. Visit our developer docs for details: https://developers.cloudflare.com/workers/wrangler/configuration/#usage-model - " - `); + " + `); }); it("should not warn user about ignored usage model if usage_model not specified", async () => { msw.use( ...mswSuccessDeploymentScriptMetadata, ...mswListNewDeploymentsLatestFull ); - writeWranglerToml(); + writeWranglerConfig(); writeWorkerSource(); mockSubDomainRequest(); mockUploadWorkerRequest(); diff --git a/packages/wrangler/src/__tests__/dev.test.ts b/packages/wrangler/src/__tests__/dev.test.ts index 4c6560f72394..561cbecd4034 100644 --- a/packages/wrangler/src/__tests__/dev.test.ts +++ b/packages/wrangler/src/__tests__/dev.test.ts @@ -22,10 +22,7 @@ import { } from "./helpers/msw"; import { runInTempDir } from "./helpers/run-in-tmp"; import { runWrangler } from "./helpers/run-wrangler"; -import { - writeWranglerJson, - writeWranglerToml, -} from "./helpers/write-wrangler-toml"; +import { writeWranglerConfig } from "./helpers/write-wrangler-config"; import type { Binding, StartDevWorkerInput, @@ -81,6 +78,7 @@ async function expectedHostAndZone( env: undefined, legacyEnv: undefined, sendMetrics: undefined, + configPath: config.config, }); expect(ctx).toEqual( @@ -158,7 +156,7 @@ describe.sequential("wrangler dev", () => { describe("config file support", () => { it("should support wrangler.toml", async () => { - writeWranglerToml({ + writeWranglerConfig({ name: "test-worker-toml", main: "index.js", compatibility_date: "2024-01-01", @@ -170,21 +168,22 @@ describe.sequential("wrangler dev", () => { }); it("should support wrangler.json", async () => { - writeWranglerJson({ - name: "test-worker-json", - main: "index.js", - compatibility_date: "2024-01-01", - }); + writeWranglerConfig( + { + name: "test-worker-json", + main: "index.js", + compatibility_date: "2024-01-01", + }, + "wrangler.json" + ); fs.writeFileSync("index.js", `export default {};`); - const options = await runWranglerUntilConfig( - "dev --experimental-json-config" - ); + const options = await runWranglerUntilConfig("dev"); expect(options.name).toMatchInlineSnapshot(`"test-worker-json"`); }); it("should support wrangler.jsonc", async () => { - writeWranglerJson( + writeWranglerConfig( { name: "test-worker-jsonc", main: "index.js", @@ -194,9 +193,7 @@ describe.sequential("wrangler dev", () => { ); fs.writeFileSync("index.js", `export default {};`); - const options = await runWranglerUntilConfig( - "dev --experimental-json-config" - ); + const options = await runWranglerUntilConfig("dev"); expect(options.name).toMatchInlineSnapshot(`"test-worker-jsonc"`); }); }); @@ -219,7 +216,7 @@ describe.sequential("wrangler dev", () => { }); describe("authorization with env var", () => { it("should use config.account_id over env var", async () => { - writeWranglerToml({ + writeWranglerConfig({ name: "test-worker-toml", main: "index.js", compatibility_date: "2024-01-01", @@ -235,7 +232,7 @@ describe.sequential("wrangler dev", () => { }); it("should use env var when config.account_id is not set", async () => { - writeWranglerToml({ + writeWranglerConfig({ name: "test-worker-toml", main: "index.js", compatibility_date: "2024-01-01", @@ -258,7 +255,7 @@ describe.sequential("wrangler dev", () => { }); it("should warn if there is a wrangler.toml but no compatibility-date", async () => { - writeWranglerToml({ + writeWranglerConfig({ main: "index.js", compatibility_date: undefined, }); @@ -274,19 +271,19 @@ describe.sequential("wrangler dev", () => { expect(std.warn.replaceAll(currentDate, "")) .toMatchInlineSnapshot(` -"▲ [WARNING] No compatibility_date was specified. Using the installed Workers runtime's latest supported date: . + "▲ [WARNING] No compatibility_date was specified. Using the installed Workers runtime's latest supported date: . - ❯❯ Add one to your wrangler.toml file: compatibility_date = \\"\\", or - ❯❯ Pass it in your terminal: wrangler dev [