CodeSampleX

Пример

import-fresh 3.3.1

Проверенный пример — npm import-fresh 3.3.1. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: importFresh throws TypeError when moduleId…

sha256:b9ed95eeb82afdc30a82de96ec34c7acd2bb94eb18bd39a50db5575dd4ba8e1a

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. 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-23

Кейс

HOW
Цель
verify pkg:npm/import-fresh@3.3.1
Пакеты
Создан
2026-08-23T14:08:52Z

Контракт

  1. importFresh throws TypeError when moduleId argument is not a string
  2. importFresh imports a module and returns its exported value
  3. importFresh returns a new module instance on each call bypassing require cache
  4. importFresh resolves relative module paths relative to the caller file directory in CommonJS
  5. importFresh loads fresh parsed objects for JSON files bypassing cache
  6. importFresh throws MODULE_NOT_FOUND error when the module cannot be resolved

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs
  • test/fixtures/data.json
  • test/fixtures/stateful.cjs
  • test/fixtures/sub/caller.cjs
  • test/fixtures/sub/target.cjs

Скачать артефакт с исходным кодом (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 pkg:npm/import-fresh@3.3.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/import-fresh@3.3.1

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:885649d8df8598de2c77ac3b0819456947b809ea10a9359ecd8f7cd395b135c8","contract":["importFresh throws TypeError when moduleId argument is not a string","importFresh imports a module and returns its exported value","importFresh returns a new module instance on each call bypassing require cache","importFresh resolves relative module paths relative to the caller file directory in CommonJS","importFresh loads fresh parsed objects for JSON files bypassing cache","importFresh throws MODULE_NOT_FOUND error when the module cannot be resolved"],"goal":"verify pkg:npm/import-fresh@3.3.1","kind":"HOW","packages":["pkg:npm/import-fresh@3.3.1"],"schemaVersion":1},"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/import-fresh@3.3.1"],"schemaVersion":1,"subject":"pkg:npm/import-fresh@3.3.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-import-fresh",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-import-fresh",
      "version": "1.0.0",
      "dependencies": {
        "import-fresh": "3.3.1"
      }
    },
    "node_modules/callsites": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
      "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/import-fresh": {
      "version": "3.3.1",
      "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz",
      "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==",
      "license": "MIT",
      "dependencies": {
        "parent-module": "^1.0.0",
        "resolve-from": "^4.0.0"
      },
      "engines": {
        "node": ">=6"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/parent-module": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
      "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==",
      "license": "MIT",
      "dependencies": {
        "callsites": "^3.0.0"
      },
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/resolve-from": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
      "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==",
      "license": "MIT",
      "engines": {
        "node": ">=4"
      }
    }
  }
}
package.json
{
  "name": "sample-import-fresh",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "import-fresh": "3.3.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/import-fresh@3.3.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/import-fresh@3.3.1"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import path from 'node:path';
import importFresh from 'import-fresh';

const require = createRequire(import.meta.url);
const { loadRelativeTarget } = require('./fixtures/sub/caller.cjs');

// 1. importFresh throws TypeError when moduleId argument is not a string
{
	assert.throws(
		() => {
			importFresh(12345);
		},
		{
			name: 'TypeError',
			message: 'Expected a string',
		}
	);
	assert.throws(
		() => {
			importFresh(null);
		},
		{
			name: 'TypeError',
			message: 'Expected a string',
		}
	);
	assert.throws(
		() => {
			importFresh(undefined);
		},
		{
			name: 'TypeError',
			message: 'Expected a string',
		}
	);
}

// 2. importFresh imports a module and returns its exported value
{
	const fixturePath = path.resolve('test/fixtures/stateful.cjs');
	const mod = importFresh(fixturePath);
	assert.ok(mod !== null && typeof mod === 'object');
	assert.equal(typeof mod.getExecutionCount, 'function');
	assert.equal(typeof mod.instanceId, 'object');
}

// 3. importFresh returns a new module instance on each call bypassing require cache
{
	const fixturePath = path.resolve('test/fixtures/stateful.cjs');
	const mod1 = importFresh(fixturePath);
	const mod2 = importFresh(fixturePath);

	assert.notEqual(mod1, mod2);
	assert.notEqual(mod1.instanceId, mod2.instanceId);
}

// 4. importFresh resolves relative module paths relative to the caller file directory in CommonJS
{
	const result1 = loadRelativeTarget();
	const result2 = loadRelativeTarget();

	assert.equal(result1.name, 'sub-target');
	assert.equal(result2.name, 'sub-target');
	assert.notEqual(result1.uniqueRef, result2.uniqueRef);
}

// 5. importFresh loads fresh parsed objects for JSON files bypassing cache
{
	const jsonPath = path.resolve('test/fixtures/data.json');
	const data1 = importFresh(jsonPath);
	const data2 = importFresh(jsonPath);

	assert.deepEqual(data1, {
		name: 'sample-data',
		version: 1,
		nested: {
			active: true,
		},
	});
	assert.notEqual(data1, data2);
	assert.notEqual(data1.nested, data2.nested);
}

// 6. importFresh throws MODULE_NOT_FOUND error when the module cannot be resolved
{
	assert.throws(
		() => {
			importFresh(path.resolve('test/fixtures/non-existent-module.cjs'));
		},
		(err) => {
			return err.code === 'MODULE_NOT_FOUND' || err.message.includes('Cannot find module');
		}
	);
}
test/fixtures/data.json
{
  "name": "sample-data",
  "version": 1,
  "nested": {
    "active": true
  }
}
test/fixtures/stateful.cjs
'use strict';

let executionCount = 0;
executionCount += 1;

module.exports = {
  instanceId: {},
  createdAt: Date.now(),
  getExecutionCount: () => executionCount,
};
test/fixtures/sub/caller.cjs
'use strict';
const importFresh = require('import-fresh');

module.exports = {
  loadRelativeTarget: function () {
    return importFresh('./target.cjs');
  },
};
test/fixtures/sub/target.cjs
'use strict';

module.exports = {
  name: 'sub-target',
  uniqueRef: {},
};

Исходный сидер

аноним