CodeSampleX

Ejemplo

npm-bundled 4.0.0: sync

Muestra verificada para npm npm-bundled 4.0.0: sync. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: assert bundled.sync returns direct…

sha256:972a3843907c0948c7b9cb2cad9e91dddf2927401ca36869efd34e2786badb6a

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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-10-18

Caso

HOW
Objetivo
verify npm-bundled.sync in pkg:npm/npm-bundled@4.0.0
Paquetes
Símbolos
  • npm-bundled.sync
Creado
2026-10-18T03:06:27Z

Contrato

  1. assert bundled.sync returns direct bundleDependencies and hoisted transitive dependencies while excluding unbundled and nested dependencies
  2. assert bundled.sync resolves scoped packages (@scope/pkg) in top-level node_modules
  3. assert bundled.sync bundles all dependencies and optionalDependencies when bundleDependencies is true and populates packageJsonCache
  4. assert bundled.sync returns an empty array when no bundleDependencies are configured or package.json is missing

Archivos

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

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 npm-bundled.sync in pkg:npm/npm-bundled@4.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/npm-bundled@4.0.0
Demonstrate these symbols/APIs:
  - npm-bundled.sync

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:c3ecdb49bc6a2f582810d359093592a7e99182d7cbcc57bfd0e82237fe2dca14","contract":["assert bundled.sync returns direct bundleDependencies and hoisted transitive dependencies while excluding unbundled and nested dependencies","assert bundled.sync resolves scoped packages (@scope/pkg) in top-level node_modules","assert bundled.sync bundles all dependencies and optionalDependencies when bundleDependencies is true and populates packageJsonCache","assert bundled.sync returns an empty array when no bundleDependencies are configured or package.json is missing"],"goal":"verify npm-bundled.sync in pkg:npm/npm-bundled@4.0.0","kind":"HOW","packages":["pkg:npm/npm-bundled@4.0.0"],"schemaVersion":1,"symbols":["npm-bundled.sync"]},"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/npm-bundled@4.0.0"],"schemaVersion":1,"subject":"pkg:npm/npm-bundled@4.0.0","symbols":["npm-bundled.sync"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const bundled = require('npm-bundled');

/**
 * Synchronously lists top-level node_modules packages that are bundledDependencies
 * or hoisted transitive dependencies of bundledDependencies.
 *
 * @param {string} pkgPath - Directory path of the target package.
 * @param {Map<string, object>} [packageJsonCache] - Optional cache map for parsed package.json objects.
 * @returns {string[]} List of bundled top-level dependency names.
 */
function listBundledSync(pkgPath, packageJsonCache) {
  const options = { path: pkgPath };
  if (packageJsonCache) {
    options.packageJsonCache = packageJsonCache;
  }
  return bundled.sync(options);
}

module.exports = {
  listBundledSync,
  bundled,
};
package-lock.json
{
  "name": "sample-npm-bundled-sync",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-npm-bundled-sync",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "npm-bundled": "4.0.0"
      }
    },
    "node_modules/npm-bundled": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-4.0.0.tgz",
      "integrity": "sha512-IxaQZDMsqfQ2Lz37VvyyEtKLe8FsRZuysmedy/N06TU1RyVppYKXrO4xIhR0F+7ubIBox6Q7nir6fQI3ej39iA==",
      "license": "ISC",
      "dependencies": {
        "npm-normalize-package-bin": "^4.0.0"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/npm-normalize-package-bin": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-4.0.0.tgz",
      "integrity": "sha512-TZKxPvItzai9kN9H/TkmCtx/ZN/hvr3vUycjlfmH0ootY9yFBzNOpiXAdIn1Iteqsvk4lQn6B5PTrt+n6h8k/w==",
      "license": "ISC",
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    }
  }
}
package.json
{
  "name": "sample-npm-bundled-sync",
  "version": "1.0.0",
  "description": "Clean-room sample verifying npm-bundled.sync functionality",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "license": "MIT-0",
  "dependencies": {
    "npm-bundled": "4.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify npm-bundled.sync in pkg:npm/npm-bundled@4.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/npm-bundled@4.0.0"
  ],
  "symbols": [
    "npm-bundled.sync"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import bundled from 'npm-bundled';
import { listBundledSync } from '../index.js';

function writePkg(dir, pkgJson) {
  fs.mkdirSync(dir, { recursive: true });
  fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkgJson, null, 2));
}

const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'npm-bundled-test-'));

