Exemple
source-map 0.6.1: SourceMapGenerator
Échantillon vérifié pour npm source-map 0.6.1: SourceMapGenerator. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:67dc4f809fcde2a0e6bdb76e782cca73df9b62095408462ac24d37b7df940974
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify source-map.SourceMapGenerator in pkg:npm/source-map@0.6.1
- Paquets
- Symboles
-
- source-map.SourceMapGenerator
- Environnement
- node 22.23.2
- Créé
- 2026-08-23T13:40:32Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.cjs
Code source
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);
});
Seeder d'origine
anonyme