@astrojs/cloudflare 6.6.1 → 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/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,6 +68,10 @@ 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
77
  "astro:build:ssr": ({ entryPoints }) => {
@@ -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
+ }
104
107
  });
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) => {
107
- return `[[${p2}]]`;
108
+ const outputFiles = await glob(`**/*`, {
109
+ cwd: outputDir,
110
+ filesOnly: true
111
+ });
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));
@@ -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.1",
4
+ "version": "6.6.2",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -38,14 +38,14 @@
38
38
  "tiny-glob": "^0.2.9"
39
39
  },
40
40
  "peerDependencies": {
41
- "astro": "^2.8.2"
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.8.2",
48
+ "astro": "2.8.4",
49
49
  "astro-scripts": "0.0.14"
50
50
  },
51
51
  "scripts": {