try {
  // 1. Direct bundleDependencies & hoisted transitive dependencies
  const proj1 = path.join(tmpRoot, 'proj1');
  writePkg(proj1, {
    name: 'root-pkg',
    version: '1.0.0',
    dependencies: {
      'bundled-a': '1.0.0',
      'unbundled-b': '1.0.0',
    },
    bundleDependencies: ['bundled-a'],
  });

  // bundled-a depends on hoisted-trans-c and nested-trans-d, plus optional hoisted-opt-e
  writePkg(path.join(proj1, 'node_modules', 'bundled-a'), {
    name: 'bundled-a',
    version: '1.0.0',
    dependencies: {
      'hoisted-trans-c': '1.0.0',
      'nested-trans-d': '1.0.0',
    },
    optionalDependencies: {
      'hoisted-opt-e': '1.0.0',
    },
  });

  // nested-trans-d is inside bundled-a/node_modules (should NOT appear in top-level list)
  writePkg(path.join(proj1, 'node_modules', 'bundled-a', 'node_modules', 'nested-trans-d'), {
    name: 'nested-trans-d',
    version: '1.0.0',
  });

  // hoisted-trans-c and hoisted-opt-e are hoisted to top-level node_modules
  writePkg(path.join(proj1, 'node_modules', 'hoisted-trans-c'), {
    name: 'hoisted-trans-c',
    version: '1.0.0',
  });
  writePkg(path.join(proj1, 'node_modules', 'hoisted-opt-e'), {
    name: 'hoisted-opt-e',
    version: '1.0.0',
  });

  // unbundled-b is in top-level node_modules but not bundled
  writePkg(path.join(proj1, 'node_modules', 'unbundled-b'), {
    name: 'unbundled-b',
    version: '1.0.0',
  });

  const list1 = listBundledSync(proj1);
  assert(Array.isArray(list1), 'bundled.sync must return an array');
  assert.deepStrictEqual(
    list1.slice().sort(),
    ['bundled-a', 'hoisted-opt-e', 'hoisted-trans-c'],
    'bundled.sync must include direct bundled deps and hoisted transitive deps, excluding unbundled and nested deps'
  );

  // 2. Scoped packages (@scope/pkg) as bundled and transitive dependencies
  const proj2 = path.join(tmpRoot, 'proj2');
  writePkg(proj2, {
    name: 'scoped-root',
    version: '1.0.0',
    bundledDependencies: ['@scope/alpha'],
  });
  writePkg(path.join(proj2, 'node_modules', '@scope', 'alpha'), {
    name: '@scope/alpha',
    version: '1.0.0',
    dependencies: {
      '@scope/beta': '1.0.0',
    },
  });
  writePkg(path.join(proj2, 'node_modules', '@scope', 'beta'), {
    name: '@scope/beta',
    version: '1.0.0',
  });

  const list2 = bundled.sync({ path: proj2 });
  assert.deepStrictEqual(
    list2.slice().sort(),
    ['@scope/alpha', '@scope/beta'],
    'bundled.sync must resolve scoped packages (@scope/pkg) in top-level node_modules'
  );

  // 3. bundleDependencies: true bundles all dependencies and optionalDependencies, and populates packageJsonCache
  const proj3 = path.join(tmpRoot, 'proj3');
  writePkg(proj3, {
    name: 'bundle-all-root',
    version: '1.0.0',
    dependencies: { 'dep-one': '1.0.0' },
    optionalDependencies: { 'dep-two': '1.0.0' },
    bundleDependencies: true,
  });
  writePkg(path.join(proj3, 'node_modules', 'dep-one'), {
    name: 'dep-one',
    version: '1.0.0',
  });
  writePkg(path.join(proj3, 'node_modules', 'dep-two'), {
    name: 'dep-two',
    version: '1.0.0',
  });

  const cache = new Map();
  const list3 = listBundledSync(proj3, cache);
  assert.deepStrictEqual(
    list3.slice().sort(),
    ['dep-one', 'dep-two'],
    'bundled.sync must bundle all dependencies and optionalDependencies when bundleDependencies is true'
  );
  assert(
    cache.has(path.resolve(proj3, 'package.json')),
    'bundled.sync must populate packageJsonCache with parsed package.json entries'
  );

  // 4. Package with no bundledDependencies or missing package.json returns empty array
  const proj4 = path.join(tmpRoot, 'proj4');
  writePkg(proj4, {
    name: 'no-bundled-root',
    version: '1.0.0',
    dependencies: { 'dep-one': '1.0.0' },
  });
  assert.deepStrictEqual(
    bundled.sync({ path: proj4 }),
    [],
    'bundled.sync must return empty array when no bundleDependencies are configured'
  );
  assert.deepStrictEqual(
    bundled.sync({ path: path.join(tmpRoot, 'nonexistent') }),
    [],
    'bundled.sync must return empty array when package.json does not exist'
  );

  console.log('All contract assertions passed.');
} finally {
  fs.rmSync(tmpRoot, { recursive: true, force: true });
}

Seeder de origen

anónimo