create-cloudflare 2.64.8 → 2.65.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.
- package/dist/cli.js +6821 -1554
- package/package.json +25 -28
- package/templates/analog/c3.ts +4 -4
- package/templates/angular/pages/c3.ts +2 -2
- package/templates/angular/workers/c3.ts +2 -2
- package/templates/astro/pages/c3.ts +3 -3
- package/templates/astro/workers/c3.ts +1 -1
- package/templates/hello-world/js/package.json +2 -2
- package/templates/hello-world/js/src/index.js +1 -1
- package/templates/hello-world/js/test/index.spec.js +13 -8
- package/templates/hello-world/js/vitest.config.js +2 -2
- package/templates/hello-world/py/pyproject.toml +2 -6
- package/templates/hello-world/ts/src/index.ts +1 -1
- package/templates/hello-world/ts/test/env.d.ts +1 -1
- package/templates/hello-world/ts/test/index.spec.ts +13 -8
- package/templates/hello-world/ts/vitest.config.mts +2 -2
- package/templates/hello-world-with-assets/js/test/index.spec.js +23 -14
- package/templates/hello-world-with-assets/ts/test/env.d.ts +1 -1
- package/templates/hello-world-with-assets/ts/test/index.spec.ts +27 -14
- package/templates/nuxt/pages/c3.ts +6 -6
- package/templates/nuxt/workers/c3.ts +6 -6
- package/templates/pre-existing/c3.ts +5 -5
- package/templates/qwik/pages/c3.ts +8 -2
- package/templates/qwik/workers/c3.ts +10 -7
- package/templates/react/pages/c3.ts +1 -1
- package/templates/react/workers/c3.ts +6 -6
- package/templates/solid/c3.ts +2 -2
- package/templates/svelte/pages/c3.ts +6 -6
- package/templates/svelte/workers/c3.ts +6 -6
|
@@ -4,7 +4,7 @@ import { spinner } from "@cloudflare/cli/interactive";
|
|
|
4
4
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
5
5
|
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
6
6
|
import { quoteShellArgs, runCommand } from "helpers/command";
|
|
7
|
-
import {
|
|
7
|
+
import { usesTypescript } from "helpers/files";
|
|
8
8
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
9
9
|
import * as recast from "recast";
|
|
10
10
|
import type { TemplateConfig } from "../../../src/templates";
|
|
@@ -17,15 +17,18 @@ const generate = async (ctx: C3Context) => {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const configure = async (ctx: C3Context) => {
|
|
20
|
-
// Add the
|
|
20
|
+
// Add the workers integration
|
|
21
21
|
// For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
|
|
22
|
-
const cmd = [
|
|
22
|
+
const cmd = [
|
|
23
|
+
name === "pnpm" ? npm : npx,
|
|
24
|
+
"qwik",
|
|
25
|
+
"add",
|
|
26
|
+
"cloudflare-workers",
|
|
27
|
+
"--skipConfirmation=true",
|
|
28
|
+
];
|
|
23
29
|
endSection(`Running ${quoteShellArgs(cmd)}`);
|
|
24
30
|
await runCommand(cmd);
|
|
25
31
|
|
|
26
|
-
// Remove the extraneous Pages files
|
|
27
|
-
removeFile("./public/_routes.json");
|
|
28
|
-
|
|
29
32
|
addBindingsProxy(ctx);
|
|
30
33
|
};
|
|
31
34
|
|
|
@@ -46,7 +49,7 @@ const addBindingsProxy = (ctx: C3Context) => {
|
|
|
46
49
|
// Insert the env declaration after the last import (but before the rest of the body)
|
|
47
50
|
visitProgram: function (n) {
|
|
48
51
|
const lastImportIndex = n.node.body.findLastIndex(
|
|
49
|
-
(t) => t.type === "ImportDeclaration"
|
|
52
|
+
(t) => t.type === "ImportDeclaration"
|
|
50
53
|
);
|
|
51
54
|
const lastImport = n.get("body", lastImportIndex);
|
|
52
55
|
lastImport.insertAfter(...snippets.getPlatformProxyTs);
|
|
@@ -44,7 +44,7 @@ async function getVariant(ctx: C3Context) {
|
|
|
44
44
|
const selected = variantsOptions.find((v) => v.value === ctx.args.variant);
|
|
45
45
|
if (!selected) {
|
|
46
46
|
throw new Error(
|
|
47
|
-
`Unknown variant "${ctx.args.variant}". Valid variants are: ${variantsOptions.map((v) => v.value).join(", ")}
|
|
47
|
+
`Unknown variant "${ctx.args.variant}". Valid variants are: ${variantsOptions.map((v) => v.value).join(", ")}`
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
return selected.value;
|
|
@@ -54,12 +54,12 @@ function transformViteConfig(ctx: C3Context) {
|
|
|
54
54
|
// import {cloudflare} from "@cloudflare/vite-plugin";
|
|
55
55
|
// ```
|
|
56
56
|
const lastImportIndex = n.node.body.findLastIndex(
|
|
57
|
-
(statement) => statement.type === "ImportDeclaration"
|
|
57
|
+
(statement) => statement.type === "ImportDeclaration"
|
|
58
58
|
);
|
|
59
59
|
const lastImport = n.get("body", lastImportIndex);
|
|
60
60
|
const importAst = b.importDeclaration(
|
|
61
61
|
[b.importSpecifier(b.identifier("cloudflare"))],
|
|
62
|
-
b.stringLiteral("@cloudflare/vite-plugin")
|
|
62
|
+
b.stringLiteral("@cloudflare/vite-plugin")
|
|
63
63
|
);
|
|
64
64
|
lastImport.insertAfter(importAst);
|
|
65
65
|
|
|
@@ -81,7 +81,7 @@ function transformViteConfig(ctx: C3Context) {
|
|
|
81
81
|
const pluginsProp = config.properties.find((prop) => isPluginsProp(prop));
|
|
82
82
|
assert(pluginsProp && t.ArrayExpression.check(pluginsProp.value));
|
|
83
83
|
pluginsProp.value.elements.push(
|
|
84
|
-
b.callExpression(b.identifier("cloudflare"), [])
|
|
84
|
+
b.callExpression(b.identifier("cloudflare"), [])
|
|
85
85
|
);
|
|
86
86
|
|
|
87
87
|
return false;
|
|
@@ -90,7 +90,7 @@ function transformViteConfig(ctx: C3Context) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
function isPluginsProp(
|
|
93
|
-
prop: unknown
|
|
93
|
+
prop: unknown
|
|
94
94
|
): prop is types.namedTypes.ObjectProperty | types.namedTypes.Property {
|
|
95
95
|
return (
|
|
96
96
|
(t.Property.check(prop) || t.ObjectProperty.check(prop)) &&
|
|
@@ -142,11 +142,11 @@ async function getVariant(ctx: C3Context) {
|
|
|
142
142
|
// If variant is provided via CLI args, use it directly
|
|
143
143
|
if (ctx.args.variant) {
|
|
144
144
|
const selected = variantsOptions.find(
|
|
145
|
-
(variant) => variant.value === ctx.args.variant
|
|
145
|
+
(variant) => variant.value === ctx.args.variant
|
|
146
146
|
);
|
|
147
147
|
if (!selected) {
|
|
148
148
|
throw new Error(
|
|
149
|
-
`Unknown variant "${ctx.args.variant}". Valid variants are: ${variantsOptions.map((v) => v.value).join(", ")}
|
|
149
|
+
`Unknown variant "${ctx.args.variant}". Valid variants are: ${variantsOptions.map((v) => v.value).join(", ")}`
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
return selected;
|
package/templates/solid/c3.ts
CHANGED
|
@@ -34,7 +34,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
34
34
|
const b = recast.types.builders;
|
|
35
35
|
const presetProp = b.objectProperty(
|
|
36
36
|
b.identifier("preset"),
|
|
37
|
-
b.stringLiteral("cloudflare-module")
|
|
37
|
+
b.stringLiteral("cloudflare-module")
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
if (n.node.arguments.length === 0) {
|
|
@@ -42,7 +42,7 @@ const configure = async (ctx: C3Context) => {
|
|
|
42
42
|
} else {
|
|
43
43
|
mergeObjectProperties(
|
|
44
44
|
n.node.arguments[0] as recast.types.namedTypes.ObjectExpression,
|
|
45
|
-
[presetProp]
|
|
45
|
+
[presetProp]
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -98,21 +98,21 @@ const updateTypeDefinitions = (ctx: C3Context) => {
|
|
|
98
98
|
b.tsInterfaceBody([
|
|
99
99
|
b.tsPropertySignature(
|
|
100
100
|
b.identifier("env"),
|
|
101
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
101
|
+
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
102
102
|
),
|
|
103
103
|
b.tsPropertySignature(
|
|
104
104
|
b.identifier("cf"),
|
|
105
105
|
b.tsTypeAnnotation(
|
|
106
|
-
b.tsTypeReference(b.identifier("CfProperties"))
|
|
107
|
-
)
|
|
106
|
+
b.tsTypeReference(b.identifier("CfProperties"))
|
|
107
|
+
)
|
|
108
108
|
),
|
|
109
109
|
b.tsPropertySignature(
|
|
110
110
|
b.identifier("ctx"),
|
|
111
111
|
b.tsTypeAnnotation(
|
|
112
|
-
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
113
|
-
)
|
|
112
|
+
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
113
|
+
)
|
|
114
114
|
),
|
|
115
|
-
])
|
|
115
|
+
])
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
moduleBlock.body.unshift(platformInterface);
|
|
@@ -68,21 +68,21 @@ const updateTypeDefinitions = (ctx: C3Context) => {
|
|
|
68
68
|
b.tsInterfaceBody([
|
|
69
69
|
b.tsPropertySignature(
|
|
70
70
|
b.identifier("env"),
|
|
71
|
-
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
71
|
+
b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env")))
|
|
72
72
|
),
|
|
73
73
|
b.tsPropertySignature(
|
|
74
74
|
b.identifier("cf"),
|
|
75
75
|
b.tsTypeAnnotation(
|
|
76
|
-
b.tsTypeReference(b.identifier("CfProperties"))
|
|
77
|
-
)
|
|
76
|
+
b.tsTypeReference(b.identifier("CfProperties"))
|
|
77
|
+
)
|
|
78
78
|
),
|
|
79
79
|
b.tsPropertySignature(
|
|
80
80
|
b.identifier("ctx"),
|
|
81
81
|
b.tsTypeAnnotation(
|
|
82
|
-
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
83
|
-
)
|
|
82
|
+
b.tsTypeReference(b.identifier("ExecutionContext"))
|
|
83
|
+
)
|
|
84
84
|
),
|
|
85
|
-
])
|
|
85
|
+
])
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
moduleBlock.body.unshift(platformInterface);
|