CodeSampleX

Exemple

source-map-support 0.5.21: sourceMapSupport.install

Échantillon vérifié pour npm source-map-support 0.5.21: sourceMapSupport.install. Le contrat s'est exécuté sur node 22 · linux debian/x64 · docker et a…

sha256:538be996e4848ae80667e27ec77f4129821af67b64457af004c41cfb4c596ce3

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
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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-01

Cas

HOW
Objectif
verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21
Paquets
Symboles
  • sourceMapSupport.install
Créé
2026-09-01T11:51:22Z

Contrat

  1. sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping
  2. sourceMapSupport.install rewrites stack traces to map generated positions back to original source files
  3. sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps
  4. sourceMapSupport.install preserves standard stack trace structure when no source map is found

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code 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 sourceMapSupport.install in 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:
  - sourceMapSupport.install

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:5046590449b2dfd1c98ea3da01e34f5959b466640c9ac3098f2d932ae84d8491","contract":["sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping","sourceMapSupport.install rewrites stack traces to map generated positions back to original source files","sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps","sourceMapSupport.install preserves standard stack trace structure when no source map is found"],"goal":"verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21","kind":"HOW","packages":["pkg:npm/source-map-support@0.5.21"],"schemaVersion":1,"symbols":["sourceMapSupport.install"]},"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":["sourceMapSupport.install"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-source-map-support-install",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-source-map-support-install",
      "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-install",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of sourceMapSupport.install in source-map-support",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "license": "MIT-0",
  "dependencies": {
    "source-map-support": "0.5.21"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify sourceMapSupport.install in pkg:npm/source-map-support@0.5.21",
  "kind": "HOW",
  "packages": [
    "pkg:npm/source-map-support@0.5.21"
  ],
  "symbols": [
    "sourceMapSupport.install"
  ]
}
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 install(options) {
  return sourceMapSupport.install(options);
}

/**
 * Resets custom retrieve handlers to defaults if available.
 * @returns {void}
 */
function resetRetrieveHandlers() {
  if (typeof sourceMapSupport.resetRetrieveHandlers === "function") {
    sourceMapSupport.resetRetrieveHandlers();
  }
}

module.exports = {
  sourceMapSupport,
  install,
  resetRetrieveHandlers,
};
test/contract.mjs
import assert from "node:assert";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
const { sourceMapSupport, install, resetRetrieveHandlers } = require("../src/index.js");

async function runContract() {
  // 1. sourceMapSupport.install configures Error.prepareStackTrace for stack trace remapping
  assert.strictEqual(typeof sourceMapSupport.install, "function", "sourceMapSupport.install must be a function");
  assert.strictEqual(typeof install, "function", "install wrapper must be a function");

  let hookInvocations = 0;
  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"
  };

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

  assert.strictEqual(typeof Error.prepareStackTrace, "function", "Error.prepareStackTrace must be a function after install()");

  // 2. sourceMapSupport.install rewrites stack traces to map generated positions back to original source files
  const fnWithSourceURL = new Function(
    "//# sourceURL=compiled-bundle.js\nthrow new Error(\"error inside compiled bundle\");"
  );
  let caughtError = null;
  try {
    fnWithSourceURL();
  } catch (err) {
    caughtError = err;
  }

  assert.ok(caughtError instanceof Error, "Expected error to be thrown");
  assert.ok(
    caughtError.stack.includes("src/original-module.ts"),
    `Expected stack trace to contain mapped original file "src/original-module.ts", got:\n${caughtError.stack}`
  );

  // 3. sourceMapSupport.install supports custom retrieveSourceMap hook to resolve in-memory source maps
  assert.ok(hookInvocations > 0, "Expected custom retrieveSourceMap hook to be invoked when formatting stack trace");

  // 4. sourceMapSupport.install preserves standard stack trace structure when no source map is found
  const fnUnmapped = new Function(
    "//# sourceURL=unmapped-file.js\nthrow new Error(\"unmapped error message\");"
  );
  let unmappedErr = null;
  try {
    fnUnmapped();
  } catch (err) {
    unmappedErr = err;
  }
  assert.ok(unmappedErr instanceof Error, "Expected unmapped error");
  assert.ok(typeof unmappedErr.stack === "string", "Stack trace must be a string");
  assert.ok(unmappedErr.stack.includes("unmapped error message"), "Stack trace must contain original error message");
  assert.ok(unmappedErr.stack.includes("unmapped-file.js"), "Stack trace must contain unmapped source URL");

  resetRetrieveHandlers();
  console.log("Contract assertions passed successfully.");
}

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

Seeder d'origine

anonyme