CodeSampleX

Пример

convert-source-map 1.9.0

Проверенный пример — npm convert-source-map 1.9.0. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: fromObject converts a source map…

sha256:3da0b0fb6d3493e7b5d2ecd2dcc0487399af4afe00f358d3189502ab22103033

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
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

Кейс

HOW
Цель
verify pkg:npm/convert-source-map@1.9.0
Пакеты
Окружение
node 22.23.2
Создан
2026-08-25T02:37:43Z

Контракт

  1. fromObject converts a source map object to a Converter with toComment and toJSON methods
  2. fromComment parses inline line and block sourceMappingURL comments into source map objects
  3. fromJSON and fromBase64 reconstruct source map converters from serialized formats
  4. fromSource extracts embedded inline source map from source code string
  5. removeComments strips inline source map comment annotations from source code
  6. setProperty and getProperty modify and inspect source map metadata properties

Файлы

  • 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 pkg:npm/convert-source-map@1.9.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/convert-source-map@1.9.0

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:d928a57238232f7f02686681914c9f0c7007076e6c2718c8c8718183192e4741","contract":["fromObject converts a source map object to a Converter with toComment and toJSON methods","fromComment parses inline line and block sourceMappingURL comments into source map objects","fromJSON and fromBase64 reconstruct source map converters from serialized formats","fromSource extracts embedded inline source map from source code string","removeComments strips inline source map comment annotations from source code","setProperty and getProperty modify and inspect source map metadata properties"],"goal":"verify pkg:npm/convert-source-map@1.9.0","kind":"HOW","packages":["pkg:npm/convert-source-map@1.9.0"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","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@1.9.0"],"schemaVersion":1,"subject":"pkg:npm/convert-source-map@1.9.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": "1.9.0"
      }
    },
    "node_modules/convert-source-map": {
      "version": "1.9.0",
      "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz",
      "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-convert-source-map",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of convert-source-map",
  "main": "src/index.js",
  "dependencies": {
    "convert-source-map": "1.9.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/convert-source-map@1.9.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/convert-source-map@1.9.0"
  ]
}
src/index.js
const convertSourceMap = require('convert-source-map');

/**
 * Generate an inline sourceMappingURL comment from a source map object.
 * @param {object} mapObject - Source map object.
 * @param {object} [options] - Generation options.
 * @param {boolean} [options.multiline=false] - Whether to generate a block comment.
 * @returns {string} Inline comment string.
 */
function createSourceMapComment(mapObject, options = {}) {
  const converter = convertSourceMap.fromObject(mapObject);
  return converter.toComment(options);
}

/**
 * Parse a source map object from an inline comment string.
 * @param {string} comment - Inline comment containing source map.
 * @returns {object|null} Parsed source map object, or null if invalid.
 */
function parseSourceMapFromComment(comment) {
  const converter = convertSourceMap.fromComment(comment);
  return converter ? converter.toObject() : null;
}

/**
 * Extract and parse an inline source map from a source code string.
 * @param {string} sourceCode - Source code containing inline source map.
 * @returns {object|null} Parsed source map object, or null if not found.
 */
function parseSourceMapFromSource(sourceCode) {
  const converter = convertSourceMap.fromSource(sourceCode);
  return converter ? converter.toObject() : null;
}

/**
 * Strip inline source map comments from source code.
 * @param {string} sourceCode - Source code containing inline source maps.
 * @returns {string} Source code without inline source map comments.
 */
function stripSourceMapComments(sourceCode) {
  return convertSourceMap.removeComments(sourceCode);
}

/**
 * Set a metadata property on a source map object.
 * @param {object} mapObject - Source map object.
 * @param {string} key - Property name.
 * @param {any} value - Property value.
 * @returns {object} Updated source map object.
 */
function modifySourceMapProperty(mapObject, key, value) {
  const converter = convertSourceMap.fromObject(mapObject);
  converter.setProperty(key, value);
  return converter.toObject();
}

module.exports = {
  convertSourceMap,
  createSourceMapComment,
  parseSourceMapFromComment,
  parseSourceMapFromSource,
  stripSourceMapComments,
  modifySourceMapProperty
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  convertSourceMap,
  createSourceMapComment,
  parseSourceMapFromComment,
  parseSourceMapFromSource,
  stripSourceMapComments,
  modifySourceMapProperty
} = require('../src/index.js');

