@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 +1 -1
- package/dist/index.js +39 -21
- package/dist/server.directory.d.ts +1 -1
- package/dist/server.directory.js +3 -1
- package/package.json +4 -4
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
|
-
|
|
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 {
|
|
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": ({
|
|
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
|
|
87
|
-
const
|
|
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
|
-
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const outputFiles = await glob(`**/*`, {
|
|
109
|
+
cwd: outputDir,
|
|
110
|
+
filesOnly: true
|
|
104
111
|
});
|
|
105
|
-
for (const
|
|
106
|
-
const
|
|
107
|
-
|
|
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
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
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
|
-
|
|
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<
|
|
8
|
+
} & Record<string, unknown>) => Promise<import("@cloudflare/workers-types").Response | Response>;
|
|
9
9
|
manifest: SSRManifest;
|
|
10
10
|
};
|
package/dist/server.directory.js
CHANGED
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
48
|
+
"astro": "2.8.4",
|
|
49
49
|
"astro-scripts": "0.0.14"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|