CodeSampleX

Sample

source-map-support 0.5.21: getErrorSource, install, mapSourcePosition

Verified sample for npm source-map-support 0.5.21: getErrorSource, install, mapSourcePosition. The contract ran on node 22 · linux alpine/x64 · docker and…

sha256:ad1adc8aa939fb00a7d99afb3707f432b10ad1b4a9cacd1ca2e04f7b2271f33b

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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-28

Case

HOW
Goal
verify pkg:npm/source-map-support@0.5.21
Packages
Symbols
  • source-map-support.getErrorSource
  • source-map-support.install
  • source-map-support.mapSourcePosition
Created
2026-08-28T04:53:48Z

Contract

  1. source-map-support.install configures stack trace remapping and supports custom retrieveSourceMap handlers
  2. source-map-support.mapSourcePosition maps compiled file positions to original source files and lines
  3. source-map-support.mapSourcePosition preserves unmapped positions when no source map is found
  4. source-map-support.getErrorSource extracts original source line and column caret from an Error with mapped stack
  5. source-map-support.getErrorSource returns null for errors without matchable stack frames

Files

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Download the source artifact (tar.gz)

Source

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/source-map-support@0.5.21
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/source-map-support@0.5.21
Demonstrate these symbols/APIs:
  - source-map-support.getErrorSource
  - source-map-support.install
  - source-map-support.mapSourcePosition

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:7979e13a724d2fa56bd732f79dec7751cdd097a8164ca2acaeeb507177457499","contract":["source-map-support.install configures stack trace remapping and supports custom retrieveSourceMap handlers","source-map-support.mapSourcePosition maps compiled file positions to original source files and lines","source-map-support.mapSourcePosition preserves unmapped positions when no source map is found","source-map-support.getErrorSource extracts original source line and column caret from an Error with mapped stack","source-map-support.getErrorSource returns null for errors without matchable stack frames"],"goal":"verify pkg:npm/source-map-support@0.5.21","kind":"HOW","packages":["pkg:npm/source-map-support@0.5.21"],"schemaVersion":1,"symbols":["source-map-support.getErrorSource","source-map-support.install","source-map-support.mapSourcePosition"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/source-map-support@0.5.21"],"schemaVersion":1,"subject":"pkg:npm/source-map-support@0.5.21","symbols":["source-map-support.getErrorSource","source-map-support.install","source-map-support.mapSourcePosition"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-source-map-support",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-support",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "source-map-support": "0.5.21"
      }
    },
    "node_modules/buffer-from": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
      "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
      "license": "MIT"
    },
    "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"
      }
    },
    "node_modules/source-map-support": {
      "version": "0.5.21",
      "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
      "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
      "license": "MIT",
      "dependencies": {
        "buffer-from": "^1.0.0",
        "source-map": "^0.6.0"
      }
    }
  }
}
package.json
{
  "name": "sample-source-map-support",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of source-map-support",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "source-map-support": "0.5.21"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/source-map-support@0.5.21",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map-support@0.5.21"
  ],
  "symbols": [
    "source-map-support.getErrorSource",
    "source-map-support.install",
    "source-map-support.mapSourcePosition"
  ]
}
src/index.js
const sourceMapSupport = require('source-map-support');

/**
 * Installs source map support into Node.js stack trace handling.
 * @param {object} [options]
 * @returns {void}
 */
function installSupport(options) {
  return sourceMapSupport.install(options);
}

/**
 * Maps a position in compiled code to the corresponding location in original source.
 * @param {string} source - Path or identifier of the compiled file
 * @param {number} line - 1-based line number in compiled code
 * @param {number} column - 0-based column number in compiled code
 * @returns {{ source: string, line: number, column: number, name: string | null }}
 */
function mapPosition(source, line, column) {
  return sourceMapSupport.mapSourcePosition({
    source,
    line,
    column,
  });
}

/**
 * Extracts the source code snippet and caret indicator for the top frame of an Error.
 * @param {Error} error - Error object with a stack trace
 * @returns {string | null}
 */
function getErrorSnippet(error) {
  return sourceMapSupport.getErrorSource(error);
}

/**
 * Resets custom source map retrieval handlers to default state.
 * @returns {void}
 */
