@astrojs/cloudflare 8.0.1 → 8.1.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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
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: !args?.wasmModuleImports
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: !args?.wasmModuleImports
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);
@@ -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') {