create-cloudflare 0.0.0-fa045c93 → 0.0.0-fa300e9a
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/dist/cli.js +743 -561
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -9
- package/templates/analog/c3.ts +4 -4
- package/templates/angular/c3.ts +2 -2
- package/templates/astro/c3.ts +3 -3
- package/templates/common/ts/src/ab-test.ts +2 -2
- package/templates/common/ts/src/index.ts +2 -2
- package/templates/common/ts/src/proxy.ts +2 -2
- package/templates/common/ts/src/redirect.ts +2 -2
- package/templates/hello-world/js/vitest.config.js +8 -8
- package/templates/hello-world/ts/src/index.ts +2 -2
- package/templates/hello-world/ts/test/tsconfig.json +6 -9
- package/templates/hello-world/ts/vitest.config.ts +8 -8
- package/templates/hello-world-durable-object/c3.ts +1 -1
- package/templates/hello-world-durable-object/js/src/index.js +1 -1
- package/templates/hello-world-durable-object/js/wrangler.toml +1 -1
- package/templates/hello-world-durable-object/ts/src/index.ts +3 -3
- package/templates/hello-world-durable-object/ts/wrangler.toml +2 -2
- package/templates/hono/c3.ts +1 -1
- package/templates/next/c3.ts +8 -6
- package/templates/nuxt/c3.ts +8 -9
- package/templates/openapi/ts/src/index.ts +1 -1
- package/templates/pre-existing/c3.ts +5 -5
- package/templates/queues/ts/src/index.ts +3 -3
- package/templates/qwik/c3.ts +3 -3
- package/templates/scheduled/js/package.json +2 -2
- package/templates/scheduled/js/src/index.js +8 -1
- package/templates/scheduled/ts/package.json +2 -2
- package/templates/scheduled/ts/src/index.ts +3 -3
- package/templates/solid/c3.ts +11 -9
- package/templates/svelte/c3.ts +6 -6
|
@@ -6,7 +6,7 @@ const EXPERIMENTS = [
|
|
|
6
6
|
];
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
|
-
async fetch(request
|
|
9
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
10
10
|
const fingerprint = [request.headers.get('cf-connecting-ip'), request.cf?.postalCode]; // add any values you want considered as a fingerprint
|
|
11
11
|
const activeExperiments = await getActiveExperiments(fingerprint, EXPERIMENTS);
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@ export default {
|
|
|
22
22
|
|
|
23
23
|
return rewriter.transform(res);
|
|
24
24
|
},
|
|
25
|
-
}
|
|
25
|
+
} satisfies ExportedHandler<Env>;
|
|
26
26
|
|
|
27
27
|
// Get active experiments by hashing a fingerprint
|
|
28
28
|
async function getActiveExperiments(fingerprint: unknown, experiments: Array<{ name: string; threshold: number }>) {
|
|
@@ -19,7 +19,7 @@ import apiRouter from './router';
|
|
|
19
19
|
export default {
|
|
20
20
|
// The fetch handler is invoked when this worker receives a HTTP(S) request
|
|
21
21
|
// and should return a Response (optionally wrapped in a Promise)
|
|
22
|
-
async fetch(request
|
|
22
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
23
23
|
// You'll find it helpful to parse the request.url string into a URL object. Learn more at https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
24
24
|
const url = new URL(request.url);
|
|
25
25
|
|
|
@@ -46,4 +46,4 @@ export default {
|
|
|
46
46
|
{ headers: { 'Content-Type': 'text/html' } }
|
|
47
47
|
);
|
|
48
48
|
},
|
|
49
|
-
}
|
|
49
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
async fetch(request
|
|
2
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
3
3
|
const url = new URL(request.url);
|
|
4
4
|
|
|
5
5
|
const proxyUrl = url.searchParams.get('proxyUrl'); // get a query param value (?proxyUrl=...)
|
|
@@ -20,4 +20,4 @@ export default {
|
|
|
20
20
|
|
|
21
21
|
return res;
|
|
22
22
|
},
|
|
23
|
-
}
|
|
23
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
async fetch(request
|
|
2
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
3
3
|
const url = new URL(request.url);
|
|
4
4
|
const redirectUrl = url.searchParams.get('redirectUrl'); // get a query param value (?redirectUrl=...)
|
|
5
5
|
|
|
@@ -10,4 +10,4 @@ export default {
|
|
|
10
10
|
// The Response class has static methods to create common Response objects as a convenience
|
|
11
11
|
return Response.redirect(redirectUrl);
|
|
12
12
|
},
|
|
13
|
-
}
|
|
13
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineWorkersConfig } from
|
|
1
|
+
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
|
|
2
2
|
|
|
3
3
|
export default defineWorkersConfig({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
test: {
|
|
5
|
+
poolOptions: {
|
|
6
|
+
workers: {
|
|
7
|
+
wrangler: { configPath: './wrangler.toml' },
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
11
|
});
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
export default {
|
|
15
|
-
async fetch(request
|
|
15
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
16
16
|
return new Response('Hello World!');
|
|
17
17
|
},
|
|
18
|
-
}
|
|
18
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
},
|
|
9
|
-
"include": ["./**/*.ts", "../src/env.d.ts"],
|
|
10
|
-
"exclude": []
|
|
2
|
+
"extends": "../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"types": ["@cloudflare/workers-types/experimental", "@cloudflare/vitest-pool-workers"]
|
|
5
|
+
},
|
|
6
|
+
"include": ["./**/*.ts", "../src/env.d.ts"],
|
|
7
|
+
"exclude": []
|
|
11
8
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { defineWorkersConfig } from
|
|
1
|
+
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
|
|
2
2
|
|
|
3
3
|
export default defineWorkersConfig({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
test: {
|
|
5
|
+
poolOptions: {
|
|
6
|
+
workers: {
|
|
7
|
+
wrangler: { configPath: './wrangler.toml' },
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
11
|
});
|
|
@@ -32,7 +32,7 @@ export class MyDurableObject extends DurableObject {
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* The Durable Object exposes an RPC method sayHello which will be invoked when when a Durable
|
|
35
|
-
* Object instance receives a request from a Worker via the same method
|
|
35
|
+
* Object instance receives a request from a Worker via the same method invocation on the stub
|
|
36
36
|
*
|
|
37
37
|
* @param {string} name - The name provided to a Durable Object instance from a Worker
|
|
38
38
|
* @returns {Promise<string>} The greeting to be sent back to the Worker
|
|
@@ -49,7 +49,7 @@ export class MyDurableObject extends DurableObject {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* The Durable Object exposes an RPC method sayHello which will be invoked when when a Durable
|
|
52
|
-
* Object instance receives a request from a Worker via the same method
|
|
52
|
+
* Object instance receives a request from a Worker via the same method invocation on the stub
|
|
53
53
|
*
|
|
54
54
|
* @param name - The name provided to a Durable Object instance from a Worker
|
|
55
55
|
* @returns The greeting to be sent back to the Worker
|
|
@@ -68,7 +68,7 @@ export default {
|
|
|
68
68
|
* @param ctx - The execution context of the Worker
|
|
69
69
|
* @returns The response to be sent back to the client
|
|
70
70
|
*/
|
|
71
|
-
async fetch(request
|
|
71
|
+
async fetch(request, env, ctx): Promise<Response> {
|
|
72
72
|
// We will create a `DurableObjectId` using the pathname from the Worker request
|
|
73
73
|
// This id refers to a unique instance of our 'MyDurableObject' class above
|
|
74
74
|
let id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
|
|
@@ -83,4 +83,4 @@ export default {
|
|
|
83
83
|
|
|
84
84
|
return new Response(greeting);
|
|
85
85
|
},
|
|
86
|
-
}
|
|
86
|
+
} satisfies ExportedHandler<Env>;
|
|
@@ -48,13 +48,13 @@ compatibility_date = "<TBD>"
|
|
|
48
48
|
|
|
49
49
|
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
50
50
|
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
51
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
51
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
|
|
52
52
|
[[durable_objects.bindings]]
|
|
53
53
|
name = "MY_DURABLE_OBJECT"
|
|
54
54
|
class_name = "MyDurableObject"
|
|
55
55
|
|
|
56
56
|
# Durable Object migrations.
|
|
57
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
57
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
|
|
58
58
|
[[migrations]]
|
|
59
59
|
tag = "v1"
|
|
60
60
|
new_classes = ["MyDurableObject"]
|
package/templates/hono/c3.ts
CHANGED
|
@@ -35,7 +35,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
35
35
|
// Insert the env declaration after the last import (but before the rest of the body)
|
|
36
36
|
visitProgram: function (n) {
|
|
37
37
|
const lastImportIndex = n.node.body.findLastIndex(
|
|
38
|
-
(t) => t.type === "ImportDeclaration"
|
|
38
|
+
(t) => t.type === "ImportDeclaration",
|
|
39
39
|
);
|
|
40
40
|
const lastImport = n.get("body", lastImportIndex);
|
|
41
41
|
lastImport.insertAfter(...snippets.bindingsTypeTs);
|
package/templates/next/c3.ts
CHANGED
|
@@ -35,7 +35,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
35
35
|
// (instead of making it a special case which needs extra care)
|
|
36
36
|
const newTomlContent = wranglerToml.replace(
|
|
37
37
|
/#\s+\[\[kv_namespaces\]\]\n#\s+binding\s+=\s+"MY_KV_NAMESPACE"\n#\s+id\s+=\s+"[a-zA-Z0-9]+?"/,
|
|
38
|
-
($1) => `# KV Example:\n${$1}
|
|
38
|
+
($1) => `# KV Example:\n${$1}`,
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
if (!/# KV Example/.test(newTomlContent)) {
|
|
@@ -97,7 +97,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
97
97
|
if (usesTs) {
|
|
98
98
|
copyFile(
|
|
99
99
|
join(getTemplatePath(ctx), "env.d.ts"),
|
|
100
|
-
join(projectPath, "env.d.ts")
|
|
100
|
+
join(projectPath, "env.d.ts"),
|
|
101
101
|
);
|
|
102
102
|
updateStatus("Created an env.d.ts file");
|
|
103
103
|
}
|
|
@@ -112,7 +112,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
112
112
|
|
|
113
113
|
copyFile(
|
|
114
114
|
join(getTemplatePath(ctx), "README.md"),
|
|
115
|
-
join(projectPath, "README.md")
|
|
115
|
+
join(projectPath, "README.md"),
|
|
116
116
|
);
|
|
117
117
|
updateStatus("Updated the README file");
|
|
118
118
|
|
|
@@ -120,15 +120,17 @@ const configure = async (ctx: C3Context) => {
|
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
123
|
-
ctx: C3Context
|
|
123
|
+
ctx: C3Context,
|
|
124
124
|
): Promise<boolean> => {
|
|
125
125
|
const eslintUsage = usesEslint(ctx);
|
|
126
126
|
|
|
127
|
-
if (!eslintUsage.used)
|
|
127
|
+
if (!eslintUsage.used) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
128
130
|
|
|
129
131
|
if (eslintUsage.configType !== ".eslintrc.json") {
|
|
130
132
|
warn(
|
|
131
|
-
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead
|
|
133
|
+
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
|
|
132
134
|
);
|
|
133
135
|
return false;
|
|
134
136
|
}
|
package/templates/nuxt/c3.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { logRaw } from "@cloudflare/cli";
|
|
|
2
2
|
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
3
|
import { spinner } from "@cloudflare/cli/interactive";
|
|
4
4
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
|
-
import { transformFile } from "helpers/codemod";
|
|
5
|
+
import { mergeObjectProperties, transformFile } from "helpers/codemod";
|
|
6
6
|
import { getLatestTypesEntrypoint } from "helpers/compatDate";
|
|
7
7
|
import { readFile, writeFile } from "helpers/files";
|
|
8
8
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
@@ -82,25 +82,24 @@ const updateNuxtConfig = () => {
|
|
|
82
82
|
b.objectExpression([
|
|
83
83
|
b.objectProperty(
|
|
84
84
|
b.identifier("preset"),
|
|
85
|
-
b.stringLiteral("cloudflare-pages")
|
|
85
|
+
b.stringLiteral("cloudflare-pages"),
|
|
86
86
|
),
|
|
87
|
-
])
|
|
87
|
+
]),
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
const moduleDef = b.objectProperty(
|
|
91
91
|
b.identifier("modules"),
|
|
92
|
-
b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")])
|
|
92
|
+
b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")]),
|
|
93
93
|
);
|
|
94
94
|
|
|
95
95
|
transformFile(configFile, {
|
|
96
96
|
visitCallExpression: function (n) {
|
|
97
97
|
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
98
98
|
if (callee.name === "defineNuxtConfig") {
|
|
99
|
-
|
|
100
|
-
.arguments[0] as recast.types.namedTypes.ObjectExpression
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
obj.properties.push(moduleDef);
|
|
99
|
+
mergeObjectProperties(
|
|
100
|
+
n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
|
|
101
|
+
[presetDef, moduleDef],
|
|
102
|
+
);
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
return this.traverse(n);
|
|
@@ -23,7 +23,7 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
|
23
23
|
"Please specify the name of the existing worker in this account?",
|
|
24
24
|
label: "worker",
|
|
25
25
|
defaultValue: ctx.project.name,
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -46,22 +46,22 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
|
46
46
|
env: { CLOUDFLARE_ACCOUNT_ID: ctx.account?.id },
|
|
47
47
|
startText: "Downloading existing worker files",
|
|
48
48
|
doneText: `${brandColor("downloaded")} ${dim(
|
|
49
|
-
`existing "${ctx.args.existingScript}" worker files
|
|
49
|
+
`existing "${ctx.args.existingScript}" worker files`,
|
|
50
50
|
)}`,
|
|
51
|
-
}
|
|
51
|
+
},
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
// copy src/* files from the downloaded worker
|
|
55
55
|
await cp(
|
|
56
56
|
join(tempdir, ctx.args.existingScript, "src"),
|
|
57
57
|
join(ctx.project.path, "src"),
|
|
58
|
-
{ recursive: true }
|
|
58
|
+
{ recursive: true },
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
// copy wrangler.toml from the downloaded worker
|
|
62
62
|
await cp(
|
|
63
63
|
join(tempdir, ctx.args.existingScript, "wrangler.toml"),
|
|
64
|
-
join(ctx.project.path, "wrangler.toml")
|
|
64
|
+
join(ctx.project.path, "wrangler.toml"),
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -18,7 +18,7 @@ export default {
|
|
|
18
18
|
// Our fetch handler is invoked on a HTTP request: we can send a message to a queue
|
|
19
19
|
// during (or after) a request.
|
|
20
20
|
// https://developers.cloudflare.com/queues/platform/javascript-apis/#producer
|
|
21
|
-
async fetch(req
|
|
21
|
+
async fetch(req, env, ctx): Promise<Response> {
|
|
22
22
|
// To send a message on a queue, we need to create the queue first
|
|
23
23
|
// https://developers.cloudflare.com/queues/get-started/#3-create-a-queue
|
|
24
24
|
await env.MY_QUEUE.send({
|
|
@@ -30,7 +30,7 @@ export default {
|
|
|
30
30
|
},
|
|
31
31
|
// The queue handler is invoked when a batch of messages is ready to be delivered
|
|
32
32
|
// https://developers.cloudflare.com/queues/platform/javascript-apis/#messagebatch
|
|
33
|
-
async queue(batch
|
|
33
|
+
async queue(batch, env): Promise<void> {
|
|
34
34
|
// A queue consumer can make requests to other endpoints on the Internet,
|
|
35
35
|
// write to R2 object storage, query a D1 Database, and much more.
|
|
36
36
|
for (let message of batch.messages) {
|
|
@@ -38,4 +38,4 @@ export default {
|
|
|
38
38
|
console.log(`message ${message.id} processed: ${JSON.stringify(message.body)}`);
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
}
|
|
41
|
+
} satisfies ExportedHandler<Env, Error>;
|
package/templates/qwik/c3.ts
CHANGED
|
@@ -43,7 +43,7 @@ const addBindingsProxy = (ctx: C3Context) => {
|
|
|
43
43
|
// Insert the env declaration after the last import (but before the rest of the body)
|
|
44
44
|
visitProgram: function (n) {
|
|
45
45
|
const lastImportIndex = n.node.body.findLastIndex(
|
|
46
|
-
(t) => t.type === "ImportDeclaration"
|
|
46
|
+
(t) => t.type === "ImportDeclaration",
|
|
47
47
|
);
|
|
48
48
|
const lastImport = n.get("body", lastImportIndex);
|
|
49
49
|
lastImport.insertAfter(...snippets.getPlatformProxyTs);
|
|
@@ -109,8 +109,8 @@ const populateCloudflareEnv = () => {
|
|
|
109
109
|
].map(([varName, type]) =>
|
|
110
110
|
b.tsPropertySignature(
|
|
111
111
|
b.identifier(varName),
|
|
112
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier(type)))
|
|
113
|
-
)
|
|
112
|
+
b.tsTypeAnnotation(b.tsTypeReference(b.identifier(type))),
|
|
113
|
+
),
|
|
114
114
|
);
|
|
115
115
|
|
|
116
116
|
n.node.body.body = newBody;
|
|
@@ -6,13 +6,20 @@
|
|
|
6
6
|
* https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
|
|
7
7
|
*
|
|
8
8
|
* - Run `npm run dev` in your terminal to start a development server
|
|
9
|
-
* -
|
|
9
|
+
* - Run `curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*"` to see your worker in action
|
|
10
10
|
* - Run `npm run deploy` to publish your worker
|
|
11
11
|
*
|
|
12
12
|
* Learn more at https://developers.cloudflare.com/workers/
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
export default {
|
|
16
|
+
async fetch(req) {
|
|
17
|
+
const url = new URL(req.url)
|
|
18
|
+
url.pathname = "/__scheduled";
|
|
19
|
+
url.searchParams.append("cron", "* * * * *");
|
|
20
|
+
return new Response(`To test the scheduled handler, ensure you have used the "--test-scheduled" then try running "curl ${url.href}".`);
|
|
21
|
+
},
|
|
22
|
+
|
|
16
23
|
// The scheduled handler is invoked at the interval set in our wrangler.toml's
|
|
17
24
|
// [[triggers]] configuration.
|
|
18
25
|
async scheduled(event, env, ctx) {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"private": true,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"deploy": "wrangler deploy",
|
|
7
|
-
"dev": "wrangler dev",
|
|
8
|
-
"start": "wrangler dev",
|
|
7
|
+
"dev": "wrangler dev --test-scheduled",
|
|
8
|
+
"start": "wrangler dev --test-scheduled",
|
|
9
9
|
"cf-typegen": "wrangler types"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* https://developers.cloudflare.com/workers/platform/triggers/cron-triggers/
|
|
7
7
|
*
|
|
8
8
|
* - Run `npm run dev` in your terminal to start a development server
|
|
9
|
-
* -
|
|
9
|
+
* - Run `curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*"` to see your worker in action
|
|
10
10
|
* - Run `npm run deploy` to publish your worker
|
|
11
11
|
*
|
|
12
12
|
* Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
export default {
|
|
19
19
|
// The scheduled handler is invoked at the interval set in our wrangler.toml's
|
|
20
20
|
// [[triggers]] configuration.
|
|
21
|
-
async scheduled(event
|
|
21
|
+
async scheduled(event, env, ctx): Promise<void> {
|
|
22
22
|
// A Cron Trigger can make requests to other endpoints on the Internet,
|
|
23
23
|
// publish to a Queue, query a D1 Database, and much more.
|
|
24
24
|
//
|
|
@@ -30,4 +30,4 @@ export default {
|
|
|
30
30
|
// In this template, we'll just log the result:
|
|
31
31
|
console.log(`trigger fired at ${event.cron}: ${wasSuccessful}`);
|
|
32
32
|
},
|
|
33
|
-
}
|
|
33
|
+
} satisfies ExportedHandler<Env>;
|
package/templates/solid/c3.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
2
|
import { blue } from "@cloudflare/cli/colors";
|
|
3
3
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
|
-
import { transformFile } from "helpers/codemod";
|
|
4
|
+
import { mergeObjectProperties, transformFile } from "helpers/codemod";
|
|
5
5
|
import { usesTypescript } from "helpers/files";
|
|
6
6
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
7
7
|
import * as recast from "recast";
|
|
@@ -32,28 +32,30 @@ const configure = async (ctx: C3Context) => {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const b = recast.types.builders;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
|
|
36
|
+
mergeObjectProperties(
|
|
37
|
+
n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
|
|
38
|
+
[
|
|
37
39
|
b.objectProperty(
|
|
38
40
|
b.identifier("server"),
|
|
39
41
|
b.objectExpression([
|
|
40
42
|
b.objectProperty(
|
|
41
43
|
b.identifier("preset"),
|
|
42
|
-
b.stringLiteral("cloudflare-pages")
|
|
44
|
+
b.stringLiteral("cloudflare-pages"),
|
|
43
45
|
),
|
|
44
46
|
b.objectProperty(
|
|
45
47
|
b.identifier("rollupConfig"),
|
|
46
48
|
b.objectExpression([
|
|
47
49
|
b.objectProperty(
|
|
48
50
|
b.identifier("external"),
|
|
49
|
-
b.arrayExpression([b.stringLiteral("node:async_hooks")])
|
|
51
|
+
b.arrayExpression([b.stringLiteral("node:async_hooks")]),
|
|
50
52
|
),
|
|
51
|
-
])
|
|
53
|
+
]),
|
|
52
54
|
),
|
|
53
|
-
])
|
|
55
|
+
]),
|
|
54
56
|
),
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
+
],
|
|
58
|
+
);
|
|
57
59
|
|
|
58
60
|
return false;
|
|
59
61
|
},
|
package/templates/svelte/c3.ts
CHANGED
|
@@ -69,21 +69,21 @@ const updateTypeDefinitions = (ctx: C3Context) => {
|
|
|
69
69
|
b.tsInterfaceBody([
|
|
70
70
|
b.tsPropertySignature(
|
|
71
71
|
b.identifier("env"),
|
|
72
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
72
|
+
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env"))),
|
|
73
73
|
),
|
|
74
74
|
b.tsPropertySignature(
|
|
75
75
|
b.identifier("cf"),
|
|
76
76
|
b.tsTypeAnnotation(
|
|
77
|
-
b.tsTypeReference(b.identifier("CfProperties"))
|
|
78
|
-
)
|
|
77
|
+
b.tsTypeReference(b.identifier("CfProperties")),
|
|
78
|
+
),
|
|
79
79
|
),
|
|
80
80
|
b.tsPropertySignature(
|
|
81
81
|
b.identifier("ctx"),
|
|
82
82
|
b.tsTypeAnnotation(
|
|
83
|
-
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
84
|
-
)
|
|
83
|
+
b.tsTypeReference(b.identifier("ExecutionContext")),
|
|
84
|
+
),
|
|
85
85
|
),
|
|
86
|
-
])
|
|
86
|
+
]),
|
|
87
87
|
);
|
|
88
88
|
|
|
89
89
|
moduleBlock.body.unshift(platformInterface);
|