@astrojs/cloudflare 8.0.2 → 9.0.0
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/entrypoints/image-endpoint.d.ts +1 -0
- package/dist/entrypoints/image-endpoint.js +1 -0
- package/dist/entrypoints/server.advanced.js +1 -1
- package/dist/entrypoints/server.directory.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -27
- package/dist/utils/deduplicatePatterns.js +8 -6
- package/dist/utils/image-config.js +6 -0
- package/dist/utils/local-runtime.d.ts +282 -282
- package/dist/utils/sharpBundlePatch.d.ts +2 -0
- package/dist/utils/sharpBundlePatch.js +18 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -26,7 +26,7 @@ export function createExports(manifest) {
|
|
|
26
26
|
caches: caches,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
|
-
const response = await app.render(request, routeData, locals);
|
|
29
|
+
const response = await app.render(request, { routeData, locals });
|
|
30
30
|
if (app.setCookieHeaders) {
|
|
31
31
|
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
32
32
|
response.headers.append('Set-Cookie', setCookieHeader);
|
|
@@ -28,7 +28,7 @@ export function createExports(manifest) {
|
|
|
28
28
|
caches: caches,
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
|
-
const response = await app.render(request, routeData, locals);
|
|
31
|
+
const response = await app.render(request, { routeData, locals });
|
|
32
32
|
if (app.setCookieHeaders) {
|
|
33
33
|
for (const setCookieHeader of app.setCookieHeaders(response)) {
|
|
34
34
|
response.headers.append('Set-Cookie', setCookieHeader);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { DirectoryRuntime } from './entrypoints/server.directory.js';
|
|
|
5
5
|
export type Options = {
|
|
6
6
|
mode?: 'directory' | 'advanced';
|
|
7
7
|
functionPerRoute?: boolean;
|
|
8
|
-
imageService?: 'passthrough' | 'cloudflare';
|
|
8
|
+
imageService?: 'passthrough' | 'cloudflare' | 'compile';
|
|
9
9
|
/** Configure automatic `routes.json` generation */
|
|
10
10
|
routes?: {
|
|
11
11
|
/** Strategy for generating `include` and `exclude` patterns
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { prepareImageConfig } from './utils/image-config.js';
|
|
|
12
12
|
import { getLocalRuntime, getRuntimeConfig } from './utils/local-runtime.js';
|
|
13
13
|
import { prependForwardSlash } from './utils/prependForwardSlash.js';
|
|
14
14
|
import { rewriteWasmImportPath } from './utils/rewriteWasmImportPath.js';
|
|
15
|
+
import { patchSharpBundle } from './utils/sharpBundlePatch.js';
|
|
15
16
|
import { wasmModuleLoader } from './utils/wasm-module-loader.js';
|
|
16
17
|
export default function createIntegration(args) {
|
|
17
18
|
let _config;
|
|
@@ -153,7 +154,14 @@ export default function createIntegration(args) {
|
|
|
153
154
|
const pagesDirname = relative(fileURLToPath(_buildConfig.server), pathsGroup[0]).split(sep)[0];
|
|
154
155
|
const absolutePagesDirname = fileURLToPath(new URL(pagesDirname, _buildConfig.server));
|
|
155
156
|
const urlWithinFunctions = new URL(relative(absolutePagesDirname, pathsGroup[0]), functionsUrl);
|
|
157
|
+
const esbuildPlugins = [];
|
|
158
|
+
if (args?.imageService === 'compile') {
|
|
159
|
+
esbuildPlugins.push(patchSharpBundle());
|
|
160
|
+
}
|
|
156
161
|
const relativePathToAssets = relative(dirname(fileURLToPath(urlWithinFunctions)), fileURLToPath(assetsUrl));
|
|
162
|
+
if (args?.wasmModuleImports) {
|
|
163
|
+
esbuildPlugins.push(rewriteWasmImportPath({ relativePathToAssets }));
|
|
164
|
+
}
|
|
157
165
|
await esbuild.build({
|
|
158
166
|
target: 'es2022',
|
|
159
167
|
platform: 'browser',
|
|
@@ -188,9 +196,7 @@ export default function createIntegration(args) {
|
|
|
188
196
|
logOverride: {
|
|
189
197
|
'ignored-bare-import': 'silent',
|
|
190
198
|
},
|
|
191
|
-
plugins:
|
|
192
|
-
? []
|
|
193
|
-
: [rewriteWasmImportPath({ relativePathToAssets })],
|
|
199
|
+
plugins: esbuildPlugins,
|
|
194
200
|
});
|
|
195
201
|
}
|
|
196
202
|
const outputFiles = await glob('**/*', {
|
|
@@ -228,6 +234,17 @@ export default function createIntegration(args) {
|
|
|
228
234
|
const buildPath = fileURLToPath(entryUrl);
|
|
229
235
|
// A URL for the final build path after renaming
|
|
230
236
|
const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, '.js'));
|
|
237
|
+
const esbuildPlugins = [];
|
|
238
|
+
if (args?.imageService === 'compile') {
|
|
239
|
+
esbuildPlugins.push(patchSharpBundle());
|
|
240
|
+
}
|
|
241
|
+
if (args?.wasmModuleImports) {
|
|
242
|
+
esbuildPlugins.push(rewriteWasmImportPath({
|
|
243
|
+
relativePathToAssets: isModeDirectory
|
|
244
|
+
? relative(fileURLToPath(functionsUrl), fileURLToPath(assetsUrl))
|
|
245
|
+
: relative(fileURLToPath(_buildConfig.client), fileURLToPath(assetsUrl)),
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
231
248
|
await esbuild.build({
|
|
232
249
|
target: 'es2022',
|
|
233
250
|
platform: 'browser',
|
|
@@ -261,15 +278,7 @@ export default function createIntegration(args) {
|
|
|
261
278
|
logOverride: {
|
|
262
279
|
'ignored-bare-import': 'silent',
|
|
263
280
|
},
|
|
264
|
-
plugins:
|
|
265
|
-
? []
|
|
266
|
-
: [
|
|
267
|
-
rewriteWasmImportPath({
|
|
268
|
-
relativePathToAssets: isModeDirectory
|
|
269
|
-
? relative(fileURLToPath(functionsUrl), fileURLToPath(assetsUrl))
|
|
270
|
-
: relative(fileURLToPath(_buildConfig.client), fileURLToPath(assetsUrl)),
|
|
271
|
-
}),
|
|
272
|
-
],
|
|
281
|
+
plugins: esbuildPlugins,
|
|
273
282
|
});
|
|
274
283
|
// Rename to worker.js
|
|
275
284
|
await fs.promises.rename(buildPath, finalBuildUrl);
|
|
@@ -408,21 +417,39 @@ export default function createIntegration(args) {
|
|
|
408
417
|
include: ['/*'],
|
|
409
418
|
exclude: deduplicatePatterns(staticPathList.concat(args?.routes?.exclude ?? [])),
|
|
410
419
|
};
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
switch (args?.routes?.strategy) {
|
|
421
|
+
case 'include':
|
|
422
|
+
await fs.promises.writeFile(new URL('./_routes.json', _config.outDir), JSON.stringify({
|
|
423
|
+
version: 1,
|
|
424
|
+
...includeStrategy,
|
|
425
|
+
}, null, 2));
|
|
426
|
+
break;
|
|
427
|
+
case 'exclude':
|
|
428
|
+
await fs.promises.writeFile(new URL('./_routes.json', _config.outDir), JSON.stringify({
|
|
429
|
+
version: 1,
|
|
430
|
+
...excludeStrategy,
|
|
431
|
+
}, null, 2));
|
|
432
|
+
break;
|
|
433
|
+
default:
|
|
434
|
+
{
|
|
435
|
+
const includeStrategyLength = includeStrategy
|
|
436
|
+
? includeStrategy.include.length + includeStrategy.exclude.length
|
|
437
|
+
: Infinity;
|
|
438
|
+
const excludeStrategyLength = excludeStrategy
|
|
439
|
+
? excludeStrategy.include.length + excludeStrategy.exclude.length
|
|
440
|
+
: Infinity;
|
|
441
|
+
const winningStrategy = notFoundIsSSR
|
|
442
|
+
? excludeStrategy
|
|
443
|
+
: includeStrategyLength <= excludeStrategyLength
|
|
444
|
+
? includeStrategy
|
|
445
|
+
: excludeStrategy;
|
|
446
|
+
await fs.promises.writeFile(new URL('./_routes.json', _config.outDir), JSON.stringify({
|
|
447
|
+
version: 1,
|
|
448
|
+
...winningStrategy,
|
|
449
|
+
}, null, 2));
|
|
450
|
+
}
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
426
453
|
}
|
|
427
454
|
},
|
|
428
455
|
},
|
|
@@ -9,15 +9,17 @@ export function deduplicatePatterns(patterns) {
|
|
|
9
9
|
const openPatterns = [];
|
|
10
10
|
// A value in the set may only occur once; it is unique in the set's collection.
|
|
11
11
|
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
|
|
12
|
-
|
|
12
|
+
const uniquePatterns = [...new Set(patterns)];
|
|
13
|
+
for (const pattern of uniquePatterns) {
|
|
14
|
+
if (pattern.endsWith('*')) {
|
|
15
|
+
openPatterns.push(new RegExp(`^${pattern.replace(/(\*\/)*\*$/g, '[^*\n]*$')}`));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return uniquePatterns
|
|
13
19
|
.sort((a, b) => a.length - b.length)
|
|
14
20
|
.filter((pattern) => {
|
|
15
|
-
if (openPatterns.some((p) => p.test(pattern)))
|
|
21
|
+
if (openPatterns.some((p) => p.test(pattern)))
|
|
16
22
|
return false;
|
|
17
|
-
}
|
|
18
|
-
if (pattern.endsWith('*')) {
|
|
19
|
-
openPatterns.push(new RegExp(`^${pattern.replace(/(\*\/)*\*$/g, '.*')}`));
|
|
20
|
-
}
|
|
21
23
|
return true;
|
|
22
24
|
});
|
|
23
25
|
}
|
|
@@ -10,6 +10,12 @@ export function prepareImageConfig(service, config, command, logger) {
|
|
|
10
10
|
? sharpImageService()
|
|
11
11
|
: { entrypoint: '@astrojs/cloudflare/image-service' },
|
|
12
12
|
};
|
|
13
|
+
case 'compile':
|
|
14
|
+
return {
|
|
15
|
+
...config,
|
|
16
|
+
service: sharpImageService(),
|
|
17
|
+
endpoint: command === 'dev' ? undefined : '@astrojs/cloudflare/image-endpoint',
|
|
18
|
+
};
|
|
13
19
|
default:
|
|
14
20
|
if (config.service.entrypoint === 'astro/assets/services/sharp' ||
|
|
15
21
|
config.service.entrypoint === 'astro/assets/services/squoosh') {
|