CodeSampleX

Beispiel

@istanbuljs/load-nyc-config 1.1.0: load NYC configuration asynchronously using @istanbuljs/load-nyc-config

Verifiziertes Beispiel für npm @istanbuljs/load-nyc-config 1.1.0: load NYC configuration asynchronously using @istanbuljs/load-nyc-config. Der Vertrag lief…

sha256:f857ba4f05eebd6d89091a1cc48a3ad72904244c7ea2a67bcba1442c68b9b0d1

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 npm

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
load NYC configuration asynchronously using @istanbuljs/load-nyc-config
Pakete
Symbole
  • loadNycConfig
Erstellt
2026-08-27T21:28:26Z

Contract

  1. assert loadNycConfig asynchronously loads configuration from package.json with camelCase normalization and resolved cwd
  2. assert loadNycConfig asynchronously loads configuration from .nycrc.json with precedence over package.json
  3. assert loadNycConfig asynchronously loads specific configuration file specified via nycrcPath option
  4. assert loadNycConfig rejects when specified nycrcPath configuration file does not exist
  5. assert loadNycConfig normalizes singular string values to arrays for array fields
  6. assert loadNycConfig merges extended configurations where extended file properties apply over extending file
  7. assert loadNycConfig rejects when circular extended configurations are detected
  8. assert isLoading returns boolean false when configuration loading is idle

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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: load NYC configuration asynchronously using @istanbuljs/load-nyc-config
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40istanbuljs/load-nyc-config@1.1.0
Demonstrate these symbols/APIs:
  - loadNycConfig

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:11216b67914ce811f50c7f2c6bcf5e4b9d422084d768023ed7e896176d9f7c41","contract":["assert loadNycConfig asynchronously loads configuration from package.json with camelCase normalization and resolved cwd","assert loadNycConfig asynchronously loads configuration from .nycrc.json with precedence over package.json","assert loadNycConfig asynchronously loads specific configuration file specified via nycrcPath option","assert loadNycConfig rejects when specified nycrcPath configuration file does not exist","assert loadNycConfig normalizes singular string values to arrays for array fields","assert loadNycConfig merges extended configurations where extended file properties apply over extending file","assert loadNycConfig rejects when circular extended configurations are detected","assert isLoading returns boolean false when configuration loading is idle"],"goal":"load NYC configuration asynchronously using @istanbuljs/load-nyc-config","kind":"HOW","packages":["pkg:npm/%40istanbuljs/load-nyc-config@1.1.0"],"schemaVersion":1,"symbols":["loadNycConfig"]},"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/%40istanbuljs/load-nyc-config@1.1.0"],"schemaVersion":1,"subject":"pkg:npm/%40istanbuljs/load-nyc-config@1.1.0","symbols":["loadNycConfig"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { loadNycConfig, isLoading } from '@istanbuljs/load-nyc-config';

/**
 * Loads NYC configuration asynchronously for the given directory or options.
 *
 * @param {object} [options]
 * @param {string} [options.cwd]
 * @param {string|string[]} [options.nycrcPath]
 * @returns {Promise<Record<string, any>>}
 */
export async function loadConfig(options) {
  return loadNycConfig(options);
}

/**
 * Checks if configuration loading is currently in progress.
 *
 * @returns {boolean}
 */
export function isCurrentlyLoading() {
  return isLoading();
}

