CodeSampleX

샘플

real-require 1.0.0: realImport

검증된 샘플 — npm real-require 1.0.0: realImport. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: realImport is exported as a callable function from…

sha256:9658e8538cebb3037499f2b00be62dce628572c412b530b082039f8d2d3021ed

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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-10-12

케이스

HOW
목표
verify real-require.realImport in pkg:npm/real-require@1.0.0
패키지
심벌
  • real-require.realImport
생성일
2026-10-12T09:16:38Z

컨트랙트

  1. realImport is exported as a callable function from real-require
  2. realImport returns a Promise resolving to the module namespace for built-in modules
  3. realImport dynamically imports installed packages by package name
  4. realImport dynamically imports local ES modules via file URL and exposes named and default exports
  5. realImport rejects with an error when attempting to import a nonexistent module
  6. dynamicImport helper wraps realImport to load modules dynamically
  7. importNamedExport helper retrieves a specific named export from a dynamically imported module

파일

  • PROMPT.md
  • csx.json
  • fixtures/helper.mjs
  • 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 real-require.realImport in pkg:npm/real-require@1.0.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/real-require@1.0.0
Demonstrate these symbols/APIs:
  - real-require.realImport

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:55094863593fc5ccd36c51f9b52421bd7d8e5d48bb013db35ea28c2a5b0e0359","contract":["realImport is exported as a callable function from real-require","realImport returns a Promise resolving to the module namespace for built-in modules","realImport dynamically imports installed packages by package name","realImport dynamically imports local ES modules via file URL and exposes named and default exports","realImport rejects with an error when attempting to import a nonexistent module","dynamicImport helper wraps realImport to load modules dynamically","importNamedExport helper retrieves a specific named export from a dynamically imported module"],"goal":"verify real-require.realImport in pkg:npm/real-require@1.0.0","kind":"HOW","packages":["pkg:npm/real-require@1.0.0"],"schemaVersion":1,"symbols":["real-require.realImport"]},"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/real-require@1.0.0"],"schemaVersion":1,"subject":"pkg:npm/real-require@1.0.0","symbols":["real-require.realImport"],"verifierAdapter":"node-typescript@1"}
fixtures/helper.mjs
export const greeting = 'hello from fixture';

export function calculateSum(a, b) {
  return a + b;
}

export default {
  type: 'fixture-module',
  active: true
};
package-lock.json
{
  "name": "sample-real-require",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-real-require",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "real-require": "1.0.0"
      }
    },
    "node_modules/real-require": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/real-require/-/real-require-1.0.0.tgz",
      "integrity": "sha512-P4nbQYQfePJxRSmY+v/KINxVucm4NF3p3s7pJveMTtom52FR4YGltUQLB8idDXwDDWW+eYrWDFbuzUnjoWHF7g==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-real-require",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for real-require@1.0.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "real-require": "1.0.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify real-require.realImport in pkg:npm/real-require@1.0.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/real-require@1.0.0"
  ],
  "symbols": [
    "real-require.realImport"
  ]
}
src/index.js
'use strict';

const { realImport, realRequire } = require('real-require');

/**
 * Dynamically imports a module by specifier or file URL using realImport.
 *
 * @param {string} specifier - Module specifier, path, or file URL.
 * @returns {Promise<any>} Module namespace object.
 */
async function dynamicImport(specifier) {
  return realImport(specifier);
}

/**
 * Dynamically imports a module and retrieves a specific named export.
 *
 * @param {string} specifier - Module specifier, path, or file URL.
 * @param {string} exportName - Name of the exported property to retrieve.
 * @returns {Promise<any>} The exported value.
 */
async function importNamedExport(specifier, exportName) {
  const moduleNamespace = await realImport(specifier);
  return moduleNamespace[exportName];
}

module.exports = {
  realImport,
  realRequire,
  dynamicImport,
  importNamedExport
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  realImport,
  realRequire,
  dynamicImport,
  importNamedExport
} = require('../src/index.js');

async function main() {
  // 1. realImport is exported as a callable function from real-require
  assert.equal(typeof realImport, 'function', 'realImport should be a function');
  assert.equal(typeof realRequire, 'function', 'realRequire should be a function');

  // 2. realImport returns a Promise resolving to the module namespace for built-in modules
  const pathModulePromise = realImport('node:path');
  assert(pathModulePromise instanceof Promise, 'realImport should return a Promise');
  const pathModule = await pathModulePromise;
  assert(pathModule !== null && typeof pathModule === 'object', 'Resolved module should be an object');
  assert.equal(typeof pathModule.join, 'function', 'pathModule should expose join function');
  assert.equal(pathModule.posix.join('foo', 'bar'), 'foo/bar', 'join should concatenate path segments');

  // 3. realImport dynamically imports installed packages by package name
  const selfPkg = await realImport('real-require');
  assert(selfPkg !== null && typeof selfPkg === 'object', 'Installed package should resolve to object');
  assert.equal(typeof selfPkg.realImport, 'function', 'Imported package should expose realImport');
  assert.equal(typeof selfPkg.realRequire, 'function', 'Imported package should expose realRequire');

  // 4. realImport dynamically imports local ES modules via file URL and exposes named and default exports
  const fixtureUrl = new URL('../fixtures/helper.mjs', import.meta.url).href;
  const fixture = await realImport(fixtureUrl);
  assert(fixture !== null && typeof fixture === 'object', 'Fixture module should resolve to namespace');
  assert.equal(fixture.greeting, 'hello from fixture', 'Named export greeting should match');
  assert.equal(typeof fixture.calculateSum, 'function', 'calculateSum should be a function');
  assert.equal(fixture.calculateSum(3, 4), 7, 'calculateSum(3, 4) should return 7');
  assert.equal(fixture.default.type, 'fixture-module', 'Default export type should match');
  assert.equal(fixture.default.active, true, 'Default export active should be true');

  // 5. realImport rejects with an error when attempting to import a nonexistent module
  await assert.rejects(
    async () => {
      await realImport('node:nonexistent_builtin_for_testing_purposes');
    },
    (err) => {
      assert(err instanceof Error, 'Rejected value should be an Error');
      assert(
        err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'ERR_UNKNOWN_BUILTIN_MODULE',
        `Unexpected error code: ${err.code}`
      );
      return true;
    }
  );

  // 6. dynamicImport helper wraps realImport to load modules dynamically
  const urlModule = await dynamicImport('node:url');
  assert(urlModule !== null && typeof urlModule === 'object', 'URL module should resolve');
  assert.equal(typeof urlModule.fileURLToPath, 'function', 'fileURLToPath should be a function');

  // 7. importNamedExport helper retrieves a specific named export from a dynamically imported module
  const joinFn = await importNamedExport('node:path', 'join');
  assert.equal(typeof joinFn, 'function', 'Retrieved named export join should be a function');
  const fixtureDefault = await importNamedExport(fixtureUrl, 'default');
  assert.equal(fixtureDefault.type, 'fixture-module', 'Retrieved default export property should match');

  console.log('All contract assertions passed successfully.');
}

main().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명