CodeSampleX

Exemplo

@img/sharp-webcontainers-wasm32 0.35.5

Amostra verificada para npm @img/sharp-webcontainers-wasm32 0.35.5. O contrato rodou em node 22 · linux debian/x64 · docker e passou.

sha256:43dc7f585852621e0f2da3ed97b23d5008ec904dcd482e97a3683b45b2817f0d

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-11-29

Caso

HOW
Objetivo
verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5
Pacotes
Ambiente
node 22.23.2
Criado
2026-11-29T06:03:01Z

Contrato

  1. Installing @img/sharp-webcontainers-wasm32@0.35.5 on linux/x64 requires force=true in .npmrc because package.json restricts cpu to wasm32
  2. Requiring @img/sharp-webcontainers-wasm32, @img/sharp-webcontainers-wasm32/package, or @img/sharp-webcontainers-wasm32/versions throws ERR_PACKAGE_PATH_NOT_EXPORTED in 0.35.5
  3. Requiring @img/sharp-webcontainers-wasm32/sharp.node loads the WebAssembly libvips 8.18.7 addon with isWasm=true and isGlobal=false, and dynamic ESM import resolves to the same addon
  4. binding.format() reports png, jpeg, and webp codecs with buffer input and output enabled
  5. binding.cache(24, 16, 48), binding.concurrency(2)/concurrency(1), and binding.simd(false)/simd(true) update and return libvips runtime settings
  6. binding.metadata() requires input.limitInputChannels as a number in 0.35.5 and decodes an offline 2x3 RGBA PNG returning format=png, mediaType=image/png, width=2, height=3, channels=4, hasAlpha=true, space=srgb
  7. binding.stats() returns isOpaque=false and exact 4-channel means [200, 100, 50, 128] for the offline 2x3 RGBA PNG
  8. binding.metadata() passes an Error matching unsupported image format to its callback when given invalid image bytes

Arquivos

  • .npmrc
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.cjs
  • test/contract.cjs

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

.npmrc
force=true
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:93568e2e22bdc16df8782c9f928e0a54cacdb7c4c2dd038a13ed9cb07057a778","constraints":{"executionContext":"node"},"contract":["Installing @img/sharp-webcontainers-wasm32@0.35.5 on linux/x64 requires force=true in .npmrc because package.json restricts cpu to wasm32","Requiring @img/sharp-webcontainers-wasm32, @img/sharp-webcontainers-wasm32/package, or @img/sharp-webcontainers-wasm32/versions throws ERR_PACKAGE_PATH_NOT_EXPORTED in 0.35.5","Requiring @img/sharp-webcontainers-wasm32/sharp.node loads the WebAssembly libvips 8.18.7 addon with isWasm=true and isGlobal=false, and dynamic ESM import resolves to the same addon","binding.format() reports png, jpeg, and webp codecs with buffer input and output enabled","binding.cache(24, 16, 48), binding.concurrency(2)/concurrency(1), and binding.simd(false)/simd(true) update and return libvips runtime settings","binding.metadata() requires input.limitInputChannels as a number in 0.35.5 and decodes an offline 2x3 RGBA PNG returning format=png, mediaType=image/png, width=2, height=3, channels=4, hasAlpha=true, space=srgb","binding.stats() returns isOpaque=false and exact 4-channel means [200, 100, 50, 128] for the offline 2x3 RGBA PNG","binding.metadata() passes an Error matching unsupported image format to its callback when given invalid image bytes"],"goal":"verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5","kind":"HOW","packages":["pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5"],"schemaVersion":1,"subject":"pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sharp-webcontainers-wasm32-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sharp-webcontainers-wasm32-sample",
      "version": "1.0.0",
      "dependencies": {
        "@img/sharp-webcontainers-wasm32": "0.35.5"
      }
    },
    "node_modules/@emnapi/runtime": {
      "version": "1.11.3",
      "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
      "integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
      "license": "MIT",
      "dependencies": {
        "tslib": "^2.4.0"
      }
    },
    "node_modules/@img/sharp-wasm32": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz",
      "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==",
      "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
      "dependencies": {
        "@emnapi/runtime": "^1.11.3"
      },
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/@img/sharp-webcontainers-wasm32": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.5.tgz",
      "integrity": "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA==",
      "cpu": [
        "wasm32"
      ],
      "license": "Apache-2.0",
      "dependencies": {
        "@img/sharp-wasm32": "0.35.5"
      },
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/tslib": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
      "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sharp-webcontainers-wasm32-sample",
  "version": "1.0.0",
  "private": true,
  "type": "commonjs",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@img/sharp-webcontainers-wasm32": "0.35.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.cjs
'use strict';

const zlib = require('node:zlib');

function loadBinding() {
  return require('@img/sharp-webcontainers-wasm32/sharp.node');
}

function crc32(buffer) {
  let crc = 0xffffffff;
  for (let i = 0; i < buffer.length; i += 1) {
    crc ^= buffer[i];
    for (let bit = 0; bit < 8; bit += 1) {
      crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
    }
  }
  return (crc ^ 0xffffffff) >>> 0;
}

function makePngChunk(type, data) {
  const typeBuffer = Buffer.from(type, 'ascii');
  const lengthBuffer = Buffer.alloc(4);
  lengthBuffer.writeUInt32BE(data.length, 0);
  const body = Buffer.concat([typeBuffer, data]);
  const crcBuffer = Buffer.alloc(4);
  crcBuffer.writeUInt32BE(crc32(body), 0);
  return Buffer.concat([lengthBuffer, body, crcBuffer]);
}

