サンプル
resolve-from 5.0.0: resolve path of a module from a given directory with resolveFrom and resolveFrom.silent
検証済みサンプル — npm resolve-from 5.0.0: resolve path of a module from a given directory with resolveFrom and resolveFrom.silent. node 22 · linux alpine/x64 …
sha256:d036bc2560094a5587183cb6b00be1b7d635571e9cde8a6eb37020c88fd10e84
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 npm
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- resolve path of a module from a given directory with resolveFrom and resolveFrom.silent
- パッケージ
- シンボル
-
- resolveFrom
- resolveFrom.silent
- 作成日
- 2026-08-26T06:59:06Z
コントラクト
- resolveFrom resolves an existing relative module from a given directory to its absolute path
- resolveFrom resolves a package located in node_modules from a given directory
- resolveFrom throws an error with MODULE_NOT_FOUND code when the target module cannot be resolved
- resolveFrom.silent resolves an existing module from a given directory returning the absolute path
- resolveFrom.silent returns undefined when the target module cannot be resolved without throwing
ファイル
- 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: resolve path of a module from a given directory with resolveFrom and resolveFrom.silent
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/resolve-from@5.0.0
Demonstrate these symbols/APIs:
- resolveFrom
- resolveFrom.silent
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:e8a689bbe93b4d0afc4d4b25e1ab110dad0c5ad01a6903ae6c947bbb1079f519","contract":["resolveFrom resolves an existing relative module from a given directory to its absolute path","resolveFrom resolves a package located in node_modules from a given directory","resolveFrom throws an error with MODULE_NOT_FOUND code when the target module cannot be resolved","resolveFrom.silent resolves an existing module from a given directory returning the absolute path","resolveFrom.silent returns undefined when the target module cannot be resolved without throwing"],"goal":"resolve path of a module from a given directory with resolveFrom and resolveFrom.silent","kind":"HOW","packages":["pkg:npm/resolve-from@5.0.0"],"schemaVersion":1,"symbols":["resolveFrom","resolveFrom.silent"]},"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/resolve-from@5.0.0"],"schemaVersion":1,"subject":"pkg:npm/resolve-from@5.0.0","symbols":["resolveFrom","resolveFrom.silent"],"verifierAdapter":"node-typescript@1"}
const resolveFrom = require('resolve-from');
/**
* Resolves the path of a module relative to a given directory.
* Throws if the module cannot be resolved.
*
* @param {string} fromDirectory - Directory to resolve relative to.
* @param {string} moduleId - Target module ID or relative file path.
* @returns {string} The resolved absolute file path.
*/
function resolveModuleFrom(fromDirectory, moduleId) {
return resolveFrom(fromDirectory, moduleId);
}
/**
* Resolves the path of a module relative to a given directory silently.
* Returns undefined instead of throwing if the module cannot be resolved.
*
* @param {string} fromDirectory - Directory to resolve relative to.
* @param {string} moduleId - Target module ID or relative file path.
* @returns {string | undefined} The resolved absolute file path, or undefined.
*/
function resolveModuleFromSilent(fromDirectory, moduleId) {
return resolveFrom.silent(fromDirectory, moduleId);
}
module.exports = {
resolveModuleFrom,
resolveModuleFromSilent,
resolveFrom,
};
{
"name": "sample-resolve-from",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-resolve-from",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"resolve-from": "5.0.0"
}
},
"node_modules/resolve-from": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
"license": "MIT",
"engines": {
"node": ">=8"
}
}
}
}
{
"name": "sample-resolve-from",
"version": "1.0.0",
"description": "Clean-room sample demonstrating resolve-from module resolution",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"resolve-from": "5.0.0"
}
}
{
"schemaVersion": 1,
"goal": "resolve path of a module from a given directory with resolveFrom and resolveFrom.silent",
"kind": "HOW",
"packages": [
"pkg:npm/resolve-from@5.0.0"
],
"symbols": [
"resolveFrom",
"resolveFrom.silent"
]
}
import assert from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import resolveFrom from 'resolve-from';
import { resolveModuleFrom, resolveModuleFromSilent } from '../index.js';
// Setup temporary directory structure for offline testing
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'resolve-from-contract-'));
const fixturesDir = path.join(tmpDir, 'fixtures');
const subDir = path.join(fixturesDir, 'sub');
const nestedModulesDir = path.join(subDir, 'node_modules', 'dummy-pkg');
fs.mkdirSync(nestedModulesDir, { recursive: true });
// Create a fixture file
const helperFile = path.join(fixturesDir, 'helper.js');
fs.writeFileSync(helperFile, 'module.exports = { name: "helper" };', 'utf8');
// Create a package in subDir's node_modules
const dummyPkgEntry = path.join(nestedModulesDir, 'index.js');
const dummyPkgJson = path.join(nestedModulesDir, 'package.json');
fs.writeFileSync(dummyPkgJson, JSON.stringify({ name: 'dummy-pkg', main: 'index.js' }), 'utf8');
fs.writeFileSync(dummyPkgEntry, 'module.exports = "dummy";', 'utf8');
try {
// 1. resolveFrom resolves an existing relative module from a directory
const resolvedHelperDirect = resolveFrom(fixturesDir, './helper');
assert.strictEqual(resolvedHelperDirect, helperFile, 'resolveFrom must resolve relative path to absolute file path');
const resolvedHelperWrapper = resolveModuleFrom(fixturesDir, './helper.js');
assert.strictEqual(resolvedHelperWrapper, helperFile, 'resolveModuleFrom must resolve relative file path');
// 2. resolveFrom resolves a package located in node_modules from a directory
const resolvedPkg = resolveFrom(subDir, 'dummy-pkg');
assert.strictEqual(resolvedPkg, dummyPkgEntry, 'resolveFrom must resolve package entry from node_modules');
// 3. resolveFrom throws an error with MODULE_NOT_FOUND code for non-existent module
assert.throws(
() => resolveFrom(fixturesDir, './non-existent-module'),
(err) => {
assert.strictEqual(err.code, 'MODULE_NOT_FOUND');
assert.match(err.message, /Cannot find module/);
return true;
},
'resolveFrom must throw error with code MODULE_NOT_FOUND when module is missing'
);
// 4. resolveFrom.silent resolves an existing module and returns the path
const resolvedSilentDirect = resolveFrom.silent(fixturesDir, './helper');
assert.strictEqual(resolvedSilentDirect, helperFile, 'resolveFrom.silent must return path for existing module');
const resolvedSilentWrapper = resolveModuleFromSilent(subDir, 'dummy-pkg');
assert.strictEqual(resolvedSilentWrapper, dummyPkgEntry, 'resolveModuleFromSilent must return path for package');
// 5. resolveFrom.silent returns undefined for non-existent module without throwing
const nonExistentSilent = resolveFrom.silent(fixturesDir, './non-existent-module');
assert.strictEqual(nonExistentSilent, undefined, 'resolveFrom.silent must return undefined for non-existent module');
const nonExistentSilentWrapper = resolveModuleFromSilent(fixturesDir, 'unknown-pkg');
assert.strictEqual(nonExistentSilentWrapper, undefined, 'resolveModuleFromSilent must return undefined for unknown package');
console.log('All resolve-from contract assertions passed.');
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
オリジンシーダー
匿名