CodeSampleX

샘플

get-package-type 0.1.0: getPackageType

검증된 샘플 — npm get-package-type 0.1.0: getPackageType. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert getPackageType asynchronously…

sha256:b53832ff9c9349ca50473ea10e7758fabbb907d231fd1d7b94b0482fe240da88

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
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-26
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-07

케이스

HOW
목표
verify getPackageType in pkg:npm/get-package-type@0.1.0
패키지
심벌
  • getPackageType
환경
node 22.23.2
생성일
2026-08-26T11:26:50Z

컨트랙트

  1. assert getPackageType asynchronously resolves to "module" for a file inside a package with type module
  2. assert getPackageType asynchronously resolves to "commonjs" for a file inside a package with type commonjs
  3. assert getPackageType asynchronously resolves to "commonjs" for a file inside a package without explicit type field
  4. assert getPackageType asynchronously resolves to "commonjs" when no package.json exists in directory hierarchy
  5. assert getPackageType asynchronously stops at node_modules boundary and returns "commonjs" ignoring parent type module
  6. assert getPackageType.sync synchronously returns "module" for a file inside a package with type module
  7. assert getPackageType.sync synchronously returns "commonjs" for a file inside a package with type commonjs
  8. assert getPackageType.sync synchronously returns "commonjs" for a file inside a package without explicit type field
  9. assert getPackageType.sync synchronously resolves nested module package inside node_modules
  10. assert getPackageType.sync synchronously returns "module" when searching from nested subdirectories up to package.json

파일

  • 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 getPackageType in pkg:npm/get-package-type@0.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/get-package-type@0.1.0
Demonstrate these symbols/APIs:
  - getPackageType
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:37bf7d2f49c9f7681512202ace01c658af3ec519f435e61d4e60b656129743d4","constraints":{"executionContext":"node"},"contract":["assert getPackageType asynchronously resolves to \"module\" for a file inside a package with type module","assert getPackageType asynchronously resolves to \"commonjs\" for a file inside a package with type commonjs","assert getPackageType asynchronously resolves to \"commonjs\" for a file inside a package without explicit type field","assert getPackageType asynchronously resolves to \"commonjs\" when no package.json exists in directory hierarchy","assert getPackageType asynchronously stops at node_modules boundary and returns \"commonjs\" ignoring parent type module","assert getPackageType.sync synchronously returns \"module\" for a file inside a package with type module","assert getPackageType.sync synchronously returns \"commonjs\" for a file inside a package with type commonjs","assert getPackageType.sync synchronously returns \"commonjs\" for a file inside a package without explicit type field","assert getPackageType.sync synchronously resolves nested module package inside node_modules","assert getPackageType.sync synchronously returns \"module\" when searching from nested subdirectories up to package.json"],"goal":"verify getPackageType in pkg:npm/get-package-type@0.1.0","kind":"HOW","packages":["pkg:npm/get-package-type@0.1.0"],"schemaVersion":1,"symbols":["getPackageType"]},"contractCommand":["node","test/contract.mjs"],"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/get-package-type@0.1.0"],"schemaVersion":1,"subject":"pkg:npm/get-package-type@0.1.0","symbols":["getPackageType"],"verifierAdapter":"node-typescript@1"}
index.js
const getPackageType = require('get-package-type');

/**
 * Determines package type asynchronously for a given file path.
 *
 * @param {string} filename - Path to file.
 * @returns {Promise<'commonjs' | 'module'>}
 */
async function resolvePackageType(filename) {
  return getPackageType(filename);
}

/**
 * Determines package type synchronously for a given file path.
 *
 * @param {string} filename - Path to file.
 * @returns {'commonjs' | 'module'}
 */
function resolvePackageTypeSync(filename) {
  return getPackageType.sync(filename);
}

module.exports = {
  getPackageType,
  resolvePackageType,
  resolvePackageTypeSync,
};
package-lock.json
{
  "name": "sample-get-package-type",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-get-package-type",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "get-package-type": "0.1.0"
      }
    },
    "node_modules/get-package-type": {
      "version": "0.1.0",
      "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz",
      "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-get-package-type",
  "version": "1.0.0",
  "description": "Clean-room sample verifying getPackageType in get-package-type",
  "main": "index.js",
  "license": "MIT-0",
  "dependencies": {
    "get-package-type": "0.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify getPackageType in pkg:npm/get-package-type@0.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/get-package-type@0.1.0"
  ],
  "symbols": [
    "getPackageType"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  getPackageType,
  resolvePackageType,
  resolvePackageTypeSync,
} = require('../index.js');

const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), 'gpt-contract-'));

