CodeSampleX

サンプル

node-abi 3.96.0: additionalTargets

検証済みサンプル — npm node-abi 3.96.0: additionalTargets. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: additionalTargets is exported as an array from…

sha256:d637f3ec40c08ccc2f31e50d52d044acfbbd8a1c8ac1edca24657573a647d7c3

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-09-07

ケース

HOW
ゴール
verify node-abi.additionalTargets in pkg:npm/node-abi@3.96.0
パッケージ
シンボル
  • additionalTargets
作成日
2026-09-07T02:55:45Z

コントラクト

  1. additionalTargets is exported as an array from node-abi containing node-webkit runtime targets
  2. each target entry in additionalTargets has runtime, target, abi strings and lts set to false
  3. every target in additionalTargets is present in allTargets
  4. additionalTargets is disjoint from supportedTargets and deprecatedTargets
  5. getAbi resolves node-webkit target versions to their corresponding abi strings
  6. getTarget resolves node-webkit abi strings to their corresponding target versions
  7. getAbi and getTarget throw error when queried with unsupported node-webkit target or abi
  8. isAdditionalTarget identifies whether a given runtime and target version is in additionalTargets
  9. findAdditionalTarget looks up node-webkit target records by target version or abi string

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

ソースアーティファクトをダウンロード (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 node-abi.additionalTargets in pkg:npm/node-abi@3.96.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-abi@3.96.0
Demonstrate these symbols/APIs:
  - additionalTargets

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:9a4e5ea15e391f54eac8a2aeeb8f0d304940ad15499338bb61b52a17bfb9059c","contract":["additionalTargets is exported as an array from node-abi containing node-webkit runtime targets","each target entry in additionalTargets has runtime, target, abi strings and lts set to false","every target in additionalTargets is present in allTargets","additionalTargets is disjoint from supportedTargets and deprecatedTargets","getAbi resolves node-webkit target versions to their corresponding abi strings","getTarget resolves node-webkit abi strings to their corresponding target versions","getAbi and getTarget throw error when queried with unsupported node-webkit target or abi","isAdditionalTarget identifies whether a given runtime and target version is in additionalTargets","findAdditionalTarget looks up node-webkit target records by target version or abi string"],"goal":"verify node-abi.additionalTargets in pkg:npm/node-abi@3.96.0","kind":"HOW","packages":["pkg:npm/node-abi@3.96.0"],"schemaVersion":1,"symbols":["additionalTargets"]},"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/node-abi@3.96.0"],"schemaVersion":1,"subject":"pkg:npm/node-abi@3.96.0","symbols":["additionalTargets"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-node-abi-additional-targets",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-abi-additional-targets",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "node-abi": "3.96.0"
      }
    },
    "node_modules/node-abi": {
      "version": "3.96.0",
      "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.96.0.tgz",
      "integrity": "sha512-rebQ/lz7i0EkoLzUVSrKRzA69zMkwLp95kKMWoMDkkM00Suxz0D7zEQPwRml5fQum24mj7bPvmlgLAmu2JCiYg==",
      "license": "MIT",
      "dependencies": {
        "semver": "^7.3.5"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/semver": {
      "version": "7.8.5",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz",
      "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    }
  }
}
package.json
{
  "name": "sample-node-abi-additional-targets",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for node-abi.additionalTargets in node-abi@3.96.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "node-abi": "3.96.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify node-abi.additionalTargets in pkg:npm/node-abi@3.96.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-abi@3.96.0"
  ],
  "symbols": [
    "additionalTargets"
  ]
}
src/index.js
const nodeAbi = require('node-abi');

/**
 * Checks whether a given target version string and runtime is in additionalTargets.
 *
 * @param {string} target - Target version string (e.g. '0.13.0').
 * @param {string} [runtime='node-webkit'] - Target runtime (defaults to 'node-webkit').
 * @returns {boolean} True if in additionalTargets, false otherwise.
 */
