create-cloudflare 2.34.0 → 2.35.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "2.34.0",
3
+ "version": "2.35.1",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -67,15 +67,16 @@
67
67
  "xdg-app-paths": "^8.3.0",
68
68
  "yargs": "^17.7.2",
69
69
  "@cloudflare/cli": "1.1.1",
70
- "@cloudflare/eslint-config-worker": "1.1.0",
70
+ "wrangler": "3.97.0",
71
71
  "@cloudflare/workers-tsconfig": "0.0.0",
72
- "wrangler": "3.95.0"
72
+ "@cloudflare/eslint-config-worker": "1.1.0"
73
73
  },
74
74
  "engines": {
75
75
  "node": ">=18.14.1"
76
76
  },
77
77
  "workers-sdk": {
78
- "prerelease": true
78
+ "prerelease": true,
79
+ "type": "cli"
79
80
  },
80
81
  "volta": {
81
82
  "extends": "../../package.json"
@@ -1,7 +1,7 @@
1
1
  import { logRaw, updateStatus } from "@cloudflare/cli";
2
2
  import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { runFrameworkGenerator } from "frameworks/index";
4
- import { loadTemplateSnippets, transformFile } from "helpers/codemod";
4
+ import { transformFile } from "helpers/codemod";
5
5
  import { runCommand } from "helpers/command";
6
6
  import { usesTypescript } from "helpers/files";
7
7
  import { detectPackageManager } from "helpers/packageManagers";
@@ -17,7 +17,7 @@ const generate = async (ctx: C3Context) => {
17
17
  logRaw(""); // newline
18
18
  };
19
19
 
20
- const configure = async (ctx: C3Context) => {
20
+ const configure = async () => {
21
21
  await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22
22
  silent: true,
23
23
  startText: "Installing adapter",
@@ -27,7 +27,6 @@ const configure = async (ctx: C3Context) => {
27
27
  });
28
28
 
29
29
  updateAstroConfig();
30
- updateEnvDeclaration(ctx);
31
30
  };
32
31
 
33
32
  const updateAstroConfig = () => {
@@ -59,35 +58,6 @@ const updateAstroConfig = () => {
59
58
  });
60
59
  };
61
60
 
