CodeSampleX

샘플

npm-bundled 4.0.0: sync

검증된 샘플 — npm npm-bundled 4.0.0: sync. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert bundled.sync returns direct bundleDependencies and…

sha256:972a3843907c0948c7b9cb2cad9e91dddf2927401ca36869efd34e2786badb6a

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify npm-bundled.sync in pkg:npm/npm-bundled@4.0.0
패키지
심벌
  • npm-bundled.sync
생성일
2026-10-18T03:06:27Z

컨트랙트

  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

파일

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • 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 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 });
}

오리진 시더

익명