fix: build image libraries for baseline VPS CPUs
Some checks failed
Test and deploy / Verify production build (push) Failing after 15m48s
Some checks failed
Test and deploy / Verify production build (push) Failing after 15m48s
Replace the SIMD-dependent WebAssembly fallback with source-built libvips and Sharp. Pin the libvips archive checksum, use baseline x86-64 compiler flags, retain the native binding and runtime libraries, and check JPEG/PNG/WebP processing before compilation and in the runtime image. Lint, type checking, and content/security tests passed. Full Docker verification was stopped at the user request; production build and baseline CPU runtime verification remain pending.
This commit is contained in:
@@ -2,24 +2,19 @@ import { createRequire } from 'node:module';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Check the fallback directly: Sharp 0.35.4 can hide its load error behind
|
||||
// an unrelated `err.code.endsWith` exception on unsupported native CPUs.
|
||||
try {
|
||||
require('@img/sharp-wasm32/sharp.node');
|
||||
console.log('Sharp WebAssembly binding loaded.');
|
||||
} catch (error) {
|
||||
console.error('Sharp WebAssembly binding failed to load:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const { default: sharp } = await import('sharp');
|
||||
const input = await sharp({ create: { width: 8, height: 8, channels: 3, background: '#336699' } }).webp().toBuffer();
|
||||
const metadata = await sharp(input).metadata();
|
||||
if (metadata.format !== 'webp' || metadata.width !== 8 || metadata.height !== 8) {
|
||||
throw new Error('Image encode/decode verification failed');
|
||||
if (process.argv.includes('--require-source') && !Object.keys(require.cache).some(file => /sharp[/\\]src[/\\]build[/\\]Release[/\\].+\.node$/.test(file))) {
|
||||
throw new Error('Expected the source-built Sharp binding; refusing to use a prebuilt fallback');
|
||||
}
|
||||
console.log('Sharp ESM import and image processing passed.');
|
||||
for (const format of ['jpeg', 'png', 'webp']) {
|
||||
const input = await sharp({ create: { width: 8, height: 8, channels: 3, background: '#336699' } }).toFormat(format).toBuffer();
|
||||
const metadata = await sharp(input).metadata();
|
||||
if (metadata.format !== format || metadata.width !== 8 || metadata.height !== 8) {
|
||||
throw new Error(`${format} encode/decode verification failed`);
|
||||
}
|
||||
}
|
||||
console.log(`Sharp ${sharp.versions.sharp}, libvips ${sharp.versions.vips}: JPEG, PNG and WebP passed.`);
|
||||
} catch (error) {
|
||||
console.error('Sharp image runtime failed:', error);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user