@astrojs/cloudflare 12.2.0 → 12.2.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/LICENSE +59 -0
- package/dist/entrypoints/image-endpoint.js +14 -10
- package/dist/entrypoints/image-service.js +32 -33
- package/dist/entrypoints/middleware.js +10 -8
- package/dist/entrypoints/server.js +57 -48
- package/dist/index.js +255 -250
- package/dist/utils/assets.js +62 -60
- package/dist/utils/cloudflare-module-loader.js +164 -192
- package/dist/utils/env.js +12 -10
- package/dist/utils/generate-routes-json.js +212 -247
- package/dist/utils/image-config.js +32 -29
- package/dist/utils/non-server-chunk-detector.js +48 -65
- package/package.json +13 -15
|
@@ -1,260 +1,225 @@
|
|
|
1
|
-
import { existsSync } from
|
|
2
|
-
import { writeFile } from
|
|
3
|
-
import path from
|
|
4
|
-
import { fileURLToPath } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
prependForwardSlash,
|
|
7
|
+
removeLeadingForwardSlash,
|
|
8
|
+
removeTrailingForwardSlash
|
|
9
|
+
} from "@astrojs/internal-helpers/path";
|
|
10
|
+
import { glob } from "tinyglobby";
|
|
10
11
|
const ROUTE_DYNAMIC_SPLIT = /\[(.+?\(.+?\)|.+?)\]/;
|
|
11
12
|
const ROUTE_SPREAD = /^\.{3}.+$/;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
spread: dynamic && ROUTE_SPREAD.test(content),
|
|
26
|
-
});
|
|
13
|
+
function getParts(part) {
|
|
14
|
+
const result = [];
|
|
15
|
+
part.split(ROUTE_DYNAMIC_SPLIT).map((str, i) => {
|
|
16
|
+
if (!str) return;
|
|
17
|
+
const dynamic = i % 2 === 1;
|
|
18
|
+
const [, content] = dynamic ? /([^(]+)$/.exec(str) || [null, null] : [null, str];
|
|
19
|
+
if (!content || dynamic && !/^(?:\.\.\.)?[\w$]+$/.test(content)) {
|
|
20
|
+
throw new Error("Parameter name must match /^[a-zA-Z0-9_$]+$/");
|
|
21
|
+
}
|
|
22
|
+
result.push({
|
|
23
|
+
content,
|
|
24
|
+
dynamic,
|
|
25
|
+
spread: dynamic && ROUTE_SPREAD.test(content)
|
|
27
26
|
});
|
|
28
|
-
|
|
27
|
+
});
|
|
28
|
+
return result;
|
|
29
29
|
}
|
|
30
30
|
async function writeRoutesFileToOutDir(_config, logger, include, exclude) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
try {
|
|
32
|
+
await writeFile(
|
|
33
|
+
new URL("./_routes.json", _config.outDir),
|
|
34
|
+
JSON.stringify(
|
|
35
|
+
{
|
|
36
|
+
version: 1,
|
|
37
|
+
include,
|
|
38
|
+
exclude
|
|
39
|
+
},
|
|
40
|
+
null,
|
|
41
|
+
2
|
|
42
|
+
),
|
|
43
|
+
"utf-8"
|
|
44
|
+
);
|
|
45
|
+
} catch (_error) {
|
|
46
|
+
logger.error("There was an error writing the '_routes.json' file to the output directory.");
|
|
47
|
+
}
|
|
41
48
|
}
|
|
42
49
|
function segmentsToCfSyntax(segments, _config) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return pathSegments;
|
|
50
|
+
const pathSegments = [];
|
|
51
|
+
if (removeLeadingForwardSlash(removeTrailingForwardSlash(_config.base)).length > 0) {
|
|
52
|
+
pathSegments.push(removeLeadingForwardSlash(removeTrailingForwardSlash(_config.base)));
|
|
53
|
+
}
|
|
54
|
+
for (const segment of segments.flat()) {
|
|
55
|
+
if (segment.dynamic) pathSegments.push("*");
|
|
56
|
+
else pathSegments.push(segment.content);
|
|
57
|
+
}
|
|
58
|
+
return pathSegments;
|
|
54
59
|
}
|
|
55
60
|
class TrieNode {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
children = /* @__PURE__ */ new Map();
|
|
62
|
+
isEndOfPath = false;
|
|
63
|
+
hasWildcardChild = false;
|
|
59
64
|
}
|
|
60
65
|
class PathTrie {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
this.dfs(this.root, [], allPaths);
|
|
124
|
-
return [allPaths, this.returnHasWildcard];
|
|
125
|
-
}
|
|
66
|
+
root;
|
|
67
|
+
returnHasWildcard = false;
|
|
68
|
+
constructor() {
|
|
69
|
+
this.root = new TrieNode();
|
|
70
|
+
}
|
|
71
|
+
insert(thisPath) {
|
|
72
|
+
let node = this.root;
|
|
73
|
+
for (const segment of thisPath) {
|
|
74
|
+
if (segment === "*") {
|
|
75
|
+
node.hasWildcardChild = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (!node.children.has(segment)) {
|
|
79
|
+
node.children.set(segment, new TrieNode());
|
|
80
|
+
}
|
|
81
|
+
node = node.children.get(segment);
|
|
82
|
+
}
|
|
83
|
+
node.isEndOfPath = true;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Depth-first search (dfs), traverses the "graph" segment by segment until the end or wildcard (*).
|
|
87
|
+
* It makes sure that all necessary paths are returned, but not paths with an existing wildcard prefix.
|
|
88
|
+
* e.g. if we have a path like /foo/* and /foo/bar, we only want to return /foo/*
|
|
89
|
+
*/
|
|
90
|
+
dfs(node, thisPath, allPaths) {
|
|
91
|
+
if (node.hasWildcardChild) {
|
|
92
|
+
this.returnHasWildcard = true;
|
|
93
|
+
allPaths.push([...thisPath, "*"]);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (node.isEndOfPath) {
|
|
97
|
+
allPaths.push([...thisPath]);
|
|
98
|
+
}
|
|
99
|
+
for (const [segment, childNode] of node.children) {
|
|
100
|
+
this.dfs(childNode, [...thisPath, segment], allPaths);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The reduce function is used to remove unnecessary paths from the trie.
|
|
105
|
+
* It receives a trie node to compare with the current node.
|
|
106
|
+
*/
|
|
107
|
+
reduce(compNode, node) {
|
|
108
|
+
if (node.hasWildcardChild || compNode.hasWildcardChild) return;
|
|
109
|
+
for (const [segment, childNode] of node.children) {
|
|
110
|
+
if (childNode.children.size === 0) continue;
|
|
111
|
+
const compChildNode = compNode.children.get(segment);
|
|
112
|
+
if (compChildNode === void 0) {
|
|
113
|
+
childNode.hasWildcardChild = true;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
this.reduce(compChildNode, childNode);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
reduceAllPaths(compTrie) {
|
|
120
|
+
this.reduce(compTrie.root, this.root);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
getAllPaths() {
|
|
124
|
+
const allPaths = [];
|
|
125
|
+
this.dfs(this.root, [], allPaths);
|
|
126
|
+
return [allPaths, this.returnHasWildcard];
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
excludePaths.push(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
.reduceAllPaths(excludeTrie)
|
|
220
|
-
.getAllPaths();
|
|
221
|
-
const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie
|
|
222
|
-
.reduceAllPaths(includeTrie)
|
|
223
|
-
.getAllPaths();
|
|
224
|
-
/**
|
|
225
|
-
* Cloudflare allows no more than 100 include/exclude rules combined
|
|
226
|
-
* https://developers.cloudflare.com/pages/functions/routing/#limits
|
|
227
|
-
*/
|
|
228
|
-
const CLOUDFLARE_COMBINED_LIMIT = 100;
|
|
229
|
-
/**
|
|
230
|
-
* Caluclate the number of automated and extended include rules
|
|
231
|
-
*/
|
|
232
|
-
const AUTOMATIC_INCLUDE_RULES_COUNT = deduplicatedIncludePaths.length;
|
|
233
|
-
const EXTENDED_INCLUDE_RULES_COUNT = includeExtends?.length ?? 0;
|
|
234
|
-
const INCLUDE_RULES_COUNT = AUTOMATIC_INCLUDE_RULES_COUNT + EXTENDED_INCLUDE_RULES_COUNT;
|
|
235
|
-
/**
|
|
236
|
-
* Caluclate the number of automated and extended exclude rules
|
|
237
|
-
*/
|
|
238
|
-
const AUTOMATIC_EXCLUDE_RULES_COUNT = deduplicatedExcludePaths.length;
|
|
239
|
-
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
|
|
240
|
-
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;
|
|
241
|
-
const OPTION2_TOTAL_COUNT = INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);
|
|
242
|
-
if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
243
|
-
await writeRoutesFileToOutDir(_config, logger, ['/*'].concat(includeExtends?.map((entry) => entry.pattern) ?? []), deduplicatedExcludePaths
|
|
244
|
-
.map((path) => `${prependForwardSlash(path.join('/'))}`)
|
|
245
|
-
.slice(0, CLOUDFLARE_COMBINED_LIMIT -
|
|
246
|
-
EXTENDED_INCLUDE_RULES_COUNT -
|
|
247
|
-
EXTENDED_EXCLUDE_RULES_COUNT -
|
|
248
|
-
1)
|
|
249
|
-
.concat(excludeExtends?.map((entry) => entry.pattern) ?? []));
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
await writeRoutesFileToOutDir(_config, logger, deduplicatedIncludePaths
|
|
253
|
-
.map((path) => `${prependForwardSlash(path.join('/'))}`)
|
|
254
|
-
.concat(includeExtends?.map((entry) => entry.pattern) ?? []), includedPathsHaveWildcard
|
|
255
|
-
? deduplicatedExcludePaths
|
|
256
|
-
.map((path) => `${prependForwardSlash(path.join('/'))}`)
|
|
257
|
-
.concat(excludeExtends?.map((entry) => entry.pattern) ?? [])
|
|
258
|
-
: []);
|
|
259
|
-
}
|
|
129
|
+
async function createRoutesFile(_config, logger, routes, pages, redirects, includeExtends, excludeExtends) {
|
|
130
|
+
const includePaths = [];
|
|
131
|
+
const excludePaths = [];
|
|
132
|
+
const assetsPath = segmentsToCfSyntax(
|
|
133
|
+
[
|
|
134
|
+
[{ content: _config.build.assets, dynamic: false, spread: false }],
|
|
135
|
+
[{ content: "", dynamic: true, spread: false }]
|
|
136
|
+
],
|
|
137
|
+
_config
|
|
138
|
+
);
|
|
139
|
+
excludePaths.push(assetsPath);
|
|
140
|
+
for (const redirect of redirects) {
|
|
141
|
+
excludePaths.push(segmentsToCfSyntax(redirect, _config));
|
|
142
|
+
}
|
|
143
|
+
if (existsSync(fileURLToPath(_config.publicDir))) {
|
|
144
|
+
const staticFiles = await glob(`**/*`, {
|
|
145
|
+
cwd: fileURLToPath(_config.publicDir),
|
|
146
|
+
dot: true
|
|
147
|
+
});
|
|
148
|
+
for (const staticFile of staticFiles) {
|
|
149
|
+
if (["_headers", "_redirects", "_routes.json"].includes(staticFile)) continue;
|
|
150
|
+
const staticPath = staticFile;
|
|
151
|
+
const segments = removeLeadingForwardSlash(staticPath).split(path.sep).filter(Boolean).map((s) => {
|
|
152
|
+
return getParts(s);
|
|
153
|
+
});
|
|
154
|
+
excludePaths.push(segmentsToCfSyntax(segments, _config));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
let hasPrerendered404 = false;
|
|
158
|
+
for (const route of routes) {
|
|
159
|
+
const convertedPath = segmentsToCfSyntax(route.segments, _config);
|
|
160
|
+
if (route.pathname === "/404" && route.isPrerendered === true) hasPrerendered404 = true;
|
|
161
|
+
switch (route.type) {
|
|
162
|
+
case "page":
|
|
163
|
+
if (route.isPrerendered === false) includePaths.push(convertedPath);
|
|
164
|
+
break;
|
|
165
|
+
case "endpoint":
|
|
166
|
+
if (route.isPrerendered === false) includePaths.push(convertedPath);
|
|
167
|
+
else excludePaths.push(convertedPath);
|
|
168
|
+
break;
|
|
169
|
+
case "redirect":
|
|
170
|
+
excludePaths.push(convertedPath);
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
includePaths.push(convertedPath);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (const page of pages) {
|
|
178
|
+
if (page.pathname === "404") hasPrerendered404 = true;
|
|
179
|
+
const pageSegments = removeLeadingForwardSlash(page.pathname).split(path.posix.sep).filter(Boolean).map((s) => {
|
|
180
|
+
return getParts(s);
|
|
181
|
+
});
|
|
182
|
+
excludePaths.push(segmentsToCfSyntax(pageSegments, _config));
|
|
183
|
+
}
|
|
184
|
+
const includeTrie = new PathTrie();
|
|
185
|
+
for (const includePath of includePaths) {
|
|
186
|
+
includeTrie.insert(includePath);
|
|
187
|
+
}
|
|
188
|
+
const excludeTrie = new PathTrie();
|
|
189
|
+
for (const excludePath of excludePaths) {
|
|
190
|
+
if (excludePath[0] === "*") continue;
|
|
191
|
+
excludeTrie.insert(excludePath);
|
|
192
|
+
}
|
|
193
|
+
const [deduplicatedIncludePaths, includedPathsHaveWildcard] = includeTrie.reduceAllPaths(excludeTrie).getAllPaths();
|
|
194
|
+
const [deduplicatedExcludePaths, _excludedPathsHaveWildcard] = excludeTrie.reduceAllPaths(includeTrie).getAllPaths();
|
|
195
|
+
const CLOUDFLARE_COMBINED_LIMIT = 100;
|
|
196
|
+
const AUTOMATIC_INCLUDE_RULES_COUNT = deduplicatedIncludePaths.length;
|
|
197
|
+
const EXTENDED_INCLUDE_RULES_COUNT = includeExtends?.length ?? 0;
|
|
198
|
+
const INCLUDE_RULES_COUNT = AUTOMATIC_INCLUDE_RULES_COUNT + EXTENDED_INCLUDE_RULES_COUNT;
|
|
199
|
+
const AUTOMATIC_EXCLUDE_RULES_COUNT = deduplicatedExcludePaths.length;
|
|
200
|
+
const EXTENDED_EXCLUDE_RULES_COUNT = excludeExtends?.length ?? 0;
|
|
201
|
+
const EXCLUDE_RULES_COUNT = AUTOMATIC_EXCLUDE_RULES_COUNT + EXTENDED_EXCLUDE_RULES_COUNT;
|
|
202
|
+
const OPTION2_TOTAL_COUNT = INCLUDE_RULES_COUNT + (includedPathsHaveWildcard ? EXCLUDE_RULES_COUNT : 0);
|
|
203
|
+
if (!hasPrerendered404 || OPTION2_TOTAL_COUNT > CLOUDFLARE_COMBINED_LIMIT) {
|
|
204
|
+
await writeRoutesFileToOutDir(
|
|
205
|
+
_config,
|
|
206
|
+
logger,
|
|
207
|
+
["/*"].concat(includeExtends?.map((entry) => entry.pattern) ?? []),
|
|
208
|
+
deduplicatedExcludePaths.map((thisPath) => `${prependForwardSlash(thisPath.join("/"))}`).slice(
|
|
209
|
+
0,
|
|
210
|
+
CLOUDFLARE_COMBINED_LIMIT - EXTENDED_INCLUDE_RULES_COUNT - EXTENDED_EXCLUDE_RULES_COUNT - 1
|
|
211
|
+
).concat(excludeExtends?.map((entry) => entry.pattern) ?? [])
|
|
212
|
+
);
|
|
213
|
+
} else {
|
|
214
|
+
await writeRoutesFileToOutDir(
|
|
215
|
+
_config,
|
|
216
|
+
logger,
|
|
217
|
+
deduplicatedIncludePaths.map((thisPath) => `${prependForwardSlash(thisPath.join("/"))}`).concat(includeExtends?.map((entry) => entry.pattern) ?? []),
|
|
218
|
+
includedPathsHaveWildcard ? deduplicatedExcludePaths.map((thisPath) => `${prependForwardSlash(thisPath.join("/"))}`).concat(excludeExtends?.map((entry) => entry.pattern) ?? []) : []
|
|
219
|
+
);
|
|
220
|
+
}
|
|
260
221
|
}
|
|
222
|
+
export {
|
|
223
|
+
createRoutesFile,
|
|
224
|
+
getParts
|
|
225
|
+
};
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import { passthroughImageService, sharpImageService } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { passthroughImageService, sharpImageService } from "astro/config";
|
|
2
|
+
function setImageConfig(service, config, command, logger) {
|
|
3
|
+
switch (service) {
|
|
4
|
+
case "passthrough":
|
|
5
|
+
return { ...config, service: passthroughImageService() };
|
|
6
|
+
case "cloudflare":
|
|
7
|
+
return {
|
|
8
|
+
...config,
|
|
9
|
+
service: command === "dev" ? sharpImageService() : { entrypoint: "@astrojs/cloudflare/image-service" }
|
|
10
|
+
};
|
|
11
|
+
case "compile":
|
|
12
|
+
return {
|
|
13
|
+
...config,
|
|
14
|
+
service: sharpImageService(),
|
|
15
|
+
endpoint: {
|
|
16
|
+
entrypoint: command === "dev" ? void 0 : "@astrojs/cloudflare/image-endpoint"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
case "custom":
|
|
20
|
+
return { ...config };
|
|
21
|
+
default:
|
|
22
|
+
if (config.service.entrypoint === "astro/assets/services/sharp") {
|
|
23
|
+
logger.warn(
|
|
24
|
+
`The current configuration does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`
|
|
25
|
+
);
|
|
26
|
+
return { ...config, service: passthroughImageService() };
|
|
27
|
+
}
|
|
28
|
+
return { ...config };
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
|
+
export {
|
|
32
|
+
setImageConfig
|
|
33
|
+
};
|