function isAdditionalTarget(target, runtime = 'node-webkit') {
  const normalized = String(target).replace(/^v/, '');
  return nodeAbi.additionalTargets.some(
    (t) => t.runtime === runtime && t.target === normalized
  );
}

/**
 * Finds a target record in additionalTargets by version string or abi number.
 *
 * @param {string} versionOrAbi - Target version string or ABI number string.
 * @param {string} [runtime='node-webkit'] - Target runtime.
 * @returns {object|undefined} The matched target record, or undefined.
 */
function findAdditionalTarget(versionOrAbi, runtime = 'node-webkit') {
  const normalized = String(versionOrAbi).replace(/^v/, '');
  return nodeAbi.additionalTargets.find(
    (t) => t.runtime === runtime && (t.target === normalized || t.abi === normalized)
  );
}

/**
 * Resolves the ABI string for a node-webkit target version.
 *
 * @param {string} target - Target version string (e.g. '0.13.0').
 * @param {string} [runtime='node-webkit'] - Target runtime.
 * @returns {string} The ABI version string.
 */
function resolveAdditionalAbi(target, runtime = 'node-webkit') {
  return nodeAbi.getAbi(target, runtime);
}

/**
 * Resolves the target version for a node-webkit ABI string.
 *
 * @param {string} abi - ABI number string (e.g. '47').
 * @param {string} [runtime='node-webkit'] - Target runtime.
 * @returns {string} The target version string.
 */
function resolveAdditionalTarget(abi, runtime = 'node-webkit') {
  return nodeAbi.getTarget(abi, runtime);
}

module.exports = {
  nodeAbi,
  additionalTargets: nodeAbi.additionalTargets,
  allTargets: nodeAbi.allTargets,
  supportedTargets: nodeAbi.supportedTargets,
  deprecatedTargets: nodeAbi.deprecatedTargets,
  getAbi: nodeAbi.getAbi,
  getTarget: nodeAbi.getTarget,
  isAdditionalTarget,
  findAdditionalTarget,
  resolveAdditionalAbi,
  resolveAdditionalTarget
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  nodeAbi,
  additionalTargets,
  allTargets,
  supportedTargets,
  deprecatedTargets,
  getAbi,
  getTarget,
  isAdditionalTarget,
  findAdditionalTarget,
  resolveAdditionalAbi,
  resolveAdditionalTarget
} = require('../src/index.js');

