CodeSampleX

샘플

require-asset 1.2.2: require-asset

검증된 샘플 — npm require-asset 1.2.2: require-asset. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: package manifest specifies exports, Apache-2.0…

sha256:3c0eb33df1bd80671e4f284d2f8ca472ab6118f219fc87897852d8ceb5548737

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify pkg:npm/require-asset@1.2.2
패키지
심벌
  • require-asset
생성일
2026-08-27T13:00:53Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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}

오리진 시더

익명