function createSolidPng(width, height, rgba) {
  const [r, g, b, a] = rgba;
  const signature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
  const ihdr = Buffer.alloc(13);
  ihdr.writeUInt32BE(width, 0);
  ihdr.writeUInt32BE(height, 4);
  ihdr[8] = 8; // 8-bit channel depth
  ihdr[9] = 6; // RGBA color type

  const rows = [];
  for (let y = 0; y < height; y += 1) {
    const row = Buffer.alloc(1 + width * 4);
    row[0] = 0; // filter type None
    for (let x = 0; x < width; x += 1) {
      const offset = 1 + x * 4;
      row[offset] = r;
      row[offset + 1] = g;
      row[offset + 2] = b;
      row[offset + 3] = a;
    }
    rows.push(row);
  }

  const idat = zlib.deflateSync(Buffer.concat(rows));
  return Buffer.concat([
    signature,
    makePngChunk('IHDR', ihdr),
    makePngChunk('IDAT', idat),
    makePngChunk('IEND', Buffer.alloc(0))
  ]);
}

function buildInputOptions(buffer) {
  return {
    input: {
      buffer,
      failOn: 'warning',
      limitInputPixels: 268402689,
      limitInputChannels: 0,
      unlimited: false,
      autoOrient: false,
      sequentialRead: false,
      density: 72,
      ignoreIcc: false,
      pages: 1,
      page: 0
    },
    debuglog: () => {}
  };
}

function readMetadata(binding, buffer) {
  return new Promise((resolve, reject) => {
    binding.metadata(buildInputOptions(buffer), (err, info) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(info);
    });
  });
}

function readStats(binding, buffer) {
  return new Promise((resolve, reject) => {
    binding.stats(buildInputOptions(buffer), (err, stats) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(stats);
    });
  });
}

module.exports = {
  loadBinding,
  createSolidPng,
  readMetadata,
  readStats
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const {
  loadBinding,
  createSolidPng,
  readMetadata,
  readStats
} = require('../src/index.cjs');

async function main() {
  // 1. Bare specifier and json subpaths fail with ERR_PACKAGE_PATH_NOT_EXPORTED in 0.35.5
  for (const specifier of [
    '@img/sharp-webcontainers-wasm32',
    '@img/sharp-webcontainers-wasm32/package',
    '@img/sharp-webcontainers-wasm32/versions'
  ]) {
    assert.throws(
      () => require(specifier),
      (err) => err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED',
      `Expected ERR_PACKAGE_PATH_NOT_EXPORTED for ${specifier}`
    );
  }

  // 2. Loading ./sharp.node via CJS require returns the WASM libvips 8.18.7 addon
  const binding = loadBinding();
  assert.equal(typeof binding, 'object');
  assert.deepEqual(binding.libvipsVersion(), {
    semver: '8.18.7',
    isGlobal: false,
    isWasm: true
  });

  // 3. Dynamic ESM import resolves to the same WASM libvips 8.18.7 addon
  const esmModule = await import('@img/sharp-webcontainers-wasm32/sharp.node');
  assert.equal(typeof esmModule.default, 'object');
  assert.deepEqual(esmModule.default.libvipsVersion(), {
    semver: '8.18.7',
    isGlobal: false,
    isWasm: true
  });

  // 4. Codec format registry reports png, jpeg, and webp buffer input/output support
  const formats = binding.format();
  for (const codec of ['png', 'jpeg', 'webp']) {
    assert.equal(formats[codec].id, codec);
    assert.equal(formats[codec].input.buffer, true);
    assert.equal(formats[codec].output.buffer, true);
  }

  // 5. Runtime configuration controls (cache, concurrency, simd, counters)
  const updatedCache = binding.cache(24, 16, 48);
  assert.equal(updatedCache.memory.max, 24);
  assert.equal(updatedCache.files.max, 16);
  assert.equal(updatedCache.items.max, 48);
  assert.equal(binding.concurrency(2), 2);
  assert.equal(binding.concurrency(1), 1);
  assert.equal(binding.simd(false), false);
  assert.equal(binding.simd(true), true);
  assert.deepEqual(binding.counters(), { queue: 0, process: 0 });

  // 6. Offline PNG metadata decoding (requires limitInputChannels in 0.35.5)
  const pngBuffer = createSolidPng(2, 3, [200, 100, 50, 128]);
  const meta = await readMetadata(binding, pngBuffer);
  assert.equal(meta.format, 'png');
  assert.equal(meta.mediaType, 'image/png');
  assert.equal(meta.width, 2);
  assert.equal(meta.height, 3);
  assert.equal(meta.channels, 4);
  assert.equal(meta.hasAlpha, true);
  assert.equal(meta.space, 'srgb');

  // 7. Offline PNG channel statistics computation
  const stats = await readStats(binding, pngBuffer);
  assert.equal(stats.isOpaque, false);
  assert.equal(stats.channels.length, 4);
  assert.deepEqual(
    stats.channels.map((ch) => ch.mean),
    [200, 100, 50, 128]
  );

  // 8. Invalid image bytes pass an Error to the metadata callback
  await assert.rejects(
    () => readMetadata(binding, Buffer.from('not-an-image')),
    /unsupported image format/i
  );
}

main().catch((err) => {
  console.error(err);
  process.exitCode = 1;
});

Seeder de origem

anônimo