CodeSampleX

Пример

import-local 3.2.0: importLocal

Проверенный пример — npm import-local 3.2.0: importLocal. Контракт выполнен на node 22 · linux alpine/x64 · docker и пройден: importLocal is exported as a…

sha256:5e86ad77451266da99a77f1114ae0225a3406647ba9d9dd57101847849fbd38c

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

Кейс

HOW
Цель
verify pkg:npm/import-local@3.2.0
Пакеты
Символы
  • importLocal
Создан
2026-08-27T15:41:52Z

Контракт

  1. importLocal is exported as a function that checks for a locally installed version of a package
  2. importLocal returns falsy when called on a file with no corresponding local installation in the current working directory
  3. importLocal accepts file:// URLs and file paths to package entry points
  4. importLocal imports and returns the local package module when a matching package exists in the current working directory's node_modules
  5. importLocal returns false when invoked from within the local node_modules directory to prevent recursive imports

Файлы

  • 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 pkg:npm/import-local@3.2.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/import-local@3.2.0
Demonstrate these symbols/APIs:
  - importLocal

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:db00048acace335bf663bb2ea6636a2c893de02a8fc27c37364a63bfdfbaab1e","contract":["importLocal is exported as a function that checks for a locally installed version of a package","importLocal returns falsy when called on a file with no corresponding local installation in the current working directory","importLocal accepts file:// URLs and file paths to package entry points","importLocal imports and returns the local package module when a matching package exists in the current working directory's node_modules","importLocal returns false when invoked from within the local node_modules directory to prevent recursive imports"],"goal":"verify pkg:npm/import-local@3.2.0","kind":"HOW","packages":["pkg:npm/import-local@3.2.0"],"schemaVersion":1,"symbols":["importLocal"]},"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-local@3.2.0"],"schemaVersion":1,"subject":"pkg:npm/import-local@3.2.0","symbols":["importLocal"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-import-local",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-import-local",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "import-local": "3.2.0"
      }
    },
    "node_modules/find-up": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
      "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
      "license": "MIT",
      "dependencies": {
        "locate-path": "^5.0.0",
        "path-exists": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/import-local": {
      "version": "3.2.0",
      "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.2.0.tgz",
      "integrity": "sha512-2SPlun1JUPWoM6t3F0dw0FkCF/jWY8kttcY4f599GLTSjh2OCuuhdTkJQsEcZzBqbXZGKMK2OqW1oZsjtf/gQA==",
      "license": "MIT",
      "dependencies": {
        "pkg-dir": "^4.2.0",
        "resolve-cwd": "^3.0.0"
      },
      "bin": {
        "import-local-fixture": "fixtures/cli.js"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/locate-path": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
      "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
      "license": "MIT",
      "dependencies": {
        "p-locate": "^4.1.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/p-limit": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
      "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
      "license": "MIT",
      "dependencies": {
        "p-try": "^2.0.0"
      },
      "engines": {
        "node": ">=6"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/p-locate": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
      "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
      "license": "MIT",
      "dependencies": {
        "p-limit": "^2.2.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/p-try": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
      "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/path-exists": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
      "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/pkg-dir": {
      "version": "4.2.0",
      "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz",
      "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==",
      "license": "MIT",
      "dependencies": {
        "find-up": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/resolve-cwd": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz",
      "integrity": "sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==",
      "license": "MIT",
      "dependencies": {
        "resolve-from": "^5.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/resolve-from": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
      "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    }
  }
}
package.json
{
  "name": "sample-import-local",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for import-local",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "import-local": "3.2.0"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/import-local@3.2.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/import-local@3.2.0"
  ],
  "symbols": [
    "importLocal"
  ]
}
src/index.js
const importLocal = require('import-local');

function tryImportLocal(filePath) {
  return importLocal(filePath);
}

module.exports = {
  importLocal,
  tryImportLocal
};
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const importLocal = require('import-local');
const { tryImportLocal } = require('../src/index.js');

// 1. Symbol and function contract
assert.strictEqual(typeof importLocal, 'function', 'importLocal is exported as a callable function');
assert.strictEqual(typeof tryImportLocal, 'function', 'tryImportLocal helper wraps importLocal');

// 2. Returns falsy when no local duplicate exists in the working directory
const notLocalResult = importLocal(import.meta.url);
assert.strictEqual(!notLocalResult, true, 'importLocal returns falsy when local duplicate is not found in cwd');

// 3. Supports file:// URLs
const urlResult = tryImportLocal(import.meta.url);
assert.strictEqual(!urlResult, true, 'importLocal accepts file:// URLs and processes them without throwing');

// 4. Resolves and requires local package when called from outside local node_modules
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'csx-import-local-contract-'));

try {
  // Global simulation
  const globalPkgDir = path.join(tempDir, 'global-env', 'node_modules', 'contract-fixture-cli');
  fs.mkdirSync(path.join(globalPkgDir, 'bin'), { recursive: true });
  fs.writeFileSync(path.join(globalPkgDir, 'package.json'), JSON.stringify({
    name: 'contract-fixture-cli',
    version: '1.0.0',
    bin: { 'contract-fixture-cli': 'bin/cli.js' }
  }));
  const globalCliFile = path.join(globalPkgDir, 'bin', 'cli.js');
  fs.writeFileSync(globalCliFile, 'module.exports = { isLocal: false, version: "1.0.0" };');

  // Local project simulation with local installation of contract-fixture-cli
  const localProjectDir = path.join(tempDir, 'project-dir');
  const localPkgDir = path.join(localProjectDir, 'node_modules', 'contract-fixture-cli');
  fs.mkdirSync(path.join(localPkgDir, 'bin'), { recursive: true });
  fs.writeFileSync(path.join(localPkgDir, 'package.json'), JSON.stringify({
    name: 'contract-fixture-cli',
    version: '2.5.0',
    bin: { 'contract-fixture-cli': 'bin/cli.js' }
  }));
  const localCliFile = path.join(localPkgDir, 'bin', 'cli.js');
  fs.writeFileSync(localCliFile, 'module.exports = { isLocal: true, version: "2.5.0", loaded: true };');

  const previousCwd = process.cwd();
  try {
    process.chdir(localProjectDir);

    // Call importLocal from global binary path
    const resolvedLocal = importLocal(globalCliFile);
    assert.ok(resolvedLocal, 'importLocal imports the local module when available in cwd node_modules');
    assert.strictEqual(resolvedLocal.isLocal, true, 'imported module is the local version');
    assert.strictEqual(resolvedLocal.version, '2.5.0', 'imported module matches local version 2.5.0');
    assert.strictEqual(resolvedLocal.loaded, true, 'local module exports are returned');

    // Call importLocal via file:// URL
    const resolvedLocalFromUrl = importLocal(pathToFileURL(globalCliFile).href);
    assert.ok(resolvedLocalFromUrl, 'importLocal resolves correctly when given file:// URL');
    assert.strictEqual(resolvedLocalFromUrl.version, '2.5.0', 'version matches local module');

    // Call importLocal from inside the local node_modules file itself (should not re-import)
    const selfImportResult = importLocal(localCliFile);
    assert.strictEqual(selfImportResult, false, 'importLocal returns false when the file is already inside local node_modules');

    // Call importLocal in empty project directory
    const emptyDir = path.join(tempDir, 'empty-dir');
    fs.mkdirSync(emptyDir, { recursive: true });
    process.chdir(emptyDir);

    const emptyResult = importLocal(globalCliFile);
    assert.strictEqual(!emptyResult, true, 'importLocal returns falsy when local package is absent');
  } finally {
    process.chdir(previousCwd);
  }
} finally {
  fs.rmSync(tempDir, { recursive: true, force: true });
}

console.log('Contract tests passed successfully.');

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

аноним