create-cloudflare 0.0.0-e44f496a8 → 0.0.0-e4716cc87

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 (57) hide show
  1. package/dist/cli.js +3559 -3492
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +7 -6
  4. package/templates/angular/c3.ts +25 -13
  5. package/templates/angular/templates/src/server.ts +15 -0
  6. package/templates/angular/templates/tools/copy-files.mjs +8 -2
  7. package/templates/astro/c3.ts +17 -33
  8. package/templates/astro/templates/{wrangler.toml → js/wrangler.toml} +1 -0
  9. package/templates/astro/templates/ts/worker-configuration.d.ts +4 -0
  10. package/templates/{svelte → astro/templates}/ts/wrangler.toml +2 -1
  11. package/templates/hello-world/js/package.json +1 -1
  12. package/templates/hello-world/ts/package.json +1 -1
  13. package/templates/hello-world/ts/test/tsconfig.json +1 -1
  14. package/templates/next/README.md +1 -1
  15. package/templates/next/app/js/app/api/hello/route.js +4 -4
  16. package/templates/next/app/ts/app/api/hello/route.ts +4 -5
  17. package/templates/next/c3.ts +4 -4
  18. package/templates/nuxt/c3.ts +1 -1
  19. package/templates/pre-existing/c3.ts +26 -7
  20. package/templates/solid/c3.ts +1 -1
  21. package/templates/svelte/c3.ts +34 -7
  22. package/templates-experimental/angular/c3.ts +21 -7
  23. package/templates-experimental/angular/templates/src/server.ts +15 -0
  24. package/templates-experimental/astro/c3.ts +17 -33
  25. package/templates-experimental/astro/templates/ts/worker-configuration.d.ts +4 -0
  26. package/templates-experimental/astro/templates/ts/wrangler.toml +12 -0
  27. package/templates-experimental/hello-world-with-assets/js/package.json +1 -1
  28. package/templates-experimental/hello-world-with-assets/ts/package.json +1 -1
  29. package/templates-experimental/next/c3.ts +11 -4
  30. package/templates-experimental/next/templates/.dev.vars +2 -0
  31. package/templates-experimental/next/templates/__dot__gitignore +2 -5
  32. package/templates-experimental/next/templates/open-next.config.ts +28 -0
  33. package/templates-experimental/next/templates/wrangler.toml +2 -2
  34. package/templates-experimental/nuxt/c3.ts +2 -2
  35. package/templates-experimental/nuxt/templates/wrangler.toml +2 -2
  36. package/templates-experimental/remix/c3.ts +1 -26
  37. package/templates-experimental/remix/templates/public/.assetsignore +0 -4
  38. package/templates-experimental/remix/templates/wrangler.toml +1 -1
  39. package/templates-experimental/solid/c3.ts +8 -51
  40. package/templates-experimental/solid/templates/wrangler.toml +2 -2
  41. package/templates-experimental/svelte/c3.ts +4 -7
  42. package/templates-experimental/vue/c3.ts +33 -0
  43. package/templates-experimental/{svelte/ts → vue/templates}/wrangler.toml +1 -2
  44. package/templates/angular/templates/server.ts +0 -34
  45. package/templates/angular/templates/tools/alter-polyfills.mjs +0 -27
  46. package/templates/angular/templates/tools/paths.mjs +0 -9
  47. package/templates-experimental/angular/templates/server.ts +0 -34
  48. package/templates-experimental/angular/templates/tools/alter-polyfills.mjs +0 -32
  49. package/templates-experimental/nuxt/templates/cloudflare-preset/nitro.config.ts +0 -27
  50. /package/templates/astro/{snippets/runtimeDeclaration.ts → templates/ts/src/env.d.ts} +0 -0
  51. /package/templates/svelte/{js → templates}/wrangler.toml +0 -0
  52. /package/templates-experimental/astro/templates/{public → js/public}/.assetsignore +0 -0
  53. /package/templates-experimental/astro/templates/{wrangler.toml → js/wrangler.toml} +0 -0
  54. /package/templates-experimental/{svelte/js/static → astro/templates/ts/public}/.assetsignore +0 -0
  55. /package/templates-experimental/astro/{snippets/runtimeDeclaration.ts → templates/ts/src/env.d.ts} +0 -0
  56. /package/templates-experimental/svelte/{ts → templates}/static/.assetsignore +0 -0
  57. /package/templates-experimental/svelte/{js → templates}/wrangler.toml +0 -0
