Пример
tmp-promise 3.0.3: create and automatically cleanup temporary files and directories with tmp-promise
Проверенный пример — npm tmp-promise 3.0.3: create and automatically cleanup temporary files and directories with tmp-promise. Контракт выполнен на node 22 …
sha256:8c1f7f4fdf707865562dd01b6859afe3206a4f5b734e900c8fefc442077756b0
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
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-28 |
Кейс
HOW- Цель
- create and automatically cleanup temporary files and directories with tmp-promise
- Пакеты
- Символы
-
- tmp-promise.dir
- tmp-promise.file
- tmp-promise.withDir
- tmp-promise.withFile
- Создан
- 2026-08-28T05:09:04Z
Контракт
- file() resolves to { path, fd, cleanup } where cleanup removes the temporary file
- dir() resolves to { path, cleanup } where cleanup removes the temporary directory
- withFile(fn) provides { path, fd } to callback and automatically removes temporary file upon completion
- withDir(fn) provides { path } to callback and automatically removes temporary directory upon completion
Файлы
- PROMPT.md
- csx.json
- index.mjs
- 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: create and automatically cleanup temporary files and directories with tmp-promise
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/tmp-promise@3.0.3
Demonstrate these symbols/APIs:
- tmp-promise.dir
- tmp-promise.file
- tmp-promise.withDir
- tmp-promise.withFile
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:397f7b05b7fab591308bbe9f16aafef10f6e2df4005456a54e9b265f9921b29c","contract":["file() resolves to { path, fd, cleanup } where cleanup removes the temporary file","dir() resolves to { path, cleanup } where cleanup removes the temporary directory","withFile(fn) provides { path, fd } to callback and automatically removes temporary file upon completion","withDir(fn) provides { path } to callback and automatically removes temporary directory upon completion"],"goal":"create and automatically cleanup temporary files and directories with tmp-promise","kind":"HOW","packages":["pkg:npm/tmp-promise@3.0.3"],"schemaVersion":1,"symbols":["tmp-promise.dir","tmp-promise.file","tmp-promise.withDir","tmp-promise.withFile"]},"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/tmp-promise@3.0.3"],"schemaVersion":1,"subject":"pkg:npm/tmp-promise@3.0.3","symbols":["tmp-promise.dir","tmp-promise.file","tmp-promise.withDir","tmp-promise.withFile"],"verifierAdapter":"node-typescript@1"}
import fs from 'node:fs/promises';
import { file, dir, withFile, withDir } from 'tmp-promise';
export async function demonstrateFileCreation() {
const { path, fd, cleanup } = await file({ prefix: 'sample-', postfix: '.tmp' });
try {
await fs.writeFile(path, 'sample file content');
return path;
} finally {
await cleanup();
}
}
export async function demonstrateDirCreation() {
const { path, cleanup } = await dir({ prefix: 'sample-dir-', unsafeCleanup: true });
try {
return path;
} finally {
await cleanup();
}
}
export async function demonstrateWithFile() {
return await withFile(async ({ path }) => {
await fs.writeFile(path, 'scoped content');
return path;
});
}
export async function demonstrateWithDir() {
return await withDir(async ({ path }) => {
return path;
}, { unsafeCleanup: true });
}
{
"name": "sample-tmp-promise",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-tmp-promise",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"tmp-promise": "3.0.3"
}
},
"node_modules/tmp": {
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.7.tgz",
"integrity": "sha512-e0votIpp4Uo2AJYSzVHV6xCcawuiez3DzqDAbrTc3YxBkplN6e+dM13ZeIcZnDg/QpSuU2zfZ3rzwY8ukEnaXw==",
"license": "MIT",
"engines": {
"node": ">=14.14"
}
},
"node_modules/tmp-promise": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.3.tgz",
"integrity": "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==",
"license": "MIT",
"dependencies": {
"tmp": "^0.2.0"
}
}
}
}
{
"name": "sample-tmp-promise",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"tmp-promise": "3.0.3"
}
}
{
"schemaVersion": 1,
"goal": "create and automatically cleanup temporary files and directories with tmp-promise",
"kind": "HOW",
"packages": [
"pkg:npm/tmp-promise@3.0.3"
],
"symbols": [
"tmp-promise.dir",
"tmp-promise.file",
"tmp-promise.withDir",
"tmp-promise.withFile"
]
}
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { file, dir, withFile, withDir } from 'tmp-promise';
async function testFile() {
const o = await file({ prefix: 'test-file-', postfix: '.txt' });
assert.ok(typeof o.path === 'string' && o.path.length > 0, 'file() should return path string');
assert.ok(typeof o.fd === 'number', 'file() should return file descriptor');
assert.ok(typeof o.cleanup === 'function', 'file() should return cleanup function');
assert.ok(fs.existsSync(o.path), 'temporary file should exist on disk');
fs.writeSync(o.fd, Buffer.from('hello tmp file'));
await o.cleanup();
assert.strictEqual(fs.existsSync(o.path), false, 'cleanup() should remove temporary file');
}
async function testDir() {
const o = await dir({ prefix: 'test-dir-', unsafeCleanup: true });
assert.ok(typeof o.path === 'string' && o.path.length > 0, 'dir() should return path string');
assert.ok(typeof o.cleanup === 'function', 'dir() should return cleanup function');
assert.ok(fs.existsSync(o.path), 'temporary directory should exist on disk');
assert.ok(fs.statSync(o.path).isDirectory(), 'path should be a directory');
await o.cleanup();
assert.strictEqual(fs.existsSync(o.path), false, 'cleanup() should remove temporary directory');
}
async function testWithFile() {
let observedPath = '';
const result = await withFile(async ({ path, fd }) => {
observedPath = path;
assert.ok(typeof path === 'string' && path.length > 0, 'withFile should provide path');
assert.ok(typeof fd === 'number', 'withFile should provide file descriptor');
assert.ok(fs.existsSync(path), 'temporary file should exist inside withFile callback');
fs.writeSync(fd, Buffer.from('inside withFile'));
return 'file-done';
}, { prefix: 'with-file-' });
assert.strictEqual(result, 'file-done', 'withFile should return callback result');
assert.strictEqual(fs.existsSync(observedPath), false, 'withFile should automatically clean up file');
}
async function testWithDir() {
let observedPath = '';
const result = await withDir(async ({ path }) => {
observedPath = path;
assert.ok(typeof path === 'string' && path.length > 0, 'withDir should provide path');
assert.ok(fs.existsSync(path), 'temporary directory should exist inside withDir callback');
assert.ok(fs.statSync(path).isDirectory(), 'path should be a directory inside withDir callback');
return 'dir-done';
}, { prefix: 'with-dir-', unsafeCleanup: true });
assert.strictEqual(result, 'dir-done', 'withDir should return callback result');
assert.strictEqual(fs.existsSync(observedPath), false, 'withDir should automatically clean up directory');
}
async function run() {
await testFile();
await testDir();
await testWithFile();
await testWithDir();
console.log('Contract passed: all tmp-promise assertions verified');
}
run();
Исходный сидер
аноним