샘플
source-map 0.6.1: SourceMapGenerator
검증된 샘플 — npm source-map 0.6.1: SourceMapGenerator. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: SourceMapGenerator constructor creates an…
sha256:67dc4f809fcde2a0e6bdb76e782cca73df9b62095408462ac24d37b7df940974
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-23 |
| 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 source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1
- 패키지
- 심벌
-
- source-map.SourceMapGenerator
- 환경
- node 22.23.2
- 생성일
- 2026-08-23T13:40:32Z
컨트랙트
- SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot
- addMapping adds line and column mappings between generated code and original source positions
- setSourceContent embeds raw source file contents directly into the source map
- toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent
- toString serializes the source map object to a valid JSON string
- fromSourceMap static method creates a new SourceMapGenerator initialized from an existing SourceMapConsumer
파일
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
소스
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 source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/source-map@0.6.1
Demonstrate these symbols/APIs:
- source-map.SourceMapGenerator
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.
{"case":{"caseId":"case:sha256:75b652c08e35671e7e7ba274c632276bcf82a86e0b5ca076cbc11446b2bbbf95","constraints":{"executionContext":"node"},"contract":["SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot","addMapping adds line and column mappings between generated code and original source positions","setSourceContent embeds raw source file contents directly into the source map","toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent","toString serializes the source map object to a valid JSON string","fromSourceMap static method creates a new SourceMapGenerator initialized from an existing SourceMapConsumer"],"goal":"verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1","kind":"HOW","packages":["pkg:npm/source-map@0.6.1"],"schemaVersion":1,"symbols":["source-map.SourceMapGenerator"]},"contractCommand":["node","test/contract.cjs"],"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/source-map@0.6.1"],"schemaVersion":1,"subject":"pkg:npm/source-map@0.6.1","symbols":["source-map.SourceMapGenerator"],"verifierAdapter":"node-typescript@1"}
'use strict';
const { SourceMapGenerator, SourceMapConsumer } = require('source-map');
/**
* Creates a source map for generated code given mappings and source contents.
*
* @param {Object} options
* @param {string} [options.file] - The generated file name.
* @param {string} [options.sourceRoot] - The root URL/path for sources.
* @param {Array<Object>} mappings - List of mapping objects.
* @param {Object<string, string>} [sourcesContent] - Map of source filename to source text.
* @returns {SourceMapGenerator} The populated SourceMapGenerator instance.
*/
function createSourceMap(options, mappings, sourcesContent) {
const generator = new SourceMapGenerator(options);
if (Array.isArray(mappings)) {
for (const mapping of mappings) {
generator.addMapping(mapping);
}
}
if (sourcesContent && typeof sourcesContent === 'object') {
for (const [sourceFile, content] of Object.entries(sourcesContent)) {
generator.setSourceContent(sourceFile, content);
}
}
return generator;
}
/**
* Clones a source map using SourceMapGenerator.fromSourceMap.
*
* @param {SourceMapGenerator|Object} mapOrConsumer
* @returns {SourceMapGenerator}
*/
function cloneSourceMap(mapOrConsumer) {
if (typeof mapOrConsumer.toJSON === 'function') {
const consumer = new SourceMapConsumer(mapOrConsumer.toJSON());
return SourceMapGenerator.fromSourceMap(consumer);
}
return SourceMapGenerator.fromSourceMap(mapOrConsumer);
}
module.exports = {
SourceMapGenerator,
createSourceMap,
cloneSourceMap
};
{
"name": "sample-source-map-generator",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-source-map-generator",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"source-map": "0.6.1"
}
},
"node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
}
}
}
}
{
"name": "sample-source-map-generator",
"version": "1.0.0",
"private": true,
"description": "verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1",
"main": "index.js",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"source-map": "0.6.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1",
"kind": "HOW",
"packages": [
"pkg:npm/source-map@0.6.1"
],
"symbols": [
"source-map.SourceMapGenerator"
]
}
'use strict';
const assert = require('assert');
const { SourceMapGenerator, SourceMapConsumer } = require('source-map');
const { createSourceMap, cloneSourceMap } = require('../index.js');
async function runContractTests() {
// 1. SourceMapGenerator constructor creates an instance configured with optional file and sourceRoot
const generator = new SourceMapGenerator({
file: 'bundle.js',
sourceRoot: 'http://example.com/src/'
});
assert.ok(generator instanceof SourceMapGenerator, 'Must create an instance of SourceMapGenerator');
// 2. addMapping adds line and column mappings between generated code and original source positions
generator.addMapping({
generated: { line: 1, column: 0 },
original: { line: 10, column: 4 },
source: 'foo.js',
name: 'bar'
});
generator.addMapping({
generated: { line: 2, column: 0 },
original: { line: 20, column: 8 },
source: 'baz.js'
});
// 3. setSourceContent embeds raw source file contents directly into the source map
const fooContent = 'function bar() { return true; }';
const bazContent = 'const val = 123;';
generator.setSourceContent('foo.js', fooContent);
generator.setSourceContent('baz.js', bazContent);
// 4. toJSON produces a valid V3 source map object with version, file, sources, names, mappings, and sourcesContent
const jsonMap = generator.toJSON();
assert.strictEqual(jsonMap.version, 3, 'Source map version must be 3');
assert.strictEqual(jsonMap.file, 'bundle.js', 'File name must match option');
assert.strictEqual(jsonMap.sourceRoot, 'http://example.com/src/', 'sourceRoot must match option');
assert.deepStrictEqual(jsonMap.sources, ['foo.js', 'baz.js'], 'sources list must contain added sources');
assert.deepStrictEqual(jsonMap.names, ['bar'], 'names list must contain added names');
assert.deepStrictEqual(jsonMap.sourcesContent, [fooContent, bazContent], 'sourcesContent must contain embedded contents');
assert.ok(typeof jsonMap.mappings === 'string' && jsonMap.mappings.length > 0, 'mappings string must not be empty');
// 5. toString serializes the source map object to a valid JSON string
const stringified = generator.toString();
assert.strictEqual(typeof stringified, 'string', 'toString must return a string');
const parsed = JSON.parse(stringified);
assert.deepStrictEqual(parsed, jsonMap, 'Parsed toString output must match toJSON output');
// 6. Verify mapping resolution with SourceMapConsumer
const consumer = new SourceMapConsumer(jsonMap);
const pos1 = consumer.originalPositionFor({ line: 1, column: 0 });
assert.strictEqual(pos1.line, 10);
assert.strictEqual(pos1.column, 4);
assert.strictEqual(pos1.source, 'http://example.com/src/foo.js');
assert.strictEqual(pos1.name, 'bar');
const pos2 = consumer.originalPositionFor({ line: 2, column: 0 });
assert.strictEqual(pos2.line, 20);
assert.strictEqual(pos2.column, 8);
assert.strictEqual(pos2.source, 'http://example.com/src/baz.js');
assert.strictEqual(pos2.name, null);
// 7. fromSourceMap static method creates a new SourceMapGenerator initialized from an existing consumer
const clonedGen = SourceMapGenerator.fromSourceMap(consumer);
assert.ok(clonedGen instanceof SourceMapGenerator, 'fromSourceMap must return a SourceMapGenerator instance');
const clonedJson = clonedGen.toJSON();
assert.strictEqual(clonedJson.version, 3);
assert.strictEqual(clonedJson.file, 'bundle.js');
assert.deepStrictEqual(clonedJson.sources, ['foo.js', 'baz.js']);
assert.deepStrictEqual(clonedJson.names, ['bar']);
// 8. Test helper functions from index.js
const helperMap = createSourceMap(
{ file: 'app.min.js' },
[
{
generated: { line: 1, column: 0 },
original: { line: 1, column: 0 },
source: 'app.js'
}
],
{
'app.js': 'console.log("hello");'
}
);
assert.ok(helperMap instanceof SourceMapGenerator);
const helperJson = helperMap.toJSON();
assert.strictEqual(helperJson.file, 'app.min.js');
assert.deepStrictEqual(helperJson.sources, ['app.js']);
assert.deepStrictEqual(helperJson.sourcesContent, ['console.log("hello");']);
const clonedViaHelper = cloneSourceMap(helperMap);
assert.ok(clonedViaHelper instanceof SourceMapGenerator);
assert.strictEqual(clonedViaHelper.toJSON().file, 'app.min.js');
console.log('Contract tests passed successfully.');
}
runContractTests().catch((err) => {
console.error('Contract test failed:', err);
process.exit(1);
});
오리진 시더
익명