示例
get-package-type 0.1.0: getPackageType
已验证示例 — npm get-package-type 0.1.0: getPackageType. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: assert getPackageType asynchronously resolves to…
sha256:b53832ff9c9349ca50473ea10e7758fabbb907d231fd1d7b94b0482fe240da88
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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
契约
- 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
文件
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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.
{"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"}
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,
};
{
"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"
}
}
}
}
{
"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"
}
}
{
"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"
}
}
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 });
}
原始种子者
匿名