// 1. Export verification
assert.strictEqual(typeof convertSourceMap, 'object', 'convertSourceMap should be exported');
assert.strictEqual(typeof convertSourceMap.fromObject, 'function', 'fromObject should be a function');
assert.strictEqual(typeof convertSourceMap.fromJSON, 'function', 'fromJSON should be a function');
assert.strictEqual(typeof convertSourceMap.fromBase64, 'function', 'fromBase64 should be a function');
assert.strictEqual(typeof convertSourceMap.fromComment, 'function', 'fromComment should be a function');
assert.strictEqual(typeof convertSourceMap.fromSource, 'function', 'fromSource should be a function');
assert.strictEqual(typeof convertSourceMap.removeComments, 'function', 'removeComments should be a function');
assert.strictEqual(typeof createSourceMapComment, 'function', 'createSourceMapComment should be a function');
assert.strictEqual(typeof parseSourceMapFromComment, 'function', 'parseSourceMapFromComment should be a function');
assert.strictEqual(typeof parseSourceMapFromSource, 'function', 'parseSourceMapFromSource should be a function');
assert.strictEqual(typeof stripSourceMapComments, 'function', 'stripSourceMapComments should be a function');
assert.strictEqual(typeof modifySourceMapProperty, 'function', 'modifySourceMapProperty should be a function');

// 2. fromObject converts a source map object to a Converter with toComment and toJSON methods
const sampleMap = {
  version: 3,
  file: 'output.js',
  sources: ['input.js'],
  mappings: 'AAAA;'
};
const conv = convertSourceMap.fromObject(sampleMap);
assert.deepStrictEqual(conv.toObject(), sampleMap);
assert.strictEqual(typeof conv.toJSON(), 'string');
assert.strictEqual(typeof conv.toBase64(), 'string');

const lineComment = conv.toComment();
assert.ok(lineComment.startsWith('//# sourceMappingURL=data:application/json;charset=utf-8;base64,'));
const blockComment = conv.toComment({ multiline: true });
assert.ok(blockComment.startsWith('/*# sourceMappingURL=data:application/json;charset=utf-8;base64,'));
assert.ok(blockComment.endsWith('*/'));

// 3. fromComment parses inline line and block sourceMappingURL comments into source map objects
const parsedLine = parseSourceMapFromComment(lineComment);
assert.deepStrictEqual(parsedLine, sampleMap);

const parsedBlock = parseSourceMapFromComment(blockComment);
assert.deepStrictEqual(parsedBlock, sampleMap);

// 4. fromJSON and fromBase64 reconstruct source map converters from serialized formats
const jsonString = JSON.stringify(sampleMap);
const fromJsonConv = convertSourceMap.fromJSON(jsonString);
assert.deepStrictEqual(fromJsonConv.toObject(), sampleMap);

const base64String = Buffer.from(jsonString).toString('base64');
const fromBase64Conv = convertSourceMap.fromBase64(base64String);
assert.deepStrictEqual(fromBase64Conv.toObject(), sampleMap);

// 5. fromSource extracts embedded inline source map from source code string
const sampleCode = 'function hello() { return 1; }\n' + lineComment;
const parsedFromCode = parseSourceMapFromSource(sampleCode);
assert.deepStrictEqual(parsedFromCode, sampleMap);

// 6. removeComments strips inline source map comment annotations from source code
const stripped = stripSourceMapComments(sampleCode);
assert.strictEqual(stripped, 'function hello() { return 1; }\n');
assert.strictEqual(convertSourceMap.fromSource(stripped), null);

// 7. setProperty and getProperty modify and inspect source map metadata properties
const updatedMap = modifySourceMapProperty(sampleMap, 'sourcesContent', ['function hello() {}']);
assert.deepStrictEqual(updatedMap.sourcesContent, ['function hello() {}']);
assert.strictEqual(updatedMap.version, 3);
assert.strictEqual(updatedMap.file, 'output.js');

console.log('Contract tests passed successfully.');

Исходный сидер

аноним