@astrojs/cloudflare 6.6.0 → 6.6.2

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/README.md CHANGED
@@ -66,7 +66,7 @@ export default defineConfig({
66
66
  In order for preview to work you must install `wrangler`
67
67
 
68
68
  ```sh
69
- $ pnpm install wrangler --save-dev
69
+ pnpm install wrangler --save-dev
70
70
  ```
71
71
 
72
72
  It's then possible to update the preview script in your `package.json` to `"preview": "wrangler pages dev ./dist"`. This will allow you to run your entire application locally with [Wrangler](https://github.com/cloudflare/wrangler2), which supports secrets, environment variables, KV namespaces, Durable Objects and [all other supported Cloudflare bindings](https://developers.cloudflare.com/pages/platform/functions/#adding-bindings).
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { createRedirectsFromAstroRoutes } from "@astrojs/underscore-redirects";
2
2
  import esbuild from "esbuild";
3
- import * as fs from "fs";
4
- import * as os from "os";
5
- import { dirname } from "path";
3
+ import * as fs from "node:fs";
4
+ import * as os from "node:os";
5
+ import { sep } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
7
  import glob from "tiny-glob";
7
- import { fileURLToPath, pathToFileURL } from "url";
8
8
  function getAdapter(isModeDirectory) {
9
9
  return isModeDirectory ? {
10
10
  name: "@astrojs/cloudflare",
@@ -68,9 +68,13 @@ function createIntegration(args) {
68
68
  }
69
69
  vite.ssr ||= {};
70
70
  vite.ssr.target = "webworker";
71
+ vite.define = {
72
+ "process.env": "process.env",
73
+ ...vite.define
74
+ };
71
75
  }
72
76
  },
73
- "astro:build:ssr": ({ manifest, entryPoints }) => {
77
+ "astro:build:ssr": ({ entryPoints }) => {
74
78
  _entryPoints = entryPoints;
75
79
  },
76
80
  "astro:build:done": async ({ pages, routes, dir }) => {
@@ -80,11 +84,11 @@ function createIntegration(args) {
80
84
  await fs.promises.mkdir(functionsUrl, { recursive: true });
81
85
  }
82
86
  if (isModeDirectory && _buildConfig.split) {
83
- const entryPointsRouteData = [..._entryPoints.keys()];
84
87
  const entryPointsURL = [..._entryPoints.values()];
85
88
  const entryPaths = entryPointsURL.map((entry) => fileURLToPath(entry));
86
- const outputDir = fileURLToPath(new URL(".astro", _buildConfig.server));
87
- const { outputFiles } = await esbuild.build({
89
+ const outputUrl = new URL("$astro", _buildConfig.server);
90
+ const outputDir = fileURLToPath(outputUrl);
91
+ await esbuild.build({
88
92
  target: "es2020",
89
93
  platform: "browser",
90
94
  conditions: ["workerd", "worker", "browser"],
@@ -99,19 +103,31 @@ function createIntegration(args) {
99
103
  },
100
104
  logOverride: {
101
105
  "ignored-bare-import": "silent"
102
- },
103
- write: false
106
+ }
107
+ });
108
+ const outputFiles = await glob(`**/*`, {
109
+ cwd: outputDir,
110
+ filesOnly: true
104
111
  });
105
- for (const [index, outputFile] of outputFiles.entries()) {
106
- const fileName = entryPointsRouteData[index].component.replace("src/pages/", "").replace(".astro", ".js").replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2, _p3) => {
107
- return `[[${p2}]]`;
112
+ for (const outputFile of outputFiles) {
113
+ const path = outputFile.split(sep);
114
+ const finalSegments = path.map(
115
+ (segment) => segment.replace(/(\_)(\w+)(\_)/g, (_, __, prop) => {
116
+ return `[${prop}]`;
117
+ }).replace(/(\_\-\-\-)(\w+)(\_)/g, (_, __, prop) => {
118
+ return `[[${prop}]]`;
119
+ })
120
+ );
121
+ finalSegments[finalSegments.length - 1] = finalSegments[finalSegments.length - 1].replace("entry.", "").replace(/(.*)\.(\w+)\.(\w+)$/g, (_, fileName, __, newExt) => {
122
+ return `${fileName}.${newExt}`;
108
123
  });
109
- const fileUrl = new URL(fileName, functionsUrl);
110
- const newFileDir = dirname(fileURLToPath(fileUrl));
111
- if (!fs.existsSync(newFileDir)) {
112
- fs.mkdirSync(newFileDir, { recursive: true });
113
- }
114
- await fs.promises.writeFile(fileUrl, outputFile.contents);
124
+ const finalDirPath = finalSegments.slice(0, -1).join(sep);
125
+ const finalPath = finalSegments.join(sep);
126
+ const newDirUrl = new URL(finalDirPath, functionsUrl);
127
+ await fs.promises.mkdir(newDirUrl, { recursive: true });
128
+ const oldFileUrl = new URL(`$astro/${outputFile}`, outputUrl);
129
+ const newFileUrl = new URL(finalPath, functionsUrl);
130
+ await fs.promises.rename(oldFileUrl, newFileUrl);
115
131
  }
116
132
  } else {
117
133
  const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
@@ -185,10 +201,12 @@ function createIntegration(args) {
185
201
  staticPathList.push(...redirects);
186
202
  }
187
203
  }
188
- const redirectRoutes = routes.filter((r) => r.type === "redirect");
204
+ const redirectRoutes = routes.filter((r) => r.type === "redirect").map((r) => {
205
+ return [r, ""];
206
+ });
189
207
  const trueRedirects = createRedirectsFromAstroRoutes({
190
208
  config: _config,
191
- routes: redirectRoutes,
209
+ routeToDynamicTargetMap: new Map(Array.from(redirectRoutes)),
192
210
  dir
193
211
  });
194
212
  if (!trueRedirects.empty()) {
@@ -5,6 +5,6 @@ export declare function createExports(manifest: SSRManifest): {
5
5
  request: Request & CFRequest;
6
6
  next: (request: Request) => void;
7
7
  waitUntil: EventContext<unknown, any, unknown>['waitUntil'];
8
- } & Record<string, unknown>) => Promise<void | Response>;
8
+ } & Record<string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
9
9
  manifest: SSRManifest;
10
10
  };
@@ -13,7 +13,9 @@ function createExports(manifest) {
13
13
  process.env = runtimeEnv.env;
14
14
  const { pathname } = new URL(request.url);
15
15
  if (manifest.assets.has(pathname)) {
16
- return next(request);
16
+ return runtimeEnv.env.ASSETS.fetch(
17
+ request
18
+ );
17
19
  }
18
20
  let routeData = app.match(request, { matchNotFound: true });
19
21
  if (routeData) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/cloudflare",
3
3
  "description": "Deploy your site to Cloudflare Workers/Pages",
4
- "version": "6.6.0",
4
+ "version": "6.6.2",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -32,20 +32,20 @@
32
32
  "runtime.d.ts"
33
33
  ],
34
34
  "dependencies": {
35
- "@astrojs/underscore-redirects": "^0.1.0",
35
+ "@astrojs/underscore-redirects": "^0.2.0",
36
36
  "@cloudflare/workers-types": "^4.20230518.0",
37
37
  "esbuild": "^0.17.19",
38
38
  "tiny-glob": "^0.2.9"
39
39
  },
40
40
  "peerDependencies": {
41
- "astro": "^2.7.3"
41
+ "astro": "^2.8.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "chai": "^4.3.7",
45
45
  "cheerio": "1.0.0-rc.12",
46
46
  "mocha": "^9.2.2",
47
47
  "wrangler": "^2.0.23",
48
- "astro": "2.7.3",
48
+ "astro": "2.8.4",
49
49
  "astro-scripts": "0.0.14"
50
50
  },
51
51
  "scripts": {