CodeSampleX

Пример

react-refresh 0.18.0: getFamilyByType

Проверенный пример — npm react-refresh 0.18.0: getFamilyByType. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:6b1bb9a000514f669de1bb4ee2f537c5ab1f9b35b0ba915e6959ba24b9e84c32

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

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-06

Кейс

HOW
Цель
verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0
Пакеты
Символы
  • react-refresh.getFamilyByType
Окружение
node 22.23.2
Создан
2026-09-06T12:50:03Z

Контракт

  1. getFamilyByType returns undefined for an unregistered component type
  2. getFamilyByType returns a family object containing current property for a registered component type
  3. getFamilyByType returns the identical family reference for an updated component type registered with the same id
  4. getFamilyByType returns distinct family references for component types registered with different ids
  5. getFamilyByType returns undefined when called with null, undefined, or primitive values

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

Скачать артефакт с исходным кодом (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 react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/react-refresh@0.18.0
Demonstrate these symbols/APIs:
  - react-refresh.getFamilyByType
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:5b2f7382431638c0037dac065233a63b74dda1a806d9a663a14a9fc2cac99501","constraints":{"executionContext":"node"},"contract":["getFamilyByType returns undefined for an unregistered component type","getFamilyByType returns a family object containing current property for a registered component type","getFamilyByType returns the identical family reference for an updated component type registered with the same id","getFamilyByType returns distinct family references for component types registered with different ids","getFamilyByType returns undefined when called with null, undefined, or primitive values"],"goal":"verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0","kind":"HOW","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"symbols":["react-refresh.getFamilyByType"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/react-refresh@0.18.0"],"schemaVersion":1,"subject":"pkg:npm/react-refresh@0.18.0","symbols":["react-refresh.getFamilyByType"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-react-refresh-get-family-by-type",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-react-refresh-get-family-by-type",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "react-refresh": "0.18.0"
      }
    },
    "node_modules/react-refresh": {
      "version": "0.18.0",
      "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.18.0.tgz",
      "integrity": "sha512-QgT5//D3jfjJb6Gsjxv0Slpj23ip+HtOpnNgnb2S5zU3CB26G/IDPGoy4RJB42wzFE46DRsstbW6tKHoKbhAxw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-react-refresh-get-family-by-type",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for react-refresh@0.18.0",
  "license": "MIT-0",
  "dependencies": {
    "react-refresh": "0.18.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify react-refresh.getFamilyByType in pkg:npm/react-refresh@0.18.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/react-refresh@0.18.0"
  ],
  "symbols": [
    "react-refresh.getFamilyByType"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
const refreshRuntimeModule = require("react-refresh/runtime");

const RefreshRuntime =
  refreshRuntimeModule && typeof refreshRuntimeModule === "object" && "default" in refreshRuntimeModule
    ? refreshRuntimeModule.default
    : refreshRuntimeModule;

/**
 * Returns the family object associated with a given component type, or undefined if not registered.
 *
 * @param {Function|object} type - The component function or object
 * @returns {object|undefined}
 */
function getFamilyByType(type) {
  return RefreshRuntime.getFamilyByType(type);
}

/**
 * Registers a component type with a persistent identifier for Fast Refresh.
 *
 * @param {Function|object} type - The component function or object
 * @param {string} id - Persistent identifier for the component family
 */
function register(type, id) {
  RefreshRuntime.register(type, id);
}

module.exports = {
  RefreshRuntime,
  getFamilyByType,
  register
};
test/contract.mjs
import assert from "node:assert/strict";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);
const rawRuntime = require("react-refresh/runtime");
const { RefreshRuntime, getFamilyByType, register } = require("../src/index.js");

// Contract 1: getFamilyByType returns undefined for an unregistered component type
{
  function UnregisteredComponent() {
    return "unregistered";
  }

  assert.equal(getFamilyByType(UnregisteredComponent), undefined);
  assert.equal(rawRuntime.getFamilyByType(UnregisteredComponent), undefined);
}

// Contract 2: getFamilyByType returns a family object containing current property for a registered component type
function ComponentA() {
  return "ComponentA";
}
{
  register(ComponentA, "ComponentA");

  const familyA = getFamilyByType(ComponentA);
  assert.notEqual(familyA, undefined);
  assert.equal(typeof familyA, "object");
  assert.equal(familyA.current, ComponentA);

  const rawFamilyA = rawRuntime.getFamilyByType(ComponentA);
  assert.equal(rawFamilyA, familyA);
}

// Contract 3: getFamilyByType returns the identical family reference for an updated component type registered with the same id
function ComponentA_v2() {
  return "ComponentA_v2";
}
{
  register(ComponentA_v2, "ComponentA");

  const familyA_v2 = getFamilyByType(ComponentA_v2);
  const familyA = getFamilyByType(ComponentA);

  assert.notEqual(familyA_v2, undefined);
  assert.equal(familyA_v2, familyA);
}

// Contract 4: getFamilyByType returns distinct family references for component types registered with different ids
function ComponentB() {
  return "ComponentB";
}
{
  register(ComponentB, "ComponentB");

  const familyB = getFamilyByType(ComponentB);
  const familyA = getFamilyByType(ComponentA);

  assert.notEqual(familyB, undefined);
  assert.notEqual(familyB, familyA);
  assert.equal(familyB.current, ComponentB);
}

// Contract 5: getFamilyByType returns undefined when called with null, undefined, or primitive values
{
  assert.equal(getFamilyByType(null), undefined);
  assert.equal(getFamilyByType(undefined), undefined);
  assert.equal(getFamilyByType(0), undefined);
  assert.equal(getFamilyByType(42), undefined);
  assert.equal(getFamilyByType(""), undefined);
  assert.equal(getFamilyByType("ComponentA"), undefined);
  assert.equal(getFamilyByType(true), undefined);
  assert.equal(getFamilyByType(Symbol("comp")), undefined);
}

console.log("All react-refresh.getFamilyByType contract tests passed successfully.");

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

аноним