export { loadNycConfig, isLoading };
export default loadNycConfig;
package-lock.json
{
  "name": "sample-load-nyc-config",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-load-nyc-config",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@istanbuljs/load-nyc-config": "1.1.0"
      }
    },
    "node_modules/@istanbuljs/load-nyc-config": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
      "integrity": "sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==",
      "license": "ISC",
      "dependencies": {
        "camelcase": "^5.3.1",
        "find-up": "^4.1.0",
        "get-package-type": "^0.1.0",
        "js-yaml": "^3.13.1",
        "resolve-from": "^5.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/argparse": {
      "version": "1.0.10",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
      "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
      "license": "MIT",
      "dependencies": {
        "sprintf-js": "~1.0.2"
      }
    },
    "node_modules/camelcase": {
      "version": "5.3.1",
      "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
      "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/esprima": {
      "version": "4.0.1",
      "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
      "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
      "license": "BSD-2-Clause",
      "bin": {
        "esparse": "bin/esparse.js",
        "esvalidate": "bin/esvalidate.js"
      },
      "engines": {
        "node": ">=4"
      }
    },
    "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/get-package-type": {
      "version": "0.1.0",
      "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz",
      "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8.0.0"
      }
    },
    "node_modules/js-yaml": {
      "version": "3.15.2",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.2.tgz",
      "integrity": "sha512-6EuL879VkRA+1Cz578mKMiKvjPNEuk6+r1JaFzoSWejZmtf7xWbIyw1e3KkxlkzTIt9Taw6JBhEppG7utc1P+w==",
      "license": "MIT",
      "dependencies": {
        "argparse": "^1.0.7",
        "esprima": "^4.0.0"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    },
    "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/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"
      }
    },
    "node_modules/sprintf-js": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
      "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==",
      "license": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "sample-load-nyc-config",
  "version": "1.0.0",
  "description": "Clean-room sample demonstrating @istanbuljs/load-nyc-config",
  "main": "index.mjs",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@istanbuljs/load-nyc-config": "1.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "load NYC configuration asynchronously using @istanbuljs/load-nyc-config",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40istanbuljs/load-nyc-config@1.1.0"
  ],
  "symbols": [
    "loadNycConfig"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { loadNycConfig, isLoading, loadConfig, isCurrentlyLoading } from '../index.mjs';

const tmpBase = fs.mkdtempSync(path.join(os.tmpdir(), 'load-nyc-config-contract-'));

try {
  // 1. assert loadNycConfig asynchronously loads configuration from package.json with camelCase normalization and resolved cwd
  {
    const dir = path.join(tmpBase, 'pkg-json-test');
    fs.mkdirSync(dir, { recursive: true });
    fs.writeFileSync(
      path.join(dir, 'package.json'),
      JSON.stringify({
        name: 'test-pkg',
        nyc: {
          'check-coverage': true,
          lines: 95,
          'per-file': false
        }
      }),
      'utf8'
    );

    const config = await loadConfig({ cwd: dir });
    assert.strictEqual(config.cwd, dir);
    assert.strictEqual(config.checkCoverage, true);
    assert.strictEqual(config.lines, 95);
    assert.strictEqual(config.perFile, false);
  }

  // 2. assert loadNycConfig asynchronously loads configuration from .nycrc.json with precedence over package.json
  {
    const dir = path.join(tmpBase, 'nycrc-json-test');
    fs.mkdirSync(dir, { recursive: true });
    fs.writeFileSync(
      path.join(dir, 'package.json'),
      JSON.stringify({
        name: 'test-pkg',
        nyc: {
          lines: 80,
          all: false
        }
      }),
      'utf8'
    );
    fs.writeFileSync(
      path.join(dir, '.nycrc.json'),
      JSON.stringify({
        lines: 100,
        all: true,
        'report-dir': './coverage-output'
      }),
      'utf8'
    );

    const config = await loadNycConfig({ cwd: dir });
    assert.strictEqual(config.cwd, dir);
    assert.strictEqual(config.lines, 100);
    assert.strictEqual(config.all, true);
    assert.strictEqual(config.reportDir, './coverage-output');
  }

  // 3. assert loadNycConfig asynchronously loads specific configuration file specified via nycrcPath option
  {
    const dir = path.join(tmpBase, 'custom-path-test');
    fs.mkdirSync(dir, { recursive: true });
    const customConfigPath = path.join(dir, 'custom-nyc.json');
    fs.writeFileSync(
      customConfigPath,
      JSON.stringify({
        'temp-dir': '.custom-nyc_output',
        instrument: false
      }),
      'utf8'
    );

    const config = await loadNycConfig({ cwd: dir, nycrcPath: customConfigPath });
    assert.strictEqual(config.tempDir, '.custom-nyc_output');
    assert.strictEqual(config.instrument, false);
  }

  // 4. assert loadNycConfig rejects when specified nycrcPath configuration file does not exist
  {
    const dir = path.join(tmpBase, 'missing-path-test');
    fs.mkdirSync(dir, { recursive: true });
    const nonExistentPath = path.join(dir, 'does-not-exist.json');

    await assert.rejects(
      async () => {
        await loadNycConfig({ cwd: dir, nycrcPath: nonExistentPath });
      },
      {
        name: 'Error',
        message: `Requested configuration file ${nonExistentPath} not found`
      }
    );
  }

  // 5. assert loadNycConfig normalizes singular string values to arrays for array fields
  {
    const dir = path.join(tmpBase, 'array-norm-test');
    fs.mkdirSync(dir, { recursive: true });
    fs.writeFileSync(
      path.join(dir, '.nycrc'),
      JSON.stringify({
        require: 'ts-node/register',
        extension: '.ts',
        exclude: 'tests/**',
        include: 'src/**'
      }),
      'utf8'
    );

    const config = await loadNycConfig({ cwd: dir });
    assert.deepStrictEqual(config.require, ['ts-node/register']);
    assert.deepStrictEqual(config.extension, ['.ts']);
    assert.deepStrictEqual(config.exclude, ['tests/**']);
    assert.deepStrictEqual(config.include, ['src/**']);
  }

  // 6. assert loadNycConfig merges extended configurations where extended file properties apply over extending file
  {
    const dir = path.join(tmpBase, 'extends-test');
    fs.mkdirSync(dir, { recursive: true });
    const baseConfigPath = path.join(dir, 'base-nyc.json');
    fs.writeFileSync(
      baseConfigPath,
      JSON.stringify({
        all: true,
        branches: 85,
        lines: 85
      }),
      'utf8'
    );
    fs.writeFileSync(
      path.join(dir, '.nycrc.json'),
      JSON.stringify({
        extends: './base-nyc.json',
        branches: 50,
        statements: 90
      }),
      'utf8'
    );

    const config = await loadNycConfig({ cwd: dir });
    assert.strictEqual(config.all, true);
    assert.strictEqual(config.branches, 85);
    assert.strictEqual(config.lines, 85);
    assert.strictEqual(config.statements, 90);
  }

  // 7. assert loadNycConfig rejects when circular extended configurations are detected
  {
    const dir = path.join(tmpBase, 'circular-extends-test');
    fs.mkdirSync(dir, { recursive: true });
    const configA = path.join(dir, 'config-a.json');
    const configB = path.join(dir, 'config-b.json');

    fs.writeFileSync(
      configA,
      JSON.stringify({
        extends: './config-b.json'
      }),
      'utf8'
    );
    fs.writeFileSync(
      configB,
      JSON.stringify({
        extends: './config-a.json'
      }),
      'utf8'
    );

    await assert.rejects(
      async () => {
        await loadNycConfig({ cwd: dir, nycrcPath: configA });
      },
      (err) => {
        assert.strictEqual(err.name, 'Error');
        assert.ok(err.message.includes('Circular extended configurations'));
        return true;
      }
    );
  }

  // 8. assert isLoading returns boolean false when configuration loading is idle
  {
    assert.strictEqual(isLoading(), false);
    assert.strictEqual(isCurrentlyLoading(), false);
  }

  console.log('All contracts passed successfully.');
} finally {
  fs.rmSync(tmpBase, { recursive: true, force: true });
}

Ursprungs-Seeder

anonym