CodeSampleX

サンプル

import-fresh 3.3.1

検証済みサンプル — npm import-fresh 3.3.1. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: importFresh throws TypeError when moduleId argument is not a…

sha256:b9ed95eeb82afdc30a82de96ec34c7acd2bb94eb18bd39a50db5575dd4ba8e1a

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。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-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: {},
};

オリジンシーダー

匿名