CodeSampleX

サンプル

convert-source-map 2.0.0

検証済みサンプル — npm convert-source-map 2.0.0. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: fromObject converts a source map object and returns new…

sha256:31989c2b5ebccf8fb18d68c01a2306c7c4431e0c20bdf78759619331a3c340ff

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

実行証拠

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

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

検証実行環境

環境 コントラクト ステージ 実行日
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-25
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 pkg:npm/convert-source-map@2.0.0
パッケージ
環境
node 22.23.2
作成日
2026-08-25T02:34:41Z

コントラクト

  1. fromObject converts a source map object and returns new copy via toObject and JSON string via toJSON
  2. fromJSON parses a source map JSON string and allows modifying properties via getProperty, setProperty, and addProperty
  3. fromBase64 and toBase64 convert between base64-encoded strings and source map objects
  4. fromComment and toComment parse and format inline base64 and URI-encoded sourceMappingURL comments
  5. fromSource finds the last inline source map comment from source code or returns null if absent
  6. removeComments and removeMapFileComments strip inline data URIs and external map file comments from source text
  7. generateMapFileComment formats single-line and multi-line sourceMappingURL references to map files
  8. fromMapFileComment reads map file content using a custom reader function

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • 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 pkg:npm/convert-source-map@2.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/convert-source-map@2.0.0
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:ea77ca5ba5a7f7298fe4423f887787d9b1d65aa5a5dbe0bb6661db739e3d06e2","constraints":{"executionContext":"node"},"contract":["fromObject converts a source map object and returns new copy via toObject and JSON string via toJSON","fromJSON parses a source map JSON string and allows modifying properties via getProperty, setProperty, and addProperty","fromBase64 and toBase64 convert between base64-encoded strings and source map objects","fromComment and toComment parse and format inline base64 and URI-encoded sourceMappingURL comments","fromSource finds the last inline source map comment from source code or returns null if absent","removeComments and removeMapFileComments strip inline data URIs and external map file comments from source text","generateMapFileComment formats single-line and multi-line sourceMappingURL references to map files","fromMapFileComment reads map file content using a custom reader function"],"goal":"verify pkg:npm/convert-source-map@2.0.0","kind":"HOW","packages":["pkg:npm/convert-source-map@2.0.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/convert-source-map@2.0.0"],"schemaVersion":1,"subject":"pkg:npm/convert-source-map@2.0.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-convert-source-map",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-convert-source-map",
      "version": "1.0.0",
      "dependencies": {
        "convert-source-map": "2.0.0"
      }
    },
    "node_modules/convert-source-map": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
      "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-convert-source-map",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "convert-source-map": "2.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/convert-source-map@2.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/convert-source-map@2.0.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import convert from 'convert-source-map';

const rawMap = {
  version: 3,
  file: 'min.js',
  names: ['bar', 'baz'],
  sources: ['one.js', 'two.js'],
  sourceRoot: 'http://example.com/www/js/',
  mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,OAAU,GACrB',
};

// 1. fromObject converts a source map object and returns new copy via toObject and JSON string via toJSON
{
  const conv = convert.fromObject(rawMap);
  const obj = conv.toObject();
  assert.deepEqual(obj, rawMap);
  assert.notEqual(obj, rawMap);

  const jsonStr = conv.toJSON();
  assert.equal(typeof jsonStr, 'string');
  assert.deepEqual(JSON.parse(jsonStr), rawMap);
}

// 2. fromJSON parses a source map JSON string and allows modifying properties via getProperty, setProperty, and addProperty
{
  const json = JSON.stringify(rawMap);
  const conv = convert.fromJSON(json);
  assert.equal(conv.getProperty('file'), 'min.js');

  conv.setProperty('file', 'bundle.min.js');
  assert.equal(conv.getProperty('file'), 'bundle.min.js');

  conv.addProperty('x_custom', 'custom-value');
  assert.equal(conv.getProperty('x_custom'), 'custom-value');

  assert.throws(
    () => {
      conv.addProperty('file', 'other.js');
    },
    {
      name: 'Error',
      message: 'property "file" already exists on the sourcemap, use set property instead',
    }
  );
}

// 3. fromBase64 and toBase64 convert between base64-encoded strings and source map objects
{
  const conv = convert.fromObject(rawMap);
  const base64 = conv.toBase64();
  assert.equal(typeof base64, 'string');

  const parsed = convert.fromBase64(base64);
  assert.deepEqual(parsed.toObject(), rawMap);
}

// 4. fromComment and toComment parse and format inline base64 and URI-encoded sourceMappingURL comments
{
  const conv = convert.fromObject(rawMap);

  const singleLineComment = conv.toComment();
  assert.ok(singleLineComment.startsWith('//# sourceMappingURL=data:application/json;charset=utf-8;base64,'));
  const parsedFromSingle = convert.fromComment(singleLineComment);
  assert.deepEqual(parsedFromSingle.toObject(), rawMap);

  const multiLineComment = conv.toComment({ multiline: true });
  assert.ok(multiLineComment.startsWith('/*# sourceMappingURL=data:application/json;charset=utf-8;base64,'));
  assert.ok(multiLineComment.endsWith(' */'));
  const parsedFromMulti = convert.fromComment(multiLineComment);
  assert.deepEqual(parsedFromMulti.toObject(), rawMap);

  const uriComment = conv.toComment({ encoding: 'uri' });
  assert.ok(uriComment.startsWith('//# sourceMappingURL=data:application/json;charset=utf-8,'));
  const parsedFromUri = convert.fromComment(uriComment);
  assert.deepEqual(parsedFromUri.toObject(), rawMap);
}

// 5. fromSource finds the last inline source map comment from source code or returns null if absent
{
  const conv = convert.fromObject(rawMap);
  const comment = conv.toComment();
  const sourceCode = `function foo() { return 42; }\n${comment}`;

  const extracted = convert.fromSource(sourceCode);
  assert.ok(extracted);
  assert.deepEqual(extracted.toObject(), rawMap);

  const noCommentCode = 'function bar() { return 1; }';
  assert.equal(convert.fromSource(noCommentCode), null);
}

// 6. removeComments and removeMapFileComments strip inline data URIs and external map file comments from source text
{
  const inlineComment = convert.fromObject(rawMap).toComment();
  const codeWithInline = `console.log("hello");\n${inlineComment}\n`;
  const codeWithoutInline = convert.removeComments(codeWithInline);
  assert.equal(codeWithoutInline.trim(), 'console.log("hello");');

  const mapFileComment = convert.generateMapFileComment('bundle.js.map');
  const codeWithMapFile = `console.log("world");\n${mapFileComment}\n`;
  const codeWithoutMapFile = convert.removeMapFileComments(codeWithMapFile);
  assert.equal(codeWithoutMapFile.trim(), 'console.log("world");');
}

// 7. generateMapFileComment formats single-line and multi-line sourceMappingURL references to map files
{
  const single = convert.generateMapFileComment('app.min.js.map');
  assert.equal(single, '//# sourceMappingURL=app.min.js.map');

  const multi = convert.generateMapFileComment('app.min.js.map', { multiline: true });
  assert.equal(multi, '/*# sourceMappingURL=app.min.js.map */');
}

// 8. fromMapFileComment reads map file content using a custom reader function
{
  const comment = '//# sourceMappingURL=mapfile.json';
  const readFn = (filename) => {
    assert.equal(filename, 'mapfile.json');
    return JSON.stringify(rawMap);
  };

  const conv = convert.fromMapFileComment(comment, readFn);
  assert.deepEqual(conv.toObject(), rawMap);
}

オリジンシーダー

匿名