@@ -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
+ // 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
@@ -11,6 +11,6 @@
11
11
  "devDependencies": {
12
12
  "@cloudflare/vitest-pool-workers": "^0.5.2",
13
13
  "wrangler": "^3.60.3",
14
- "vitest": "2.0.5"
14
+ "vitest": "2.1.8"
15
15
  }
16
16
  }
@@ -12,7 +12,7 @@
12
12
  "devDependencies": {
13
13
  "@cloudflare/vitest-pool-workers": "^0.5.2",
14
14
  "typescript": "^5.5.2",
15
- "vitest": "2.0.5",
15
+ "vitest": "2.1.8",
16
16
  "wrangler": "^3.60.3"
17
17
  }
18
18
  }
@@ -18,7 +18,10 @@ const generate = async (ctx: C3Context) => {
18
18
  };
19
19
 
20
20
  const configure = async () => {
21
- const packages = ["@opennextjs/cloudflare", "@cloudflare/workers-types"];
21
+ const packages = [
22
+ "@opennextjs/cloudflare@0.3.x",
23
+ "@cloudflare/workers-types",
24
+ ];
22
25
  await installPackages(packages, {
23
26
  dev: true,
24
27
  startText: "Adding the Cloudflare adapter",
@@ -30,8 +33,12 @@ export default {
30
33
  configVersion: 1,
31
34
  id: "next",
32
35
  frameworkCli: "create-next-app",
36
+ // TODO: here we need to specify a version of create-next-app which is different from the
37
+ // standard one used in the stable Next.js template, that's because our open-next adapter
38
+ // is not yet fully ready for Next.js 15, once it is we should remove the following
39
+ frameworkCliPinnedVersion: "14.2.5",
33
40
  platform: "workers",
34
- displayName: "Next (using Node.js compat + Workers Assets)",
41
+ displayName: "Next.js (using Node.js compat + Workers Assets)",
35
42
  path: "templates-experimental/next",
36
43
  copyFiles: {
37
44
  path: "./templates",
@@ -40,8 +47,8 @@ export default {
40
47
  configure,
41
48
  transformPackageJson: async () => ({
42
49
  scripts: {
43
- deploy: `cloudflare && wrangler deploy`,
44
- preview: `cloudflare && wrangler dev`,
50
+ deploy: `opennextjs-cloudflare && wrangler deploy`,
51
+ preview: `opennextjs-cloudflare && wrangler dev`,
45
52
  "cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
46
53
  },
47
54
  }),
@@ -0,0 +1,2 @@
1
+ # Load .env.development* files when running `wrangler dev`
2
+ NEXTJS_ENV=development
@@ -35,8 +35,5 @@ yarn-error.log*
35
35
  *.tsbuildinfo
36
36
  next-env.d.ts
37
37
 
38
-
39
- # Cloudflare related
40
- /.save.next
41
- /.worker-next
42
- /.wrangler
38
+ # OpenNext
39
+ /.open-next
@@ -0,0 +1,28 @@
1
+ import cache from "@opennextjs/cloudflare/kvCache";
2
+
3
+ const config = {
4
+ default: {
5
+ override: {
6
+ wrapper: "cloudflare-node",
7
+ converter: "edge",
8
+ incrementalCache: async () => cache,
9
+ tagCache: "dummy",
10
+ queue: "dummy",
11
+ },
12
+ },
13
+
14
+ middleware: {
15
+ external: true,
16
+ override: {
17
+ wrapper: "cloudflare-edge",
18
+ converter: "edge",
19
+ proxyExternalRequest: "fetch",
20
+ },
21
+ },
22
+
23
+ dangerous: {
24
+ enableCacheInterception: false,
25
+ },
26
+ };
27
+
28
+ export default config;
@@ -1,6 +1,6 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<app-name>"
3
- main = ".worker-next/index.mjs"
3
+ main = ".open-next/worker.js"
4
4
 
5
5
  compatibility_date = "2024-09-26"
6
6
  compatibility_flags = ["nodejs_compat"]
@@ -9,4 +9,4 @@ compatibility_flags = ["nodejs_compat"]
9
9
  minify = true
10
10
 
11
11
  # Use the new Workers + Assets to host the static frontend files
12
- assets = { directory = ".worker-next/assets", binding = "ASSETS" }
12
+ assets = { directory = ".open-next/assets", binding = "ASSETS" }
@@ -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
  };
@@ -82,7 +82,7 @@ const updateNuxtConfig = () => {
82
82
  b.objectExpression([
83
83
  b.objectProperty(
84
84
  b.identifier("preset"),
85
- b.stringLiteral("./cloudflare-preset"),
85
+ b.stringLiteral("cloudflare_module"),
86
86
  ),
87
87
  ]),
88
88
  );
@@ -1,8 +1,8 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
- main = "./dist/worker/index.js"
5
- assets = { directory = "./dist/public", binding = "ASSETS" }
4
+ main = "./.output/server/index.mjs"
5
+ assets = { directory = "./.output/public/", binding = "ASSETS" }
6
6
 
7
7
  # Workers Logs
8
8
  # Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
@@ -1,8 +1,6 @@
1
1
  import { logRaw } from "@cloudflare/cli";
2
2
  import { brandColor, dim } from "@cloudflare/cli/colors";
3
- import { spinner } from "@cloudflare/cli/interactive";
4
3
  import { runFrameworkGenerator } from "frameworks/index";
5
- import { transformFile } from "helpers/codemod";
6
4
  import { detectPackageManager } from "helpers/packageManagers";
7
5
  import { installPackages } from "helpers/packages";
8
6
  import type { TemplateConfig } from "../../src/templates";
@@ -14,7 +12,7 @@ const generate = async (ctx: C3Context) => {
14
12
  await runFrameworkGenerator(ctx, [
15
13
  ctx.project.name,
16
14
  "--template",
17
- "https://github.com/remix-run/remix/tree/main/templates/cloudflare",
15
+ "https://github.com/remix-run/remix/tree/main/templates/cloudflare-workers",
18
16
  ]);
19
17
 
20
18
  logRaw(""); // newline
@@ -26,27 +24,6 @@ const configure = async () => {
26
24
  startText: "Updating the Wrangler version",
27
25
  doneText: `${brandColor(`updated`)} ${dim("wrangler@latest")}`,
28
26
  });
29
-
30
- const typeDefsPath = "load-context.ts";
31
-
32
- const s = spinner();
33
- s.start(`Updating \`${typeDefsPath}\``);
34
-
35
- // Remove the empty Env declaration from the template to allow the type from
36
- // worker-configuration.d.ts to take over
37
- transformFile(typeDefsPath, {
38
- visitTSInterfaceDeclaration(n) {
39
- if (n.node.id.type === "Identifier" && n.node.id.name !== "Env") {
40
- return this.traverse(n);
41
- }
42
-
43
- // Removes the node
44
- n.replace();
45
- return false;
46
- },
47
- });
48
-
49
- s.stop(`${brandColor("updated")} \`${dim(typeDefsPath)}\``);
50
27
  };
51
28
 
52
29
  const config: TemplateConfig = {
@@ -63,8 +40,6 @@ const config: TemplateConfig = {
63
40
  configure,
64
41
  transformPackageJson: async () => ({
65
42
  scripts: {
66
- build:
67
- "remix vite:build && wrangler pages functions build --outdir build/worker",
68
43
  deploy: `${npm} run build && wrangler deploy`,
69
44
  preview: `${npm} run build && wrangler dev`,
70
45
  "cf-typegen": `wrangler types`,
@@ -1,4 +0,0 @@
1
- _worker.js
2
- _routes.json
3
- _headers
4
- _redirects
@@ -1,7 +1,7 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
- main = "./build/worker/index.js"
4
+ main = "./server.ts"
5
5
  assets = { directory = "./build/client" }
6
6
 
7
7
  # Workers Logs
@@ -2,6 +2,7 @@ import { logRaw, updateStatus } from "@cloudflare/cli";
2
2
  import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { runFrameworkGenerator } from "frameworks/index";
4
4
  import { mergeObjectProperties, transformFile } from "helpers/codemod";
5
+ import { getWorkerdCompatibilityDate } from "helpers/compatDate";
5
6
  import { usesTypescript } from "helpers/files";
6
7
  import { detectPackageManager } from "helpers/packageManagers";
7
8
  import { installPackages } from "helpers/packages";
@@ -30,6 +31,8 @@ const configure = async (ctx: C3Context) => {
30
31
  usesTypescript(ctx);
31
32
  const filePath = `app.config.${usesTypescript(ctx) ? "ts" : "js"}`;
32
33
 
34
+ const compatDate = await getWorkerdCompatibilityDate();
35
+
33
36
  updateStatus(`Updating configuration in ${blue(filePath)}`);
34
37
 
35
38
  transformFile(filePath, {
@@ -46,60 +49,14 @@ const configure = async (ctx: C3Context) => {
46
49
  b.objectProperty(
47
50
  b.identifier("server"),
48
51
  b.objectExpression([
49
- // preset: "cloudflare-pages"
52
+ // preset: "cloudflare_module"
50
53
  b.objectProperty(
51
54
  b.identifier("preset"),
52
- b.stringLiteral("./cloudflare-pages"),
53
- ),
54
- // output: {
55
- // dir: "{{ rootDir }}/dist",
56
- // publicDir: "{{ output.dir }}/public",
57
- // serverDir: "{{ output.dir }}/worker",
58
- // },
59
- b.objectProperty(
60
- b.identifier("output"),
61
- b.objectExpression([
62
- b.objectProperty(
63
- b.identifier("dir"),
64
- b.stringLiteral("{{ rootDir }}/dist"),
65
- ),
66
- b.objectProperty(
67
- b.identifier("publicDir"),
68
- b.stringLiteral("{{ output.dir }}/public"),
69
- ),
70
- b.objectProperty(
71
- b.identifier("serverDir"),
72
- b.stringLiteral("{{ output.dir }}/worker"),
73
- ),
74
- ]),
75
- ),
76
- // rollupConfig: {
77
- // external: ["node:async_hooks"],
78
- // },
79
- b.objectProperty(
80
- b.identifier("rollupConfig"),
81
- b.objectExpression([
82
- b.objectProperty(
83
- b.identifier("external"),
84
- b.arrayExpression([b.stringLiteral("node:async_hooks")]),
85
- ),
86
- ]),
55
+ b.stringLiteral("cloudflare_module"),
87
56
  ),
88
- // hooks: {
89
- // // Prevent the Pages preset from writing the _routes.json etc.
90
- // compiled() {},
91
- // },
92
57
  b.objectProperty(
93
- b.identifier("hooks"),
94
- b.objectExpression([
95
- b.objectMethod(
96
- "method",
97
- b.identifier("compiled"),
98
- [],
99
- b.blockStatement([]),
100
- false,
101
- ),
102
- ]),
58
+ b.identifier("compatibilityDate"),
59
+ b.stringLiteral(compatDate),
103
60
  ),
104
61
  ]),
105
62
  ),
@@ -115,7 +72,7 @@ const config: TemplateConfig = {
115
72
  configVersion: 1,
116
73
  id: "solid",
117
74
  frameworkCli: "create-solid",
118
- displayName: "Solid",
75
+ displayName: "SolidStart",
119
76
  platform: "workers",
120
77
  copyFiles: {
121
78
  path: "./templates",
@@ -2,8 +2,8 @@
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
4
  compatibility_flags = ["nodejs_compat"]
5
- main = "./dist/worker/index.js"
6
- assets = { directory = "./dist/public", binding = "ASSETS" }
5
+ main = "./.output/server/index.mjs"
6
+ assets = { directory = "./.output/public", binding = "ASSETS" }
7
7
 
8
8
  # Workers Logs
9
9
  # Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
@@ -13,7 +13,7 @@ import type { C3Context, PackageJson } from "types";
13
13
  const { npm } = detectPackageManager();
14
14
 
15
15
  const generate = async (ctx: C3Context) => {
16
- await runFrameworkGenerator(ctx, [ctx.project.name]);
16
+ await runFrameworkGenerator(ctx, ["create", ctx.project.name]);
17
17
 
18
18
  logRaw("");
19
19
  };
@@ -97,14 +97,11 @@ const updateTypeDefinitions = (ctx: C3Context) => {
97
97
  const config: TemplateConfig = {
98
98
  configVersion: 1,
99
99
  id: "svelte",
100
- frameworkCli: "create-svelte",
101
- displayName: "Svelte",
100
+ frameworkCli: "sv",
101
+ displayName: "SvelteKit",
102
102
  platform: "workers",
103
103
  copyFiles: {
104
- variants: {
105
- js: { path: "./js" },
106
- ts: { path: "./ts" },
107
- },
104
+ path: "./templates",
108
105
  },
109
106
  path: "templates-experimental/svelte",
110
107
  generate,
@@ -0,0 +1,33 @@
1
+ import { runFrameworkGenerator } from "frameworks/index";
2
+ import { detectPackageManager } from "helpers/packageManagers";
3
+ import type { TemplateConfig } from "../../src/templates";
4
+ import type { C3Context } from "types";
5
+
6
+ const { npm } = detectPackageManager();
7
+
8
+ const generate = async (ctx: C3Context) => {
9
+ await runFrameworkGenerator(ctx, [ctx.project.name]);
10
+ };
11
+
12
+ const config: TemplateConfig = {
13
+ configVersion: 1,
14
+ id: "vue",
15
+ frameworkCli: "create-vue",
16
+ platform: "workers",
17
+ displayName: "Vue",
18
+ copyFiles: {
19
+ path: "./templates",
20
+ },
21
+ path: "templates-experimental/vue",
22
+ generate,
23
+ transformPackageJson: async () => ({
24
+ scripts: {
25
+ deploy: `${npm} run build && wrangler deploy`,
26
+ preview: `${npm} run build && wrangler dev`,
27
+ },
28
+ }),
29
+ devScript: "dev",
30
+ deployScript: "deploy",
31
+ previewScript: "preview",
32
+ };
33
+ export default config;
@@ -1,8 +1,7 @@
1
1
  #:schema node_modules/wrangler/config-schema.json
2
2
  name = "<TBD>"
3
3
  compatibility_date = "<TBD>"
4
- main = ".svelte-kit/cloudflare/_worker.js"
5
- assets = { directory = ".svelte-kit/cloudflare", binding = "ASSETS" }
4
+ assets = { directory = "./dist" }
6
5
 
7
6
  # Workers Logs
8
7
  # Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
@@ -1,34 +0,0 @@
1
- import { renderApplication } from "@angular/platform-server";
2
- import bootstrap from "./src/main.server";
3
-
4
- interface Env {
5
- ASSETS: { fetch: typeof fetch };
6
- }
7
-
8
- // We attach the Cloudflare `fetch()` handler to the global scope
9
- // so that we can export it when we process the Angular output.
10
- // See tools/bundle.mjs
11
- async function workerFetchHandler(request: Request, env: Env) {
12
- const url = new URL(request.url);
13
- console.log("render SSR", url.href);
14
-
15
- // Get the root `index.html` content.
16
- const indexUrl = new URL("/", url);
17
- const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
18
- const document = await indexResponse.text();
19
-
20
- const content = await renderApplication(bootstrap, {
21
- document,
22
- url: url.pathname,
23
- });
24
-
25
- // console.log("rendered SSR", content);
26
- return new Response(content, indexResponse);
27
- }
28
-
29
- export default {
30
- fetch: (request: Request, env: Env) =>
31
- (globalThis as any)["__zone_symbol__Promise"].resolve(
32
- workerFetchHandler(request, env)
33
- ),
34
- };
@@ -1,27 +0,0 @@
1
- import fs from "node:fs";
2
- import { EOL } from "node:os";
3
- import { join } from "node:path";
4
- import { worker } from "./paths.mjs";
5
-
6
- /**
7
- * Split by lines and comment the banner
8
- * ```
9
- * import { createRequire } from 'node:module';
10
- * globalThis['require'] ??= createRequire(import.meta.url);
11
- * ```
12
- */
13
- const serverPolyfillsFile = join(worker, "polyfills.server.mjs");
14
- const serverPolyfillsData = fs
15
- .readFileSync(serverPolyfillsFile, "utf8")
16
- .split(/\r?\n/);
17
-
18
- for (let index = 0; index < 2; index++) {
19
- if (serverPolyfillsData[index].includes("createRequire")) {
20
- serverPolyfillsData[index] = "// " + serverPolyfillsData[index];
21
- }
22
- }
23
-
24
- // Add needed polyfills
25
- serverPolyfillsData.unshift(`globalThis['process'] = {};`);
26
-
27
- fs.writeFileSync(serverPolyfillsFile, serverPolyfillsData.join(EOL));
@@ -1,9 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
-
4
- const dirname = path.dirname(fileURLToPath(import.meta.url));
5
- export const root = path.resolve(dirname, "..");
6
- export const client = path.resolve(root, "dist/browser");
7
- export const ssr = path.resolve(root, "dist/server");
8
- export const cloudflare = path.resolve(root, "dist/cloudflare");
9
- export const worker = path.resolve(cloudflare, "_worker.js");
@@ -1,34 +0,0 @@
1
- import { renderApplication } from "@angular/platform-server";
2
- import bootstrap from "./src/main.server";
3
-
4
- interface Env {
5
- ASSETS: { fetch: typeof fetch };
6
- }
7
-
8
- // We attach the Cloudflare `fetch()` handler to the global scope
9
- // so that we can export it when we process the Angular output.
10
- // See tools/bundle.mjs
11
- async function workerFetchHandler(request: Request, env: Env) {
12
- const url = new URL(request.url);
13
- console.log("render SSR", url.href);
14
-
15
- // Get the root `index.html` content.
16
- const indexUrl = new URL("/index.html", url);
17
- const indexResponse = await env.ASSETS.fetch(new Request(indexUrl));
18
- const document = await indexResponse.text();
19
-
20
- const content = await renderApplication(bootstrap, {
21
- document,
22
- url: url.pathname,
23
- });
24
-
25
- // console.log("rendered SSR", content);
26
- return new Response(content, indexResponse);
27
- }
28
-
29
- export default {
30
- fetch: (request: Request, env: Env) =>
31
- (globalThis as any)["__zone_symbol__Promise"].resolve(
32
- workerFetchHandler(request, env),
33
- ),
34
- };
@@ -1,32 +0,0 @@
1
- import fs from "node:fs";
2
- import { EOL } from "node:os";
3
- import { join } from "node:path";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- const dirname = path.dirname(fileURLToPath(import.meta.url));
7
-
8
- /**
9
- * Split by lines and comment the banner
10
- * ```
11
- * import { createRequire } from 'node:module';
12
- * globalThis['require'] ??= createRequire(import.meta.url);
13
- * ```
14
- */
15
- const serverPolyfillsFile = join(
16
- dirname,
17
- "../dist/server/polyfills.server.mjs"
18
- );
19
- const serverPolyfillsData = fs
20
- .readFileSync(serverPolyfillsFile, "utf8")
21
- .split(/\r?\n/);
22
-
23
- for (let index = 0; index < 2; index++) {
24
- if (serverPolyfillsData[index].includes("createRequire")) {
25
- serverPolyfillsData[index] = "// " + serverPolyfillsData[index];
26
- }
27
- }
28
-
29
- // Add needed polyfills
30
- serverPolyfillsData.unshift(`globalThis['process'] = {};`);
31
-
32
- fs.writeFileSync(serverPolyfillsFile, serverPolyfillsData.join(EOL));
@@ -1,27 +0,0 @@
1
- import { type NitroPreset } from "nitropack";
2
-
3
- export default <NitroPreset>{
4
- extends: "cloudflare",
5
- exportConditions: ["workerd"],
6
- output: {
7
- dir: "{{ rootDir }}/dist",
8
- publicDir: "{{ output.dir }}/public",
9
- serverDir: "{{ output.dir }}/worker",
10
- },
11
- commands: {
12
- preview: "npx wrangler dev",
13
- deploy: "npx wrangler deploy",
14
- },
15
- wasm: {
16
- lazy: false,
17
- esmImport: true,
18
- },
19
- rollupConfig: {
20
- output: {
21
- entryFileNames: "index.js",
22
- format: "esm",
23
- exports: "named",
24
- inlineDynamicImports: false,
25
- },
26
- },
27
- };