create-cloudflare 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/cli.js +26 -24
  2. package/package.json +2 -2
  3. package/templates/analog/c3.ts +1 -1
  4. package/templates/analog/templates/worker-configuration.d.ts +1 -1
  5. package/templates/astro/c3.ts +3 -3
  6. package/templates/astro/templates/wrangler.toml +27 -2
  7. package/templates/common/js/wrangler.toml +3 -1
  8. package/templates/common/ts/package.json +2 -1
  9. package/templates/common/ts/src/index.ts +3 -0
  10. package/templates/common/ts/worker-configuration.d.ts +2 -14
  11. package/templates/common/ts/wrangler.toml +3 -1
  12. package/templates/hello-world/js/test/index.spec.js +17 -17
  13. package/templates/hello-world/js/wrangler.toml +3 -1
  14. package/templates/hello-world/ts/package.json +2 -1
  15. package/templates/hello-world/ts/src/index.ts +3 -17
  16. package/templates/hello-world/ts/test/index.spec.ts +17 -17
  17. package/templates/hello-world/ts/worker-configuration.d.ts +4 -0
  18. package/templates/hello-world/ts/wrangler.toml +3 -1
  19. package/templates/hello-world-durable-object/js/wrangler.toml +3 -1
  20. package/templates/hello-world-durable-object/ts/package.json +2 -1
  21. package/templates/hello-world-durable-object/ts/src/index.ts +3 -20
  22. package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +6 -0
  23. package/templates/hello-world-durable-object/ts/wrangler.toml +3 -2
  24. package/templates/hello-world-python/py/wrangler.toml +3 -1
  25. package/templates/next/README.md +5 -5
  26. package/templates/next/c3.ts +3 -3
  27. package/templates/next/wrangler.toml +25 -1
  28. package/templates/nuxt/c3.ts +3 -3
  29. package/templates/nuxt/templates/worker-configuration.d.ts +1 -1
  30. package/templates/nuxt/templates/wrangler.toml +27 -2
  31. package/templates/openapi/ts/package.json +2 -1
  32. package/templates/openapi/ts/worker-configuration.d.ts +4 -0
  33. package/templates/openapi/ts/wrangler.toml +96 -0
  34. package/templates/queues/js/wrangler.toml +3 -1
  35. package/templates/queues/ts/package.json +2 -1
  36. package/templates/queues/ts/src/index.ts +3 -5
  37. package/templates/queues/ts/worker-configuration.d.ts +5 -0
  38. package/templates/queues/ts/wrangler.toml +3 -1
  39. package/templates/qwik/c3.ts +3 -3
  40. package/templates/qwik/templates/worker-configuration.d.ts +1 -1
  41. package/templates/qwik/templates/wrangler.toml +27 -2
  42. package/templates/remix/c3.ts +3 -3
  43. package/templates/remix/templates/worker-configuration.d.ts +1 -1
  44. package/templates/remix/templates/wrangler.toml +27 -2
  45. package/templates/scheduled/js/wrangler.toml +4 -2
  46. package/templates/scheduled/ts/package.json +2 -1
  47. package/templates/scheduled/ts/src/index.ts +3 -20
  48. package/templates/scheduled/ts/worker-configuration.d.ts +4 -0
  49. package/templates/scheduled/ts/wrangler.toml +4 -2
  50. package/templates/solid/c3.ts +5 -3
  51. package/templates/solid/templates/wrangler.toml +77 -0
  52. package/templates/svelte/c3.ts +3 -3
  53. package/templates/svelte/js/wrangler.toml +27 -2
  54. package/templates/svelte/ts/wrangler.toml +27 -2