try {
  const modulePkgDir = path.join(tmpBase, 'module-pkg');
  const cjsPkgDir = path.join(tmpBase, 'cjs-pkg');
  const defaultPkgDir = path.join(tmpBase, 'default-pkg');
  const nestedModuleSubdir = path.join(modulePkgDir, 'src', 'components');
  const bareNodeModulesDir = path.join(modulePkgDir, 'node_modules');
  const nestedDepInNodeModules = path.join(modulePkgDir, 'node_modules', 'esm-dep');
  const emptyDir = path.join(tmpBase, 'empty-dir');

  fs.mkdirSync(nestedModuleSubdir, { recursive: true });
  fs.mkdirSync(cjsPkgDir, { recursive: true });
  fs.mkdirSync(defaultPkgDir, { recursive: true });
  fs.mkdirSync(bareNodeModulesDir, { recursive: true });
  fs.mkdirSync(nestedDepInNodeModules, { recursive: true });
  fs.mkdirSync(emptyDir, { recursive: true });

  fs.writeFileSync(path.join(modulePkgDir, 'package.json'), JSON.stringify({ name: 'module-pkg', type: 'module' }), 'utf8');
  fs.writeFileSync(path.join(cjsPkgDir, 'package.json'), JSON.stringify({ name: 'cjs-pkg', type: 'commonjs' }), 'utf8');
  fs.writeFileSync(path.join(defaultPkgDir, 'package.json'), JSON.stringify({ name: 'default-pkg' }), 'utf8');
  fs.writeFileSync(path.join(nestedDepInNodeModules, 'package.json'), JSON.stringify({ name: 'esm-dep', type: 'module' }), 'utf8');

  const moduleFile = path.join(modulePkgDir, 'index.js');
  const nestedModuleFile = path.join(nestedModuleSubdir, 'widget.js');
  const cjsFile = path.join(cjsPkgDir, 'index.js');
  const defaultFile = path.join(defaultPkgDir, 'index.js');
  const bareNodeModulesFile = path.join(bareNodeModulesDir, 'direct.js');
  const esmDepFile = path.join(nestedDepInNodeModules, 'index.js');
  const emptyDirFile = path.join(emptyDir, 'standalone.js');

  fs.writeFileSync(moduleFile, '// module file', 'utf8');
  fs.writeFileSync(nestedModuleFile, '// nested module file', 'utf8');
  fs.writeFileSync(cjsFile, '// cjs file', 'utf8');
  fs.writeFileSync(defaultFile, '// default file', 'utf8');
  fs.writeFileSync(bareNodeModulesFile, '// direct inside node_modules', 'utf8');
  fs.writeFileSync(esmDepFile, '// esm dep file', 'utf8');
  fs.writeFileSync(emptyDirFile, '// standalone file', 'utf8');

  // Contract 1: assert getPackageType asynchronously resolves to "module" for a file inside a package with type module
  const res1 = await resolvePackageType(moduleFile);
  assert.strictEqual(res1, 'module', 'Expected "module" for package with type: module');

  // Contract 2: assert getPackageType asynchronously resolves to "commonjs" for a file inside a package with type commonjs
  const res2 = await resolvePackageType(cjsFile);
  assert.strictEqual(res2, 'commonjs', 'Expected "commonjs" for package with type: commonjs');

  // Contract 3: assert getPackageType asynchronously resolves to "commonjs" for a file inside a package without explicit type field
  const res3 = await resolvePackageType(defaultFile);
  assert.strictEqual(res3, 'commonjs', 'Expected "commonjs" for package without explicit type field');

  // Contract 4: assert getPackageType asynchronously resolves to "commonjs" when no package.json exists in directory hierarchy
  const res4 = await resolvePackageType(emptyDirFile);
  assert.strictEqual(res4, 'commonjs', 'Expected "commonjs" when no package.json is found');

  // Contract 5: assert getPackageType asynchronously stops at node_modules boundary and returns "commonjs" ignoring parent type module
  const res5 = await resolvePackageType(bareNodeModulesFile);
  assert.strictEqual(res5, 'commonjs', 'Expected "commonjs" for direct file in node_modules');

  // Contract 6: assert getPackageType.sync synchronously returns "module" for a file inside a package with type module
  const res6 = resolvePackageTypeSync(moduleFile);
  assert.strictEqual(res6, 'module', 'Expected sync "module" for package with type: module');

  // Contract 7: assert getPackageType.sync synchronously returns "commonjs" for a file inside a package with type commonjs
  const res7 = resolvePackageTypeSync(cjsFile);
  assert.strictEqual(res7, 'commonjs', 'Expected sync "commonjs" for package with type: commonjs');

  // Contract 8: assert getPackageType.sync synchronously returns "commonjs" for a file inside a package without explicit type field
  const res8 = resolvePackageTypeSync(defaultFile);
  assert.strictEqual(res8, 'commonjs', 'Expected sync "commonjs" for package without explicit type field');

  // Contract 9: assert getPackageType.sync synchronously resolves nested module package inside node_modules
  const res9 = resolvePackageTypeSync(esmDepFile);
  assert.strictEqual(res9, 'module', 'Expected sync "module" for module dependency inside node_modules');

  // Contract 10: assert getPackageType.sync synchronously returns "module" when searching from nested subdirectories up to package.json
  const res10 = resolvePackageTypeSync(nestedModuleFile);
  assert.strictEqual(res10, 'module', 'Expected sync "module" when traversed from nested subdirectory');

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

오리진 시더

익명