62
- const updateEnvDeclaration = (ctx: C3Context) => {
63
- if (!usesTypescript(ctx)) {
64
- return;
65
- }
66
-
67
- const filePath = "src/env.d.ts";
68
-
69
- updateStatus(`Adding type declarations in ${blue(filePath)}`);
70
-
71
- transformFile(filePath, {
72
- visitProgram: function (n) {
73
- const snippets = loadTemplateSnippets(ctx);
74
- const patch = snippets.runtimeDeclarationTs;
75
- const b = recast.types.builders;
76
-
77
- // Preserve comments with the new body
78
- const comments = n.get("comments").value;
79
- n.node.comments = comments.map((c: recast.types.namedTypes.CommentLine) =>
80
- b.commentLine(c.value),
81
- );
82
-
83
- // Add the patch
84
- n.get("body").push(...patch);
85
-
86
- return false;
87
- },
88
- });
89
- };
90
-
91
61
  const config: TemplateConfig = {
92
62
  configVersion: 1,
93
63
  id: "astro",
@@ -95,7 +65,21 @@ const config: TemplateConfig = {
95
65
  platform: "pages",
96
66
  displayName: "Astro",
97
67
  copyFiles: {
98
- path: "./templates",
68
+ async selectVariant(ctx) {
69
+ // Note: this `selectVariant` function should not be needed
70
+ // this is just a quick workaround until
71
+ // https://github.com/cloudflare/workers-sdk/issues/7495
72
+ // is resolved
73
+ return usesTypescript(ctx) ? "ts" : "js";
74
+ },
75
+ variants: {
76
+ js: {
77
+ path: "./templates/js",
78
+ },
79
+ ts: {
80
+ path: "./templates/ts",
81
+ },
82
+ },
99
83
  },
100
84
  devScript: "dev",
101
85
  deployScript: "deploy",
@@ -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
+ }
@@ -0,0 +1,86 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "<TBD>"
3
+ compatibility_date = "<TBD>"
4
+ compatibility_flags = ["nodejs_compat"]
5
+ pages_build_output_dir = "./dist"
6
+
7
+ # Automatically place your workloads in an optimal location to minimize latency.
8
+ # If you are running back-end logic in a Pages Function, running it closer to your back-end infrastructure
9
+ # rather than the end user may result in better performance.
10
+ # Docs: https://developers.cloudflare.com/pages/functions/smart-placement/#smart-placement
11
+ # [placement]
12
+ # mode = "smart"
13
+
14
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
15
+ # Docs:
16
+ # - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
17
+ # Note: Use secrets to store sensitive data.
18
+ # - https://developers.cloudflare.com/pages/functions/bindings/#secrets
19
+ # [vars]
20
+ # MY_VARIABLE = "production_value"
21
+
22
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
23
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
24
+ # [ai]
25
+ # binding = "AI"
26
+
27
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
28
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
29
+ # [[d1_databases]]
30
+ # binding = "MY_DB"
31
+ # database_name = "my-database"
32
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
33
+
34
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
35
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
36
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
37
+ # [[durable_objects.bindings]]
38
+ # name = "MY_DURABLE_OBJECT"
39
+ # class_name = "MyDurableObject"
40
+ # script_name = 'my-durable-object'
41
+
42
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
43
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
44
+ # [[kv_namespaces]]
45
+ # binding = "MY_KV_NAMESPACE"
46
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
47
+
48
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
49
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
50
+ # [[queues.producers]]
51
+ # binding = "MY_QUEUE"
52
+ # queue = "my-queue"
53
+
54
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
55
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
56
+ # [[r2_buckets]]
57
+ # binding = "MY_BUCKET"
58
+ # bucket_name = "my-bucket"
59
+
60
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
61
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
62
+ # [[services]]
63
+ # binding = "MY_SERVICE"
64
+ # service = "my-service"
65
+
66
+ # To use different bindings for preview and production environments, follow the examples below.
67
+ # When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
68
+ # Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
69
+
70
+ ######## PREVIEW environment config ########
71
+
72
+ # [env.preview.vars]
73
+ # API_KEY = "xyz789"
74
+
75
+ # [[env.preview.kv_namespaces]]
76
+ # binding = "MY_KV_NAMESPACE"
77
+ # id = "<PREVIEW_NAMESPACE_ID>"
78
+
79
+ ######## PRODUCTION environment config ########
80
+
81
+ # [env.production.vars]
82
+ # API_KEY = "abc123"
83
+
84
+ # [[env.production.kv_namespaces]]
85
+ # binding = "MY_KV_NAMESPACE"
86
+ # id = "<PRODUCTION_NAMESPACE_ID>"
@@ -46,7 +46,7 @@ In order to enable the example:
46
46
  ```ts
47
47
  // KV Example:
48
48
  ```
49
- and uncomment the commented lines below it.
49
+ and uncomment the commented lines below it (also uncomment the relevant imports).
50
50
  - Do the same in the `wrangler.toml` file, where
51
51
  the comment is:
52
52
  ```
@@ -1,9 +1,9 @@
1
- import { getRequestContext } from '@cloudflare/next-on-pages'
1
+ // import { getRequestContext } from '@cloudflare/next-on-pages'
2
2
 
3
3
  export const runtime = 'edge'
4
4
 
5
- export async function GET(request) {
6
- let responseText = 'Hello World'
5
+ export async function GET() {
6
+ const responseText = 'Hello World'
7
7
 
8
8
  // In the edge runtime you can use Bindings that are available in your application
9
9
  // (for more details see:
@@ -15,7 +15,7 @@ export async function GET(request) {
15
15
  // const myKv = getRequestContext().env.MY_KV_NAMESPACE
16
16
  // await myKv.put('suffix', ' from a KV store!')
17
17
  // const suffix = await myKv.get('suffix')
18
- // responseText += suffix
18
+ // return new Response(responseText + suffix)
19
19
 
20
20
  return new Response(responseText)
21
21
  }
@@ -1,10 +1,9 @@
1
- import type { NextRequest } from 'next/server'
2
- import { getRequestContext } from '@cloudflare/next-on-pages'
1
+ // import { getRequestContext } from '@cloudflare/next-on-pages'
3
2
 
4
3
  export const runtime = 'edge'
5
4
 
6
- export async function GET(request: NextRequest) {
7
- let responseText = 'Hello World'
5
+ export async function GET() {
6
+ const responseText = 'Hello World'
8
7
 
9
8
  // In the edge runtime you can use Bindings that are available in your application
10
9
  // (for more details see:
@@ -16,7 +15,7 @@ export async function GET(request: NextRequest) {
16
15
  // const myKv = getRequestContext().env.MY_KV_NAMESPACE
17
16
  // await myKv.put('suffix', ' from a KV store!')
18
17
  // const suffix = await myKv.get('suffix')
19
- // responseText += suffix
18
+ // return new Response(responseText + suffix)
20
19
 
21
20
  return new Response(responseText)
22
21
  }
@@ -49,10 +49,10 @@ const generate = async (ctx: C3Context) => {
49
49
  updateStatus("Created wrangler.toml file");
50
50
  };
51
51
 
52
- const updateNextConfig = () => {
52
+ const updateNextConfig = (usesTs: boolean) => {
53
53
  const s = spinner();
54
54
 
55
- const configFile = "next.config.mjs";
55
+ const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
56
56
  s.start(`Updating \`${configFile}\``);
57
57
 
58
58
  const configContent = readFile(configFile);
@@ -107,7 +107,7 @@ const configure = async (ctx: C3Context) => {
107
107
  await writeEslintrc(ctx);
108
108
  }
109
109
 
110
- updateNextConfig();
110
+ updateNextConfig(usesTs);
111
111
 