package/dist/cli.js CHANGED
@@ -3897,7 +3897,7 @@ var init_args = __esm({
3897
3897
  var version, devDependencies;
3898
3898
  var init_package = __esm({
3899
3899
  "package.json"() {
3900
- version = "2.19.0";
3900
+ version = "2.20.0";
3901
3901
  devDependencies = {
3902
3902
  "@babel/parser": "^7.21.3",
3903
3903
  "@babel/types": "^7.21.4",
@@ -70640,7 +70640,7 @@ var init_c3 = __esm({
70640
70640
  scripts: {
70641
70641
  preview: `${npm} run build && wrangler pages dev`,
70642
70642
  deploy: `${npm} run build && wrangler pages deploy`,
70643
- "build-cf-types": `wrangler types`
70643
+ "cf-typegen": `wrangler types`
70644
70644
  }
70645
70645
  }),
70646
70646
  devScript: "dev",
@@ -70833,9 +70833,9 @@ var init_c33 = __esm({
70833
70833
  configure: configure3,
70834
70834
  transformPackageJson: async (pkgJson, ctx) => ({
70835
70835
  scripts: {
70836
- deploy: `astro build && wrangler pages deploy ./dist`,
70837
- preview: `astro build && wrangler pages dev ./dist`,
70838
- ...usesTypescript(ctx) && { "build-cf-types": `wrangler types` }
70836
+ deploy: `astro build && wrangler pages deploy`,
70837
+ preview: `astro build && wrangler pages dev`,
70838
+ ...usesTypescript(ctx) && { "cf-typegen": `wrangler types` }
70839
70839
  }
70840
70840
  })
70841
70841
  };
@@ -71132,10 +71132,10 @@ ${$1}`
71132
71132
  return {
71133
71133
  scripts: {
71134
71134
  "pages:build": `${pmCommand} ${nextOnPagesCommand}`,
71135
- preview: `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static`,
71136
- deploy: `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
71135
+ preview: `${pagesBuildRunCommand} && wrangler pages dev`,
71136
+ deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
71137
71137
  ...usesTypescript(ctx) && {
71138
- "build-cf-types": `wrangler types --env-interface CloudflareEnv env.d.ts`
71138
+ "cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`
71139
71139
  }
71140
71140
  }
71141
71141
  };
@@ -71249,9 +71249,9 @@ var init_c38 = __esm({
71249
71249
  configure: configure5,
71250
71250
  transformPackageJson: async () => ({
71251
71251
  scripts: {
71252
- deploy: `${npm6} run build && wrangler pages deploy ./dist`,
71253
- preview: `${npm6} run build && wrangler pages dev ./dist`,
71254
- "build-cf-types": `wrangler types`
71252
+ deploy: `${npm6} run build && wrangler pages deploy`,
71253
+ preview: `${npm6} run build && wrangler pages dev`,
71254
+ "cf-typegen": `wrangler types`
71255
71255
  }
71256
71256
  }),
71257
71257
  devScript: "dev",
@@ -71372,9 +71372,9 @@ var init_c39 = __esm({
71372
71372
  configure: configure6,
71373
71373
  transformPackageJson: async () => ({
71374
71374
  scripts: {
71375
- deploy: `${npm7} run build && wrangler pages deploy ./dist`,
71376
- preview: `${npm7} run build && wrangler pages dev ./dist`,
71377
- "build-cf-types": `wrangler types`
71375
+ deploy: `${npm7} run build && wrangler pages deploy`,
71376
+ preview: `${npm7} run build && wrangler pages dev`,
71377
+ "cf-typegen": `wrangler types`
71378
71378
  }
71379
71379
  }),
71380
71380
  devScript: "dev",
@@ -71471,9 +71471,9 @@ var init_c311 = __esm({
71471
71471
  configure: configure7,
71472
71472
  transformPackageJson: async () => ({
71473
71473
  scripts: {
71474
- deploy: `${npm9} run build && wrangler pages deploy ./build/client`,
71475
- preview: `${npm9} run build && wrangler pages dev ./build/client`,
71476
- "build-cf-types": `wrangler types`
71474
+ deploy: `${npm9} run build && wrangler pages deploy`,
71475
+ preview: `${npm9} run build && wrangler pages dev`,
71476
+ "cf-typegen": `wrangler types`
71477
71477
  }
71478
71478
  }),
71479
71479
  devScript: "dev",
@@ -71496,7 +71496,6 @@ var init_c312 = __esm({
71496
71496
  init_colors();
71497
71497
  init_frameworks();
71498
71498
  init_codemod();
71499
- init_compatDate();
71500
71499
  init_files();
71501
71500
  init_packageManagers();
71502
71501
  recast6 = __toESM(require_main3());
@@ -71547,12 +71546,15 @@ var init_c312 = __esm({
71547
71546
  id: "solid",
71548
71547
  displayName: "Solid",
71549
71548
  platform: "pages",
71549
+ copyFiles: {
71550
+ path: "./templates"
71551
+ },
71550
71552
  generate: generate12,
71551
71553
  configure: configure8,
71552
71554
  transformPackageJson: async () => ({
71553
71555
  scripts: {
71554
- preview: `${npm10} run build && npx wrangler pages dev dist ${await compatDateFlag()} --compatibility-flag nodejs_compat`,
71555
- deploy: `${npm10} run build && wrangler pages deploy ./dist`
71556
+ preview: `${npm10} run build && npx wrangler pages dev`,
71557
+ deploy: `${npm10} run build && wrangler pages deploy`
71556
71558
  }
71557
71559
  }),
71558
71560
  compatibilityFlags: ["nodejs_compat"],
@@ -71660,14 +71662,14 @@ var init_c313 = __esm({
71660
71662
  configure: configure9,
71661
71663
  transformPackageJson: async (original, ctx) => {
71662
71664
  let scripts = {
71663
- preview: `${npm11} run build && wrangler pages dev .svelte-kit/cloudflare`,
71664
- deploy: `${npm11} run build && wrangler pages deploy .svelte-kit/cloudflare`
71665
+ preview: `${npm11} run build && wrangler pages dev`,
71666
+ deploy: `${npm11} run build && wrangler pages deploy`
71665
71667
  };
71666
71668
  if (usesTypescript(ctx)) {
71667
71669
  const mv = (0, import_node_os.platform)() === "win32" ? "move" : "mv";
71668
71670
  scripts = {
71669
71671
  ...scripts,
71670
- "build-cf-types": `wrangler types && ${mv} worker-configuration.d.ts src/`
71672
+ "cf-typegen": `wrangler types && ${mv} worker-configuration.d.ts src/`
71671
71673
  };
71672
71674
  }
71673
71675
  return { scripts };
@@ -77800,7 +77802,7 @@ init_command();
77800
77802
  init_packageManagers();
77801
77803
 
77802
77804
  // ../wrangler/package.json
77803
- var version2 = "3.51.0";
77805
+ var version2 = "3.51.1";
77804
77806
 
77805
77807
  // src/git.ts
77806
77808
  init_package();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "2.19.0",
3
+ "version": "2.20.0",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -70,7 +70,7 @@
70
70
  "yarn": "^1.22.19",
71
71
  "@cloudflare/cli": "1.1.1",
72
72
  "@cloudflare/workers-tsconfig": "0.0.0",
73
- "wrangler": "3.51.0"
73
+ "wrangler": "3.51.1"
74
74
  },
75
75
  "engines": {
76
76
  "node": ">=18.14.1"
@@ -124,7 +124,7 @@ const config: TemplateConfig = {
124
124
  scripts: {
125
125
  preview: `${npm} run build && wrangler pages dev`,
126
126
  deploy: `${npm} run build && wrangler pages deploy`,
127
- "build-cf-types": `wrangler types`,
127
+ "cf-typegen": `wrangler types`,
128
128
  },
129
129
  }),
130
130
  devScript: "dev",
@@ -1,4 +1,4 @@
1
1
  // Generated by Wrangler
2
- // After adding bindings to `wrangler.toml`, regenerate this interface via `npm build-cf-types`
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
3
3
  interface Env {
4
4
  }
@@ -103,9 +103,9 @@ const config: TemplateConfig = {
103
103
  configure,
104
104
  transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
105
105
  scripts: {
106
- deploy: `astro build && wrangler pages deploy ./dist`,
107
- preview: `astro build && wrangler pages dev ./dist`,
108
- ...(usesTypescript(ctx) && { "build-cf-types": `wrangler types` }),
106
+ deploy: `astro build && wrangler pages deploy`,
107
+ preview: `astro build && wrangler pages dev`,
108
+ ...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
109
109
  },
110
110
  }),
111
111
  };
@@ -1,10 +1,13 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
+ pages_build_output_dir = "./dist"
4
5
 
5
6
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
6
9
  # Note: Use secrets to store sensitive data.
7
- # Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
10
+ # - https://developers.cloudflare.com/pages/functions/bindings/#secrets
8
11
  # [vars]
9
12
  # MY_VARIABLE = "production_value"
10
13
 
@@ -50,4 +53,26 @@ compatibility_date = "<TBD>"
50
53
  # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
51
54
  # [[services]]
52
55
  # binding = "MY_SERVICE"
53
- # service = "my-service"
56
+ # service = "my-service"
57
+
58
+ # To use different bindings for preview and production environments, follow the examples below.
59
+ # When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
60
+ # Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
61
+
62
+ ######## PREVIEW environment config ########
63
+
64
+ # [env.preview.vars]
65
+ # API_KEY = "xyz789"
66
+
67
+ # [[env.preview.kv_namespaces]]
68
+ # binding = "MY_KV_NAMESPACE"
69
+ # id = "<PREVIEW_NAMESPACE_ID>"
70
+
71
+ ######## PRODUCTION environment config ########
72
+
73
+ # [env.production.vars]
74
+ # API_KEY = "abc123"
75
+
76
+ # [[env.production.kv_namespaces]]
77
+ # binding = "MY_KV_NAMESPACE"
78
+ # id = "<PRODUCTION_NAMESPACE_ID>"
@@ -4,8 +4,10 @@ main = "src/index.js"
4
4
  compatibility_date = "<TBD>"
5
5
 
6
6
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
7
9
  # Note: Use secrets to store sensitive data.
8
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
10
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
9
11
  # [vars]
10
12
  # MY_VARIABLE = "production_value"
11
13
 
@@ -5,7 +5,8 @@
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
7
  "dev": "wrangler dev",
8
- "start": "wrangler dev"
8
+ "start": "wrangler dev",
9
+ "cf-typegen": "wrangler types"
9
10
  },
10
11
  "devDependencies": {
11
12
  "itty-router": "^3.0.12",
@@ -5,6 +5,9 @@
5
5
  * - Open a browser tab at http://localhost:8787/ to see your worker in action
6
6
  * - Run `npm run deploy` to publish your worker
7
7
  *
8
+ * Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
9
+ * `Env` object can be regenerated with `npm run cf-typegen`.
10
+ *
8
11
  * Learn more at https://developers.cloudflare.com/workers/
9
12
  */
10
13
 
@@ -1,16 +1,4 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
1
3
  interface Env {
2
- // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
3
- // MY_KV_NAMESPACE: KVNamespace;
4
- //
5
- // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
6
- // MY_DURABLE_OBJECT: DurableObjectNamespace;
7
- //
8
- // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
9
- // MY_BUCKET: R2Bucket;
10
- //
11
- // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
12
- // MY_SERVICE: Fetcher;
13
- //
14
- // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
15
- // MY_QUEUE: Queue;
16
4
  }
@@ -4,8 +4,10 @@ main = "src/index.ts"
4
4
  compatibility_date = "<TBD>"
5
5
 
6
6
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
7
9
  # Note: Use secrets to store sensitive data.
8
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
10
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
9
11
  # [vars]
10
12
  # MY_VARIABLE = "production_value"
11
13
 
@@ -1,20 +1,20 @@
1
- import { env, createExecutionContext, waitOnExecutionContext, SELF } from "cloudflare:test";
2
- import { describe, it, expect } from "vitest";
3
- import worker from "../src";
1
+ import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
2
+ import { describe, it, expect } from 'vitest';
3
+ import worker from '../src';
4
4
 
5
- describe("Hello World worker", () => {
6
- it("responds with Hello World! (unit style)", async () => {
7
- const request = new Request("http://example.com");
8
- // Create an empty context to pass to `worker.fetch()`.
9
- const ctx = createExecutionContext();
10
- const response = await worker.fetch(request, env, ctx);
11
- // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
12
- await waitOnExecutionContext(ctx);
13
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
14
- });
5
+ describe('Hello World worker', () => {
6
+ it('responds with Hello World! (unit style)', async () => {
7
+ const request = new Request('http://example.com');
8
+ // Create an empty context to pass to `worker.fetch()`.
9
+ const ctx = createExecutionContext();
10
+ const response = await worker.fetch(request, env, ctx);
11
+ // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
12
+ await waitOnExecutionContext(ctx);
13
+ expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
14
+ });
15
15
 
16
- it("responds with Hello World! (integration style)", async () => {
17
- const response = await SELF.fetch("http://example.com");
18
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19
- });
16
+ it('responds with Hello World! (integration style)', async () => {
17
+ const response = await SELF.fetch(request, env, ctx);
18
+ expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19
+ });
20
20
  });
@@ -5,8 +5,10 @@ compatibility_date = "<TBD>"
5
5
  compatibility_flags = ["nodejs_compat"]
6
6
 
7
7
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
8
+ # Docs:
9
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
8
10
  # Note: Use secrets to store sensitive data.
9
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
11
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
10
12
  # [vars]
11
13
  # MY_VARIABLE = "production_value"
12
14
 
@@ -6,7 +6,8 @@
6
6
  "deploy": "wrangler deploy",
7
7
  "dev": "wrangler dev",
8
8
  "start": "wrangler dev",
9
- "test": "vitest"
9
+ "test": "vitest",
10
+ "cf-typegen": "wrangler types"
10
11
  },
11
12
  "devDependencies": {
12
13
  "typescript": "^5.0.4",
@@ -5,26 +5,12 @@
5
5
  * - Open a browser tab at http://localhost:8787/ to see your worker in action
6
6
  * - Run `npm run deploy` to publish your worker
7
7
  *
8
+ * Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
9
+ * `Env` object can be regenerated with `npm run cf-typegen`.
10
+ *
8
11
  * Learn more at https://developers.cloudflare.com/workers/
9
12
  */
10
13
 
11
- export interface Env {
12
- // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
13
- // MY_KV_NAMESPACE: KVNamespace;
14
- //
15
- // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
16
- // MY_DURABLE_OBJECT: DurableObjectNamespace;
17
- //
18
- // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
19
- // MY_BUCKET: R2Bucket;
20
- //
21
- // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
22
- // MY_SERVICE: Fetcher;
23
- //
24
- // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
25
- // MY_QUEUE: Queue;
26
- }
27
-
28
14
  export default {
29
15
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
30
16
  return new Response('Hello World!');
@@ -1,25 +1,25 @@
1
1
  // test/index.spec.ts
2
- import { env, createExecutionContext, waitOnExecutionContext, SELF } from "cloudflare:test";
3
- import { describe, it, expect } from "vitest";
4
- import worker from "../src/index";
2
+ import { env, createExecutionContext, waitOnExecutionContext, SELF } from 'cloudflare:test';
3
+ import { describe, it, expect } from 'vitest';
4
+ import worker from '../src/index';
5
5
 
6
6
  // For now, you'll need to do something like this to get a correctly-typed
7
7
  // `Request` to pass to `worker.fetch()`.
8
8
  const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
9
9
 
10
- describe("Hello World worker", () => {
11
- it("responds with Hello World! (unit style)", async () => {
12
- const request = new IncomingRequest("http://example.com");
13
- // Create an empty context to pass to `worker.fetch()`.
14
- const ctx = createExecutionContext();
15
- const response = await worker.fetch(request, env, ctx);
16
- // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
17
- await waitOnExecutionContext(ctx);
18
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19
- });
10
+ describe('Hello World worker', () => {
11
+ it('responds with Hello World! (unit style)', async () => {
12
+ const request = new IncomingRequest('http://example.com');
13
+ // Create an empty context to pass to `worker.fetch()`.
14
+ const ctx = createExecutionContext();
15
+ const response = await worker.fetch(request, env, ctx);
16
+ // Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
17
+ await waitOnExecutionContext(ctx);
18
+ expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
19
+ });
20
20
 
21
- it("responds with Hello World! (integration style)", async () => {
22
- const response = await SELF.fetch("https://example.com");
23
- expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
24
- });
21
+ it('responds with Hello World! (integration style)', async () => {
22
+ const response = await SELF.fetch('https://example.com');
23
+ expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
24
+ });
25
25
  });
@@ -0,0 +1,4 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
3
+ interface Env {
4
+ }
@@ -5,8 +5,10 @@ compatibility_date = "<TBD>"
5
5
  compatibility_flags = ["nodejs_compat"]
6
6
 
7
7
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
8
+ # Docs:
9
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
8
10
  # Note: Use secrets to store sensitive data.
9
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
11
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
10
12
  # [vars]
11
13
  # MY_VARIABLE = "production_value"
12
14
 
@@ -4,8 +4,10 @@ main = "src/index.ts"
4
4
  compatibility_date = "<TBD>"
5
5
 
6
6
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
7
9
  # Note: Use secrets to store sensitive data.
8
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
10
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
9
11
  # [vars]
10
12
  # MY_VARIABLE = "production_value"
11
13
 
@@ -5,7 +5,8 @@
5
5
  "scripts": {
6
6
  "deploy": "wrangler deploy",
7
7
  "dev": "wrangler dev",
8
- "start": "wrangler dev"
8
+ "start": "wrangler dev",
9
+ "cf-typegen": "wrangler types"
9
10
  },
10
11
  "devDependencies": {
11
12
  "@cloudflare/workers-types": "^4.20231218.0",
@@ -5,29 +5,12 @@
5
5
  * - Open a browser tab at http://localhost:8787/ to see your Durable Object in action
6
6
  * - Run `npm run deploy` to publish your application
7
7
  *
8
+ * Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
9
+ * `Env` object can be regenerated with `npm run cf-typegen`.
10
+ *
8
11
  * Learn more at https://developers.cloudflare.com/durable-objects
9
12
  */
10
13
 
11
- /**
12
- * Associate bindings declared in wrangler.toml with the TypeScript type system
13
- */
14
- export interface Env {
15
- // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
16
- // MY_KV_NAMESPACE: KVNamespace;
17
- //
18
- // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
19
- MY_DURABLE_OBJECT: DurableObjectNamespace;
20
- //
21
- // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
22
- // MY_BUCKET: R2Bucket;
23
- //
24
- // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
25
- // MY_SERVICE: Fetcher;
26
- //
27
- // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
28
- // MY_QUEUE: Queue;
29
- }
30
-
31
14
  /** A Durable Object's behavior is defined in an exported Javascript class */
32
15
  export class MyDurableObject {
33
16
  /**
@@ -0,0 +1,6 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm run cf-typegen`
3
+ interface Env {
4
+ MY_DURABLE_OBJECT: DurableObjectNamespace;
5
+ }
6
+
@@ -4,8 +4,10 @@ main = "src/index.ts"
4
4
  compatibility_date = "<TBD>"
5
5
 
6
6
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
7
+ # Docs:
8
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
7
9
  # Note: Use secrets to store sensitive data.
8
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
10
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
9
11
  # [vars]
10
12
  # MY_VARIABLE = "production_value"
11
13
 
@@ -96,4 +98,3 @@ new_classes = ["MyDurableObject"]
96
98
  # [[vectorize]]
97
99
  # binding = "MY_INDEX"
98
100
  # index_name = "my-index"
99
-
@@ -5,8 +5,10 @@ compatibility_flags = ["python_workers"]
5
5
  compatibility_date = "<TBD>"
6
6
 
7
7
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
8
+ # Docs:
9
+ # - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
8
10
  # Note: Use secrets to store sensitive data.
9
- # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
11
+ # - https://developers.cloudflare.com/workers/configuration/secrets/
10
12
  # [vars]
11
13
  # MY_VARIABLE = "production_value"
12
14
 
@@ -52,15 +52,15 @@ In order to enable the example:
52
52
  ```
53
53
  # KV Example:
54
54
  ```
55
- - If you're using TypeScript run the `build-cf-types` script to update the `env.d.ts` file:
55
+ - If you're using TypeScript run the `cf-typegen` script to update the `env.d.ts` file:
56
56
  ```bash
57
- npm run build-cf-types
57
+ npm run cf-typegen
58
58
  # or
59
- yarn build-cf-types
59
+ yarn cf-typegen
60
60
  # or
61
- pnpm build-cf-types
61
+ pnpm cf-typegen
62
62
  # or
63
- bun build-cf-types
63
+ bun cf-typegen
64
64
  ```
65
65
 
66
66
  After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
@@ -221,10 +221,10 @@ export default {
221
221
  return {
222
222
  scripts: {
223
223
  "pages:build": `${pmCommand} ${nextOnPagesCommand}`,
224
- preview: `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static`,
225
- deploy: `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
224
+ preview: `${pagesBuildRunCommand} && wrangler pages dev`,
225
+ deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
226
226
  ...(usesTypescript(ctx) && {
227
- "build-cf-types": `wrangler types --env-interface CloudflareEnv env.d.ts`,
227
+ "cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
228
228
  }),
229
229
  },
230
230
  };
@@ -2,10 +2,13 @@
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
4
  compatibility_flags = ["nodejs_compat"]
5
+ pages_build_output_dir = ".vercel/output/static"
5
6
 
6
7
  # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
8
+ # Docs:
9
+ # - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
7
10
  # Note: Use secrets to store sensitive data.
8
- # Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
11
+ # - https://developers.cloudflare.com/pages/functions/bindings/#secrets
9
12
  # [vars]
10
13
  # MY_VARIABLE = "production_value"
11
14
 
@@ -53,3 +56,24 @@ compatibility_flags = ["nodejs_compat"]
53
56
  # binding = "MY_SERVICE"
54
57
  # service = "my-service"
55
58
 
59
+ # To use different bindings for preview and production environments, follow the examples below.
60
+ # When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
61
+ # Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
62
+
63
+ ######## PREVIEW environment config ########
64
+
65
+ # [env.preview.vars]
66
+ # API_KEY = "xyz789"
67
+
68
+ # [[env.preview.kv_namespaces]]
69
+ # binding = "MY_KV_NAMESPACE"
70
+ # id = "<PREVIEW_NAMESPACE_ID>"
71
+
72
+ ######## PRODUCTION environment config ########
73
+
74
+ # [env.production.vars]
75
+ # API_KEY = "abc123"
76
+
77
+ # [[env.production.kv_namespaces]]
78
+ # binding = "MY_KV_NAMESPACE"
79
+ # id = "<PRODUCTION_NAMESPACE_ID>"
@@ -122,9 +122,9 @@ const config: TemplateConfig = {
122
122
  configure,
123
123
  transformPackageJson: async () => ({
124
124
  scripts: {
125
- deploy: `${npm} run build && wrangler pages deploy ./dist`,
126
- preview: `${npm} run build && wrangler pages dev ./dist`,
127
- "build-cf-types": `wrangler types`,
125
+ deploy: `${npm} run build && wrangler pages deploy`,
126
+ preview: `${npm} run build && wrangler pages dev`,
127
+ "cf-typegen": `wrangler types`,
128
128
  },
129
129
  }),
130
130
  devScript: "dev",