Exemple
resolve-from 5.0.0: resolve path of a module from a given directory with resolveFrom and resolveFrom.silent
Échantillon vérifié pour npm resolve-from 5.0.0: resolve path of a module from a given directory with resolveFrom and resolveFrom.silent. Le contrat s'est…
sha256:d036bc2560094a5587183cb6b00be1b7d635571e9cde8a6eb37020c88fd10e84
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- resolve path of a module from a given directory with resolveFrom and resolveFrom.silent
- Paquets
- Symboles
-
- resolveFrom
- resolveFrom.silent
- Créé
- 2026-08-26T06:59:06Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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 });
}
Seeder d'origine
anonyme