CodeSampleX

示例

convert-source-map 1.9.0

已验证示例 — npm convert-source-map 1.9.0. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: fromObject converts a source map object to a Converter with…

sha256:3da0b0fb6d3493e7b5d2ecd2dcc0487399af4afe00f358d3189502ab22103033

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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.');

原始种子者

匿名