Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Allow image-pool to be used as its own Worker (#5317)" #5360

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-worms-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/image': patch
---

Fixes regression with local builds
4 changes: 3 additions & 1 deletion packages/integrations/image/src/index.ts
Original file line number Diff line number Diff line change
@@ -11,12 +11,15 @@ export { getPicture } from './lib/get-picture.js';

const PKG_NAME = '@astrojs/image';
const ROUTE_PATTERN = '/_image';
<<<<<<< HEAD
const UNSUPPORTED_ADAPTERS = new Set([
'@astrojs/cloudflare',
'@astrojs/deno',
'@astrojs/netlify/edge-functions',
'@astrojs/vercel/edge',
]);
=======
>>>>>>> parent of d701ae074 (Allow image-pool to be used as its own Worker (#5317))

interface BuildConfig {
client: URL;
@@ -112,7 +115,6 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
`@astrojs/image is not supported with the ${adapterName} adapter. Please choose a Node.js compatible adapter.`
);
}

// Backwards compat
if (needsBuildConfig) {
_buildConfig = buildConfig;
5 changes: 2 additions & 3 deletions packages/integrations/image/src/loaders/squoosh.ts
Original file line number Diff line number Diff line change
@@ -3,12 +3,11 @@ import { red } from 'kleur/colors';
import { error } from '../utils/logger.js';
import { metadata } from '../utils/metadata.js';
import { isRemoteImage } from '../utils/paths.js';
import { processBuffer } from '../vendor/squoosh/image-pool.js';
import type { Operation } from '../vendor/squoosh/image.js';
import type { OutputFormat, TransformOptions } from './index.js';
import { BaseSSRService } from './index.js';

const imagePoolModulePromise = import('../vendor/squoosh/image-pool.js');

class SquooshService extends BaseSSRService {
async processAvif(image: any, transform: TransformOptions) {
const encodeOptions = transform.quality
@@ -113,7 +112,7 @@ class SquooshService extends BaseSSRService {
});
throw new Error(`Unknown image output: "${transform.format}" used for ${transform.src}`);
}
const { processBuffer } = await imagePoolModulePromise;

const data = await processBuffer(inputBuffer, operations, transform.format, transform.quality);

return {
3 changes: 1 addition & 2 deletions packages/integrations/image/src/vendor/squoosh/image-pool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { isMainThread } from 'node:worker_threads';
import { cpus } from 'os';
import { fileURLToPath } from 'url';
import type { OutputFormat } from '../../loaders/index.js';
import execOnce from '../../utils/execOnce.js';
import WorkerPool from '../../utils/workerPool.js';
@@ -13,7 +12,7 @@ const getWorker = execOnce(
// There will be at most 7 workers needed since each worker will take
// at least 1 operation type.
Math.max(1, Math.min(cpus().length - 1, 7)),
fileURLToPath(import.meta.url)
'./node_modules/@astrojs/image/dist/vendor/squoosh/image-pool.js'
);
}
)
21 changes: 0 additions & 21 deletions packages/integrations/image/src/vite-plugin-astro-image.ts
Original file line number Diff line number Diff line change
@@ -113,27 +113,6 @@ export function createPlugin(config: AstroConfig, options: Required<IntegrationO
return next();
});
},
outputOptions(outputOptions) {
if (resolvedConfig.build.ssr) {
// Build the image-pool chunk to the top-level and not inside of a chunks/
// folder. This is because the wasm is built at the top-level and this makes
// it accessible from the pool worker.
const chunkFileNames = outputOptions.chunkFileNames;
outputOptions.chunkFileNames = (chunk) => {
for (const name of Object.keys(chunk.modules)) {
if (name.endsWith('vendor/squoosh/image-pool.js')) {
return '[name].[hash].mjs';
}
}

if (typeof chunkFileNames === 'function') {
return chunkFileNames.call(this, chunk);
}

return chunkFileNames!;
};
}
},
async renderChunk(code) {
const assetUrlRE = /__ASTRO_IMAGE_ASSET__([a-z\d]{8})__(?:_(.*?)__)?/g;