CodeSampleX

Ejemplo

@ampproject/remapping 2.3.0

Muestra verificada para npm @ampproject/remapping 2.3.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:a5b8161b04e6d701c9d95717de416cc01ebc4df652a7daef4c633451993bffb5

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

Caso

HOW
Objetivo
verify pkg:npm/%40ampproject/remapping@2.3.0
Paquetes
Entorno
node 22.23.2
Creado
2026-08-20T14:44:43Z

Contrato

  1. remapping composes multi-step sourcemaps back to original source files
  2. remapping supports loader callback returning null for original source files
  3. remapping accepts JSON string as sourcemap input
  4. remapping supports decodedMappings option returning segment arrays
  5. remapping supports excludeContent option omitting sourcesContent
  6. remapping SourceMap toString returns valid JSON string

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/%40ampproject/remapping@2.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40ampproject/remapping@2.3.0
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:0184a4bfadedd85b2619f5944a31d7cb7c7ca63b9aed67198b62447e954c8c1e","constraints":{"executionContext":"node"},"contract":["remapping composes multi-step sourcemaps back to original source files","remapping supports loader callback returning null for original source files","remapping accepts JSON string as sourcemap input","remapping supports decodedMappings option returning segment arrays","remapping supports excludeContent option omitting sourcesContent","remapping SourceMap toString returns valid JSON string"],"goal":"verify pkg:npm/%40ampproject/remapping@2.3.0","kind":"HOW","packages":["pkg:npm/%40ampproject/remapping@2.3.0"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/%40ampproject/remapping@2.3.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ampproject-remapping",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ampproject-remapping",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@ampproject/remapping": "2.3.0"
      }
    },
    "node_modules/@ampproject/remapping": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
      "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==",
      "license": "Apache-2.0",
      "dependencies": {
        "@jridgewell/gen-mapping": "^0.3.5",
        "@jridgewell/trace-mapping": "^0.3.24"
      },
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@jridgewell/gen-mapping": {
      "version": "0.3.13",
      "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
      "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/sourcemap-codec": "^1.5.0",
        "@jridgewell/trace-mapping": "^0.3.24"
      }
    },
    "node_modules/@jridgewell/resolve-uri": {
      "version": "3.1.2",
      "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
      "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.0.0"
      }
    },
    "node_modules/@jridgewell/sourcemap-codec": {
      "version": "1.5.5",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
      "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
      "license": "MIT"
    },
    "node_modules/@jridgewell/trace-mapping": {
      "version": "0.3.31",
      "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
      "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
      "license": "MIT",
      "dependencies": {
        "@jridgewell/resolve-uri": "^3.1.0",
        "@jridgewell/sourcemap-codec": "^1.4.14"
      }
    }
  }
}
package.json
{
  "name": "sample-ampproject-remapping",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for @ampproject/remapping",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "@ampproject/remapping": "2.3.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40ampproject/remapping@2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40ampproject/remapping@2.3.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const remapping = require('@ampproject/remapping');

function remapSourcemap(inputMap, loader, options) {
  return remapping(inputMap, loader, options);
}

module.exports = {
  remapping,
  remapSourcemap
};
test/contract.js
'use strict';

const assert = require('node:assert');
const remapping = require('@ampproject/remapping');
const { remapSourcemap } = require('../src/index.js');

function runTests() {
  // 1. Compose multi-step sourcemaps back to original source file
  const minifiedMap = {
    version: 3,
    file: 'output.min.js',
    sources: ['transpiled.js'],
    mappings: 'AAAA;',
    sourcesContent: ['const answer = 42;']
  };

  const transpiledMap = {
    version: 3,
    file: 'transpiled.js',
    sources: ['source.ts'],
    mappings: 'AAAA;',
    sourcesContent: ['export const answer: number = 42;']
  };

  const remapped = remapping(minifiedMap, (sourcefile) => {
    if (sourcefile === 'transpiled.js') {
      return transpiledMap;
    }
    return null;
  });

  assert.strictEqual(remapped.version, 3, 'remapped version should be 3');
  assert.strictEqual(remapped.file, 'output.min.js', 'remapped file should match target');
  assert.deepStrictEqual(remapped.sources, ['source.ts'], 'remapped sources should point to original source file');
  assert.deepStrictEqual(
    remapped.sourcesContent,
    ['export const answer: number = 42;'],
    'remapped sourcesContent should match original source content'
  );

  // 2. remapSourcemap wrapper functionality
  const wrappedResult = remapSourcemap(minifiedMap, (sourcefile) => {
    if (sourcefile === 'transpiled.js') {
      return transpiledMap;
    }
    return null;
  });
  assert.deepStrictEqual(wrappedResult.sources, ['source.ts']);

  // 3. Loader callback returning null treated as original source file
  const singleStepMap = {
    version: 3,
    file: 'bundle.js',
    sources: ['root.js'],
    mappings: 'AAAA;',
    sourcesContent: ['console.log("hello");']
  };

  const singleRemapped = remapping(singleStepMap, () => null);
  assert.deepStrictEqual(singleRemapped.sources, ['root.js']);
  assert.deepStrictEqual(singleRemapped.sourcesContent, ['console.log("hello");']);

  // 4. Accept JSON string as sourcemap input
  const jsonInput = JSON.stringify(minifiedMap);
  const stringInputRemapped = remapping(jsonInput, (sourcefile) => {
    if (sourcefile === 'transpiled.js') {
      return transpiledMap;
    }
    return null;
  });
  assert.deepStrictEqual(stringInputRemapped.sources, ['source.ts']);

  // 5. decodedMappings option returning segment arrays
  const decodedResult = remapping(
    minifiedMap,
    (sourcefile) => (sourcefile === 'transpiled.js' ? transpiledMap : null),
    { decodedMappings: true }
  );
  assert(Array.isArray(decodedResult.mappings), 'mappings should be an array when decodedMappings is true');
  assert(Array.isArray(decodedResult.mappings[0]), 'first line mappings should be an array');

  // 6. excludeContent option omitting sourcesContent
  const excludedContentResult = remapping(
    minifiedMap,
    (sourcefile) => (sourcefile === 'transpiled.js' ? transpiledMap : null),
    { excludeContent: true }
  );
  assert.strictEqual(
    excludedContentResult.sourcesContent,
    undefined,
    'sourcesContent should be undefined when excludeContent is true'
  );

  // 7. toString() method returns valid JSON string
  const jsonString = remapped.toString();
  const parsed = JSON.parse(jsonString);
  assert.strictEqual(parsed.version, 3);
  assert.deepStrictEqual(parsed.sources, ['source.ts']);

  console.log('All @ampproject/remapping contract assertions passed.');
}

runTests();

Seeder de origen

anónimo