CodeSampleX

Beispiel

require-asset 1.2.2: require-asset

Verifiziertes Beispiel für npm require-asset 1.2.2: require-asset. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand.

sha256:3c0eb33df1bd80671e4f284d2f8ca472ab6118f219fc87897852d8ceb5548737

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Fall

HOW
Ziel
verify pkg:npm/require-asset@1.2.2
Pakete
Symbole
  • require-asset
Erstellt
2026-08-27T13:00:53Z

Contract

  1. package manifest specifies exports, Apache-2.0 license, and bare-module-resolve dependency
  2. exports asset resolution function accepting specifier and parent module path string or URL instance
  3. resolves relative asset paths using filesystem path string or URL instance as parentURL
  4. reads package metadata and evaluates resolution conditions for assets
  5. throws ASSET_NOT_FOUND error with specifier, referrer, and candidates properties when asset is missing

Dateien

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs
  • test/fixtures/data.txt
  • test/fixtures/info.json

Quellartefakt herunterladen (tar.gz)

Quelltext

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/require-asset@1.2.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/require-asset@1.2.2
Demonstrate these symbols/APIs:
  - require-asset

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:f2750ecbba990cb46153ab52326518f045a8dad0ae0af2736135dfbca76ee884","contract":["package manifest specifies exports, Apache-2.0 license, and bare-module-resolve dependency","exports asset resolution function accepting specifier and parent module path string or URL instance","resolves relative asset paths using filesystem path string or URL instance as parentURL","reads package metadata and evaluates resolution conditions for assets","throws ASSET_NOT_FOUND error with specifier, referrer, and candidates properties when asset is missing"],"goal":"verify pkg:npm/require-asset@1.2.2","kind":"HOW","packages":["pkg:npm/require-asset@1.2.2"],"schemaVersion":1,"symbols":["require-asset"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/require-asset@1.2.2"],"schemaVersion":1,"subject":"pkg:npm/require-asset@1.2.2","symbols":["require-asset"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-require-asset",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-require-asset",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "require-asset": "1.2.2"
      }
    },
    "node_modules/bare-module-resolve": {
      "version": "1.12.4",
      "resolved": "https://registry.npmjs.org/bare-module-resolve/-/bare-module-resolve-1.12.4.tgz",
      "integrity": "sha512-xcfgg2u7HqgJiBmah71O9vvdFAgHCvkqC/WSC2O7Bbgosoc1eC/BWe/6IDJ4OsfKlkxuvC/TDWXC+oH5yeW8mA==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-semver": "^1.0.0"
      },
      "peerDependencies": {
        "bare-url": "*"
      },
      "peerDependenciesMeta": {
        "bare-url": {
          "optional": true
        }
      }
    },
    "node_modules/bare-semver": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.1.0.tgz",
      "integrity": "sha512-1Hw5qJ7hXdVt3uPUqjeFTuxyvBUJauvz5A1I2jk8gzjZMHp04n//6nV9MDbG9CMw78JHY2lGV0w6s//LrASm2w==",
      "license": "Apache-2.0"
    },
    "node_modules/require-asset": {
      "version": "1.2.2",
      "resolved": "https://registry.npmjs.org/require-asset/-/require-asset-1.2.2.tgz",
      "integrity": "sha512-uc8nWKhqAxVD9Z4rST2b4yaemrC9Xb5vA1wlCz5AiCYnBYdwGRWNqFjneA5zRILzlo1MNrB63ry9+pc8wNR26w==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-module-resolve": "^1.6.2"
      },
      "engines": {
        "bare": ">=1.10.0",
        "node": ">=18"
      }
    }
  }
}
package.json
{
  "name": "sample-require-asset",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "require-asset": "1.2.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/require-asset@1.2.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/require-asset@1.2.2"
  ],
  "symbols": [
    "require-asset"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

const require = createRequire(import.meta.url);

// 1. Verify package manifest and metadata
const pkgPath = require.resolve('require-asset/package');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

assert.equal(pkg.name, 'require-asset', 'Package name must be require-asset');
assert.equal(pkg.version, '1.2.2', 'Package version must be 1.2.2');
assert.equal(pkg.license, 'Apache-2.0', 'Package license must be Apache-2.0');
assert.ok(pkg.exports, 'Package must define exports');
assert.equal(pkg.exports['./package'], './package.json', 'Package export must point to ./package.json');
assert.equal(pkg.exports['.'].node, './lib/node.js', 'Root node export must point to ./lib/node.js');
assert.equal(pkg.exports['.'].bare, './lib/bare.js', 'Root bare export must point to ./lib/bare.js');
assert.equal(pkg.exports['.'].default, './lib/default.js', 'Root default export must point to ./lib/default.js');
assert.ok(pkg.dependencies['bare-module-resolve'], 'Package must depend on bare-module-resolve');

// 2. Verify imported module function
const asset = require('require-asset');
assert.equal(typeof asset, 'function', 'require-asset must export a function');

// 3. Verify asset resolution with filesystem path string and URL object
const currentFilePath = fileURLToPath(import.meta.url);
const fixtureTxtPath = path.resolve(path.dirname(currentFilePath), 'fixtures', 'data.txt');
const fixtureJsonPath = path.resolve(path.dirname(currentFilePath), 'fixtures', 'info.json');

// Resolving with filesystem path string (as in CommonJS __filename or fileURLToPath)
const resolvedTxtFromPath = asset('./fixtures/data.txt', currentFilePath);
assert.equal(resolvedTxtFromPath, fixtureTxtPath, 'Resolved text path must match expected fixture path');
assert.equal(fs.readFileSync(resolvedTxtFromPath, 'utf8').trim(), 'hello require-asset');

const resolvedJsonFromPath = asset('./fixtures/info.json', currentFilePath);
assert.equal(resolvedJsonFromPath, fixtureJsonPath, 'Resolved JSON path must match expected fixture path');
const jsonContent = JSON.parse(fs.readFileSync(resolvedJsonFromPath, 'utf8'));
assert.equal(jsonContent.type, 'sample');
assert.equal(jsonContent.value, 42);

// Resolving with URL object (new URL(import.meta.url) or pathToFileURL(filePath))
const currentUrlObj = new URL(import.meta.url);
const resolvedTxtFromUrlObj = asset('./fixtures/data.txt', currentUrlObj);
assert.equal(resolvedTxtFromUrlObj, fixtureTxtPath, 'Resolved path using URL object must match');

const currentPathToFileUrl = pathToFileURL(currentFilePath);
const resolvedJsonFromPathUrl = asset('./fixtures/info.json', currentPathToFileUrl);
assert.equal(resolvedJsonFromPathUrl, fixtureJsonPath, 'Resolved path using pathToFileURL must match');

// 4. Verify ASSET_NOT_FOUND error when asset cannot be resolved
let threw = false;
try {
  asset('./fixtures/nonexistent_asset.bin', currentFilePath);
} catch (err) {
  threw = true;
  assert.equal(err.code, 'ASSET_NOT_FOUND', 'Error code must be ASSET_NOT_FOUND');
  assert.equal(err.specifier, './fixtures/nonexistent_asset.bin', 'Error must contain specifier');
  assert.ok(err.referrer instanceof URL || typeof err.referrer === 'object', 'Error must contain referrer URL');
  assert.ok(Array.isArray(err.candidates), 'Error must contain candidates array');
  assert.ok(err.message.includes("Cannot find asset './fixtures/nonexistent_asset.bin'"), 'Error message must describe missing asset');
}
assert.equal(threw, true, 'Calling asset with non-existent file must throw');

console.log('Contract tests passed successfully.');
test/fixtures/data.txt
hello require-asset
test/fixtures/info.json
{"type":"sample","value":42}

Ursprungs-Seeder

anonym