CodeSampleX

サンプル

@ampproject/remapping 2.3.0: remapping

検証済みサンプル — npm @ampproject/remapping 2.3.0: remapping. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: remapping traces multi-step sourcemaps…

sha256:9031b43d33b5d2c15e4a8c4e8f3a9cdadf8170fee8b70be7f7f3635e3d34cf1b

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
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-28

ケース

HOW
ゴール
verify pkg:npm/%40ampproject/remapping@2.3.0
パッケージ
シンボル
  • remapping
環境
node 22.23.2
作成日
2026-08-28T03:24:04Z

コントラクト

  1. remapping traces multi-step sourcemaps back to original source files via loader callback
  2. remapping passes importer and depth context to loader callback
  3. remapping accepts an array of sequential transformations
  4. remapping accepts JSON string sourcemaps as input
  5. remapping decodedMappings option returns decoded segment arrays
  6. remapping excludeContent option omits sourcesContent from output
  7. remapping SourceMap toString method serializes valid JSON sourcemap

ファイル

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

ソースアーティファクトをダウンロード (tar.gz)

ソース

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
Demonstrate these symbols/APIs:
  - remapping

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:a4ee3836917cde161451a3661b37b63248baa00256a606c21e7f3c7d20f36120","contract":["remapping traces multi-step sourcemaps back to original source files via loader callback","remapping passes importer and depth context to loader callback","remapping accepts an array of sequential transformations","remapping accepts JSON string sourcemaps as input","remapping decodedMappings option returns decoded segment arrays","remapping excludeContent option omits sourcesContent from output","remapping SourceMap toString method serializes valid JSON sourcemap"],"goal":"verify pkg:npm/%40ampproject/remapping@2.3.0","kind":"HOW","packages":["pkg:npm/%40ampproject/remapping@2.3.0"],"schemaVersion":1,"symbols":["remapping"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","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,"subject":"pkg:npm/%40ampproject/remapping@2.3.0","symbols":["remapping"],"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.6.0",
      "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz",
      "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==",
      "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",
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "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"
  ],
  "symbols": [
    "remapping"
  ]
}
src/index.mjs
import remapping from '@ampproject/remapping';

/**
 * Compose chained transformations into a single source map.
 * @param {import('@ampproject/remapping').SourceMapInput | import('@ampproject/remapping').SourceMapInput[]} inputMap
 * @param {import('@ampproject/remapping').SourceMapLoader} loader
 * @param {import('@ampproject/remapping').Options} [options]
 * @returns {import('@ampproject/remapping').SourceMap}
 */
export function composeSourceMaps(inputMap, loader, options) {
  return remapping(inputMap, loader, options);
}

/**
 * Compose an array of sequential transformations (last to first).
 * @param {import('@ampproject/remapping').SourceMapInput[]} mapChain
 * @param {import('@ampproject/remapping').Options} [options]
 * @returns {import('@ampproject/remapping').SourceMap}
 */
export function composeMapArray(mapChain, options) {
  return remapping(mapChain, () => null, options);
}

export default remapping;
test/contract.mjs
import assert from 'node:assert';
import remapping, { composeSourceMaps, composeMapArray } from '../src/index.mjs';

function runContractTests() {
  const transpileMap = {
    version: 3,
    file: 'transpiled.js',
    sources: ['source.ts'],
    mappings: 'AAAA;',
    sourcesContent: ['export const greet = (name: string): string => `Hello, ${name}!`;']
  };

  const minifyMap = {
    version: 3,
    file: 'bundle.min.js',
    sources: ['transpiled.js'],
    mappings: 'AAAA;',
    sourcesContent: ['export const greet = name => `Hello, ${name}!`;']
  };

  // 1. Compose multi-step sourcemap using loader function
  const loaderCalls = [];
  const remappedViaLoader = remapping(minifyMap, (file, ctx) => {
    loaderCalls.push({ file, importer: ctx.importer, depth: ctx.depth });
    if (file === 'transpiled.js') {
      return transpileMap;
    }
    return null;
  });

  assert.strictEqual(remappedViaLoader.version, 3);
  assert.strictEqual(remappedViaLoader.file, 'bundle.min.js');
  assert.deepStrictEqual(remappedViaLoader.sources, ['source.ts']);
  assert.deepStrictEqual(
    remappedViaLoader.sourcesContent,
    ['export const greet = (name: string): string => `Hello, ${name}!`;']
  );
  assert.strictEqual(loaderCalls.length, 2);
  assert.strictEqual(loaderCalls[0].file, 'transpiled.js');
  assert.strictEqual(loaderCalls[0].importer, '');
  assert.strictEqual(loaderCalls[0].depth, 1);
  assert.strictEqual(loaderCalls[1].file, 'source.ts');
  assert.strictEqual(loaderCalls[1].importer, 'transpiled.js');
  assert.strictEqual(loaderCalls[1].depth, 2);

  // 2. Compose sequential transformations passing array input
  const remappedArray = composeMapArray([minifyMap, transpileMap]);
  assert.strictEqual(remappedArray.version, 3);
  assert.strictEqual(remappedArray.file, 'bundle.min.js');
  assert.deepStrictEqual(remappedArray.sources, ['source.ts']);
  assert.deepStrictEqual(
    remappedArray.sourcesContent,
    ['export const greet = (name: string): string => `Hello, ${name}!`;']
  );

  // 3. Compose using wrapper function
  const wrappedResult = composeSourceMaps(minifyMap, (file) => {
    return file === 'transpiled.js' ? transpileMap : null;
  });
  assert.deepStrictEqual(wrappedResult.sources, ['source.ts']);

  // 4. Accept JSON string input
  const jsonInputResult = remapping(JSON.stringify(minifyMap), (file) => {
    return file === 'transpiled.js' ? JSON.stringify(transpileMap) : null;
  });
  assert.deepStrictEqual(jsonInputResult.sources, ['source.ts']);

  // 5. decodedMappings option returns segment array
  const decodedResult = remapping(
    minifyMap,
    (file) => (file === 'transpiled.js' ? transpileMap : null),
    { decodedMappings: true }
  );
  assert(Array.isArray(decodedResult.mappings), 'mappings should be segment array');
  assert(Array.isArray(decodedResult.mappings[0]), 'mappings line should be segment array');

  // 6. excludeContent option strips sourcesContent
  const excludedResult = remapping(
    minifyMap,
    (file) => (file === 'transpiled.js' ? transpileMap : null),
    { excludeContent: true }
  );
  assert.strictEqual(excludedResult.sourcesContent, undefined);

  // 7. toString() returns valid serialized JSON sourcemap
  const serialized = remappedViaLoader.toString();
  const parsed = JSON.parse(serialized);
  assert.strictEqual(parsed.version, 3);
  assert.strictEqual(parsed.file, 'bundle.min.js');
  assert.deepStrictEqual(parsed.sources, ['source.ts']);

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

runContractTests();

オリジンシーダー

匿名