112
112
  copyFile(
113
113
  join(getTemplatePath(ctx), "README.md"),
@@ -24,7 +24,7 @@ const generate = async (ctx: C3Context) => {
24
24
  gitFlag,
25
25
  ]);
26
26
 
27
- writeFile("./.node-version", "17");
27
+ writeFile("./.node-version", "18");
28
28
 
29
29
  logRaw(""); // newline
30
30
  };
@@ -1,7 +1,7 @@
1
1
  import { logRaw, updateStatus } from "@cloudflare/cli";
2
2
  import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { runFrameworkGenerator } from "frameworks/index";
4
- import { loadTemplateSnippets, transformFile } from "helpers/codemod";
4
+ import { transformFile } from "helpers/codemod";
5
5
  import { runCommand } from "helpers/command";
6
6
  import { usesTypescript } from "helpers/files";
7
7
  import { detectPackageManager } from "helpers/packageManagers";
@@ -17,7 +17,7 @@ const generate = async (ctx: C3Context) => {
17
17
  logRaw(""); // newline
18
18
  };
19
19
 
20
- const configure = async (ctx: C3Context) => {
20
+ const configure = async () => {
21
21
  await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22
22
  silent: true,
23
23
  startText: "Installing adapter",
@@ -27,7 +27,6 @@ const configure = async (ctx: C3Context) => {
27
27
  });
28
28
 
29
29
  updateAstroConfig();
30
- updateEnvDeclaration(ctx);
31
30
  };
32
31
 
33
32
  const updateAstroConfig = () => {
@@ -59,35 +58,6 @@ const updateAstroConfig = () => {
59
58
  });
60
59
  };
61
60
 
62
- const updateEnvDeclaration = (ctx: C3Context) => {
63
- if (!usesTypescript(ctx)) {
64
- return;
65
- }
66
-
67
- const filePath = "src/env.d.ts";
68
-
69
- updateStatus(`Adding type declarations in ${blue(filePath)}`);
70
-
71
- transformFile(filePath, {
72
- visitProgram: function (n) {
73
- const snippets = loadTemplateSnippets(ctx);
74
- const patch = snippets.runtimeDeclarationTs;
75
- const b = recast.types.builders;
76
-
77
- // Preserve comments with the new body
78
- const comments = n.get("comments").value;
79
- n.node.comments = comments.map((c: recast.types.namedTypes.CommentLine) =>
80
- b.commentLine(c.value),
81
- );
82
-
83
- // Add the patch
84
- n.get("body").push(...patch);
85
-
86
- return false;
87
- },
88
- });
89
- };
90
-
91
61
  const config: TemplateConfig = {
92
62
  configVersion: 1,
93
63
  id: "astro",
@@ -95,7 +65,21 @@ const config: TemplateConfig = {
95
65
  platform: "workers",
96
66
  displayName: "Astro",
97
67
  copyFiles: {
98
- path: "./templates",
68
+ async selectVariant(ctx) {
69
+ // Note: this `selectVariant` function should not be needed
70
+ // this is just a quick workaround until
71
+ // https://github.com/cloudflare/workers-sdk/issues/7495
72
+ // is resolved
73
+ return usesTypescript(ctx) ? "ts" : "js";
74
+ },
75
+ variants: {
76
+ js: {
77
+ path: "./templates/js",
78
+ },
79
+ ts: {
80
+ path: "./templates/ts",
81
+ },
82
+ },
99
83
  },
100
84
  devScript: "dev",
101
85
  deployScript: "deploy",
@@ -0,0 +1,4 @@
1
+ _worker.js
2
+ _routes.json
3
+ _headers
4
+ _redirects
@@ -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
+ }
@@ -0,0 +1,12 @@
1
+ #:schema node_modules/wrangler/config-schema.json
2
+ name = "<TBD>"
3
+ compatibility_date = "<TBD>"
4
+ compatibility_flags = ["nodejs_compat"]
5
+ main = "./dist/_worker.js/index.js"
6
+ assets = { directory = "./dist", binding = "ASSETS" }
7
+
8
+ # Workers Logs
9
+ # Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
10
+ # Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
11
+ [observability]
12
+ enabled = true
@@ -30,6 +30,10 @@ export default {
30
30
  configVersion: 1,
31
31
  id: "next",
32
32
  frameworkCli: "create-next-app",
33
+ // TODO: here we need to specify a version of create-next-app which is different from the
34
+ // standard one used in the stable Next.js template, that's because our open-next adapter
35
+ // is not yet fully ready for Next.js 15, once it is we should remove the following
36
+ frameworkCliPinnedVersion: "14.2.5",
33
37
  platform: "workers",
34
38
  displayName: "Next (using Node.js compat + Workers Assets)",
35
39
  path: "templates-experimental/next",
@@ -24,7 +24,7 @@ const generate = async (ctx: C3Context) => {
24
24
  gitFlag,
25
25
  ]);
26
26
 
27
- writeFile("./.node-version", "17");
27
+ writeFile("./.node-version", "18");
28
28
 
29
29
  logRaw(""); // newline
30
30
  };