async function runTests() {
  // 1. additionalTargets is exported as an array from node-abi containing node-webkit runtime targets
  assert.ok(Array.isArray(additionalTargets), 'additionalTargets must be an array');
  assert.ok(additionalTargets.length > 0, 'additionalTargets must not be empty');
  assert.equal(additionalTargets, nodeAbi.additionalTargets, 'exported additionalTargets must match node-abi');

  // 2. each target entry in additionalTargets has runtime, target, abi strings and lts set to false
  for (const entry of additionalTargets) {
    assert.equal(typeof entry.runtime, 'string', 'entry runtime must be a string');
    assert.equal(typeof entry.target, 'string', 'entry target must be a string');
    assert.equal(typeof entry.abi, 'string', 'entry abi must be a string');
    assert.equal(typeof entry.lts, 'boolean', 'entry lts must be boolean');
    assert.equal(entry.runtime, 'node-webkit', 'entry runtime must be node-webkit');
    assert.equal(entry.lts, false, 'entry lts must be false');
  }

  // 3. every target in additionalTargets is present in allTargets
  assert.ok(Array.isArray(allTargets), 'allTargets must be an array');
  for (const entry of additionalTargets) {
    assert.ok(allTargets.includes(entry), `allTargets must include additional target ${entry.target}`);
  }

  // 4. additionalTargets is disjoint from supportedTargets and deprecatedTargets
  assert.ok(Array.isArray(supportedTargets), 'supportedTargets must be an array');
  assert.ok(Array.isArray(deprecatedTargets), 'deprecatedTargets must be an array');
  for (const entry of additionalTargets) {
    assert.ok(!supportedTargets.includes(entry), `supportedTargets must not include additional target ${entry.target}`);
    assert.ok(!deprecatedTargets.includes(entry), `deprecatedTargets must not include additional target ${entry.target}`);
  }

  // 5. getAbi resolves node-webkit target versions to their corresponding abi strings
  assert.equal(resolveAdditionalAbi('0.13.0'), '47', '0.13.0 should resolve to abi 47');
  assert.equal(resolveAdditionalAbi('0.15.0'), '48', '0.15.0 should resolve to abi 48');
  assert.equal(resolveAdditionalAbi('0.18.3'), '51', '0.18.3 should resolve to abi 51');
  assert.equal(resolveAdditionalAbi('0.23.0'), '57', '0.23.0 should resolve to abi 57');
  assert.equal(resolveAdditionalAbi('0.26.5'), '59', '0.26.5 should resolve to abi 59');
  assert.equal(getAbi('0.13.0', 'node-webkit'), '47', 'getAbi direct call should match');

  // 6. getTarget resolves node-webkit abi strings to their corresponding target versions
  assert.equal(resolveAdditionalTarget('47'), '0.13.0', 'abi 47 should resolve to target 0.13.0');
  assert.equal(resolveAdditionalTarget('48'), '0.15.0', 'abi 48 should resolve to target 0.15.0');
  assert.equal(resolveAdditionalTarget('51'), '0.18.3', 'abi 51 should resolve to target 0.18.3');
  assert.equal(resolveAdditionalTarget('57'), '0.23.0', 'abi 57 should resolve to target 0.23.0');
  assert.equal(resolveAdditionalTarget('59'), '0.26.5', 'abi 59 should resolve to target 0.26.5');
  assert.equal(getTarget('47', 'node-webkit'), '0.13.0', 'getTarget direct call should match');

  // 7. getAbi and getTarget throw error when queried with unsupported node-webkit target or abi
  assert.throws(
    () => resolveAdditionalAbi('999.0.0'),
    /Could not detect abi for version 999\.0\.0 and runtime node-webkit/,
    'getAbi should throw on unsupported node-webkit version'
  );
  assert.throws(
    () => resolveAdditionalTarget('99999'),
    /Could not detect target for abi 99999 and runtime node-webkit/,
    'getTarget should throw on unsupported node-webkit abi'
  );

  // 8. isAdditionalTarget identifies whether a given runtime and target version is in additionalTargets
  assert.equal(isAdditionalTarget('0.13.0'), true, '0.13.0 should be an additional target');
  assert.equal(isAdditionalTarget('v0.13.0'), true, 'v0.13.0 should be an additional target');
  assert.equal(isAdditionalTarget('0.26.5'), true, '0.26.5 should be an additional target');
  assert.equal(isAdditionalTarget('99.0.0'), false, '99.0.0 should not be an additional target');
  assert.equal(isAdditionalTarget('0.13.0', 'node'), false, '0.13.0 node runtime should not be an additional target');

  // 9. findAdditionalTarget looks up node-webkit target records by target version or abi string
  const byTarget = findAdditionalTarget('0.13.0');
  assert.ok(byTarget, 'findAdditionalTarget should find entry by target');
  assert.equal(byTarget.abi, '47');
  assert.equal(byTarget.runtime, 'node-webkit');

  const byAbi = findAdditionalTarget('47');
  assert.ok(byAbi, 'findAdditionalTarget should find entry by abi');
  assert.equal(byAbi.target, '0.13.0');

  const notFound = findAdditionalTarget('unknown');
  assert.equal(notFound, undefined, 'findAdditionalTarget should return undefined when not found');

  console.log('All contract assertions for node-abi.additionalTargets passed successfully.');
}

runTests().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

オリジンシーダー

匿名