function resetHandlers() {
  if (typeof sourceMapSupport.resetRetrieveHandlers === 'function') {
    sourceMapSupport.resetRetrieveHandlers();
  }
}

module.exports = {
  sourceMapSupport,
  installSupport,
  mapPosition,
  getErrorSnippet,
  resetHandlers,
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  sourceMapSupport,
  installSupport,
  mapPosition,
  getErrorSnippet,
  resetHandlers,
} = require('../src/index.js');

async function runContract() {
  // Sample source map payload for testing offline
  const sampleSourceMap = {
    version: 3,
    file: 'compiled-bundle.js',
    sources: ['src/original-module.ts'],
    sourcesContent: [
      'export function executeTask(value: number): number {\n  if (value < 0) throw new Error("negative value");\n  return value * 2;\n}\n'
    ],
    names: ['executeTask', 'value'],
    mappings: 'AAAA,gBAAsBA,YAAY,CAACC,KAAa;IAC9C,IAAIA,KAAK,GAAG,CAAC;MAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACjD,OAAOA,KAAK,GAAG,CAAC,CAAC;AACnB,CAAC'
  };

  // 1. source-map-support.install configures stack trace remapping and supports custom retrieveSourceMap handlers
  assert.strictEqual(typeof sourceMapSupport.install, 'function');
  assert.strictEqual(typeof installSupport, 'function');

  installSupport({
    emptyCacheBetweenOperations: true,
    handleUncaughtExceptions: false,
    environment: 'node',
    retrieveSourceMap(source) {
      if (source === 'compiled-bundle.js' || source.endsWith('/compiled-bundle.js')) {
        return {
          url: 'compiled-bundle.js',
          map: sampleSourceMap,
        };
      }
      return null;
    },
  });

  // 2. source-map-support.mapSourcePosition maps compiled file positions to original source files and lines
  assert.strictEqual(typeof sourceMapSupport.mapSourcePosition, 'function');
  assert.strictEqual(typeof mapPosition, 'function');

  const mapped = mapPosition('compiled-bundle.js', 1, 0);
  assert.strictEqual(typeof mapped, 'object');
  assert.ok(mapped !== null);
  assert.ok(
    mapped.source.endsWith('src/original-module.ts'),
    `Expected mapped source to resolve to original file, got ${mapped.source}`
  );
  assert.strictEqual(mapped.line, 1);
  assert.strictEqual(typeof mapped.column, 'number');

  // 3. source-map-support.mapSourcePosition preserves unmapped positions when no source map is found
  const unmapped = mapPosition('unknown-file.js', 42, 10);
  assert.strictEqual(unmapped.source, 'unknown-file.js');
  assert.strictEqual(unmapped.line, 42);
  assert.strictEqual(unmapped.column, 10);

  // 4. source-map-support.getErrorSource extracts original source line and column caret from an Error with mapped stack
  assert.strictEqual(typeof sourceMapSupport.getErrorSource, 'function');
  assert.strictEqual(typeof getErrorSnippet, 'function');

  const fnWithSourceURL = new Function(
    '//# sourceURL=compiled-bundle.js\nthrow new Error("task failed");'
  );
  let caughtError = null;
  try {
    fnWithSourceURL();
  } catch (err) {
    caughtError = err;
  }

  assert.ok(caughtError instanceof Error, 'Expected an error to be thrown and caught');
  assert.ok(
    caughtError.stack.includes('src/original-module.ts'),
    'Error stack trace must contain mapped original file path'
  );

  const snippet = getErrorSnippet(caughtError);
  assert.strictEqual(typeof snippet, 'string');
  assert.ok(snippet.includes('original-module.ts'), 'Snippet must mention the original source file');
  assert.ok(snippet.includes('^'), 'Snippet must include a caret column pointer');

  // 5. source-map-support.getErrorSource returns null for errors without matchable stack frames
  const plainError = new Error('unformatted error');
  plainError.stack = 'CustomError: unformatted error without callsite frame';
  const nullSnippet = getErrorSnippet(plainError);
  assert.strictEqual(nullSnippet, null);

  // Clean up
  resetHandlers();

  console.log('Contract assertions passed successfully.');
}

runContract().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

Origin Seeder

anonymous