* Revert "Allow image-pool to be used as its own Worker (#5317)"
This reverts commit d701ae074a
.
* Adding a changeset
* Remove diff
* Remove unused code
This commit is contained in:
parent
ae41f25e10
commit
20e60c6e08
5 changed files with 8 additions and 39 deletions
5
.changeset/red-worms-occur.md
Normal file
5
.changeset/red-worms-occur.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/image': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes regression with local builds
|
|
@ -11,12 +11,6 @@ export { getPicture } from './lib/get-picture.js';
|
||||||
|
|
||||||
const PKG_NAME = '@astrojs/image';
|
const PKG_NAME = '@astrojs/image';
|
||||||
const ROUTE_PATTERN = '/_image';
|
const ROUTE_PATTERN = '/_image';
|
||||||
const UNSUPPORTED_ADAPTERS = new Set([
|
|
||||||
'@astrojs/cloudflare',
|
|
||||||
'@astrojs/deno',
|
|
||||||
'@astrojs/netlify/edge-functions',
|
|
||||||
'@astrojs/vercel/edge',
|
|
||||||
]);
|
|
||||||
|
|
||||||
interface BuildConfig {
|
interface BuildConfig {
|
||||||
client: URL;
|
client: URL;
|
||||||
|
@ -106,13 +100,6 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
|
||||||
_buildConfig = config.build;
|
_buildConfig = config.build;
|
||||||
},
|
},
|
||||||
'astro:build:start': ({ buildConfig }) => {
|
'astro:build:start': ({ buildConfig }) => {
|
||||||
const adapterName = _config.adapter?.name;
|
|
||||||
if (adapterName && UNSUPPORTED_ADAPTERS.has(adapterName)) {
|
|
||||||
throw new Error(
|
|
||||||
`@astrojs/image is not supported with the ${adapterName} adapter. Please choose a Node.js compatible adapter.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Backwards compat
|
// Backwards compat
|
||||||
if (needsBuildConfig) {
|
if (needsBuildConfig) {
|
||||||
_buildConfig = buildConfig;
|
_buildConfig = buildConfig;
|
||||||
|
|
|
@ -3,12 +3,11 @@ import { red } from 'kleur/colors';
|
||||||
import { error } from '../utils/logger.js';
|
import { error } from '../utils/logger.js';
|
||||||
import { metadata } from '../utils/metadata.js';
|
import { metadata } from '../utils/metadata.js';
|
||||||
import { isRemoteImage } from '../utils/paths.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 { Operation } from '../vendor/squoosh/image.js';
|
||||||
import type { OutputFormat, TransformOptions } from './index.js';
|
import type { OutputFormat, TransformOptions } from './index.js';
|
||||||
import { BaseSSRService } from './index.js';
|
import { BaseSSRService } from './index.js';
|
||||||
|
|
||||||
const imagePoolModulePromise = import('../vendor/squoosh/image-pool.js');
|
|
||||||
|
|
||||||
class SquooshService extends BaseSSRService {
|
class SquooshService extends BaseSSRService {
|
||||||
async processAvif(image: any, transform: TransformOptions) {
|
async processAvif(image: any, transform: TransformOptions) {
|
||||||
const encodeOptions = transform.quality
|
const encodeOptions = transform.quality
|
||||||
|
@ -113,7 +112,7 @@ class SquooshService extends BaseSSRService {
|
||||||
});
|
});
|
||||||
throw new Error(`Unknown image output: "${transform.format}" used for ${transform.src}`);
|
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);
|
const data = await processBuffer(inputBuffer, operations, transform.format, transform.quality);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { isMainThread } from 'node:worker_threads';
|
import { isMainThread } from 'node:worker_threads';
|
||||||
import { cpus } from 'os';
|
import { cpus } from 'os';
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
import type { OutputFormat } from '../../loaders/index.js';
|
import type { OutputFormat } from '../../loaders/index.js';
|
||||||
import execOnce from '../../utils/execOnce.js';
|
import execOnce from '../../utils/execOnce.js';
|
||||||
import WorkerPool from '../../utils/workerPool.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
|
// There will be at most 7 workers needed since each worker will take
|
||||||
// at least 1 operation type.
|
// at least 1 operation type.
|
||||||
Math.max(1, Math.min(cpus().length - 1, 7)),
|
Math.max(1, Math.min(cpus().length - 1, 7)),
|
||||||
fileURLToPath(import.meta.url)
|
'./node_modules/@astrojs/image/dist/vendor/squoosh/image-pool.js'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -113,27 +113,6 @@ export function createPlugin(config: AstroConfig, options: Required<IntegrationO
|
||||||
return next();
|
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) {
|
async renderChunk(code) {
|
||||||
const assetUrlRE = /__ASTRO_IMAGE_ASSET__([a-z\d]{8})__(?:_(.*?)__)?/g;
|
const assetUrlRE = /__ASTRO_IMAGE_ASSET__([a-z\d]{8})__(?:_(.*?)__)?/g;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue