CodeSampleX

샘플

@babel/helper-plugin-utils 7.29.7

검증된 샘플 — npm @babel/helper-plugin-utils 7.29.7. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: declare wraps a plugin factory function and…

sha256:d5779f96ae8b6aed1846f2f5c3787be3e7a625761c248d0b298c2a9b5476e020

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
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
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-13

케이스

HOW
목표
verify pkg:npm/%40babel/helper-plugin-utils@7.29.7
패키지
생성일
2026-08-23T07:40:11Z

컨트랙트

  1. declare wraps a plugin factory function and passes through api, options, and dirname
  2. declare polyfills missing targets method returning an empty object
  3. declare polyfills missing assumption method returning undefined
  4. declare polyfills missing addExternalDependency method as a callable no-op
  5. declare polyfills assertVersion which throws BABEL_VERSION_UNSUPPORTED when version is incompatible
  6. declare preserves pre-existing api methods without overwriting them
  7. declare defaults options parameter to an empty object when omitted or undefined
  8. declarePreset functions as an exact alias of declare

파일

  • 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/%40babel/helper-plugin-utils@7.29.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40babel/helper-plugin-utils@7.29.7

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:6c5c5180b98084ea6894e794dae98a12d0b930be982370735e8b24387e47fdce","contract":["declare wraps a plugin factory function and passes through api, options, and dirname","declare polyfills missing targets method returning an empty object","declare polyfills missing assumption method returning undefined","declare polyfills missing addExternalDependency method as a callable no-op","declare polyfills assertVersion which throws BABEL_VERSION_UNSUPPORTED when version is incompatible","declare preserves pre-existing api methods without overwriting them","declare defaults options parameter to an empty object when omitted or undefined","declarePreset functions as an exact alias of declare"],"goal":"verify pkg:npm/%40babel/helper-plugin-utils@7.29.7","kind":"HOW","packages":["pkg:npm/%40babel/helper-plugin-utils@7.29.7"],"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/%40babel/helper-plugin-utils@7.29.7"],"schemaVersion":1,"subject":"pkg:npm/%40babel/helper-plugin-utils@7.29.7","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-babel-helper-plugin-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-babel-helper-plugin-utils",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@babel/helper-plugin-utils": "7.29.7"
      }
    },
    "node_modules/@babel/helper-plugin-utils": {
      "version": "7.29.7",
      "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.29.7.tgz",
      "integrity": "sha512-G7sHYigPY17oO5SYWnfD/0MTBwVR781S/JI643e/JhUYgVgWE/61SoW3NH9KWUKyKq5LVh3npif99Wkt6j86Jw==",
      "license": "MIT",
      "engines": {
        "node": ">=6.9.0"
      }
    }
  }
}
package.json
{
  "name": "sample-babel-helper-plugin-utils",
  "version": "1.0.0",
  "description": "Minimal sample verifying @babel/helper-plugin-utils",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@babel/helper-plugin-utils": "7.29.7"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40babel/helper-plugin-utils@7.29.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40babel/helper-plugin-utils@7.29.7"
  ]
}
src/index.js
const { declare, declarePreset } = require('@babel/helper-plugin-utils');

/**
 * Declares a Babel plugin using helper-plugin-utils.
 * @param {Function} builder - The plugin builder function (api, options, dirname) => pluginObject
 * @returns {Function} Wrapped plugin factory function
 */
function createPlugin(builder) {
  return declare(builder);
}

/**
 * Declares a Babel preset using helper-plugin-utils.
 * @param {Function} builder - The preset builder function (api, options, dirname) => presetObject
 * @returns {Function} Wrapped preset factory function
 */
function createPreset(builder) {
  return declarePreset(builder);
}

/**
 * Invokes a declared plugin or preset factory with the given API and options.
 * @param {Function} factory - The declared plugin or preset factory function
 * @param {object} api - The Babel API object (or minimal API object)
 * @param {object} [options] - Plugin configuration options
 * @param {string} [dirname] - Directory name context
 * @returns {*} The result produced by the builder
 */
function invokePluginFactory(factory, api, options, dirname) {
  return factory(api, options, dirname);
}

module.exports = {
  createPlugin,
  createPreset,
  invokePluginFactory,
  declare,
  declarePreset,
};
test/contract.mjs
import assert from 'node:assert';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  createPlugin,
  createPreset,
  invokePluginFactory,
  declare,
  declarePreset,
} = require('../src/index.js');

async function runContract() {
  // 1. declare wraps a plugin factory function and passes through api, options, and dirname
  let builderExecuted = false;
  const plugin = createPlugin((api, options, dirname) => {
    builderExecuted = true;
    return {
      name: 'transform-sample-custom',
      api,
      options,
      dirname,
    };
  });

  const mockApi = {
    version: '7.29.7',
  };
  const optionsInput = { loose: true, legacy: false };
  const dirnameInput = '/mock/project/path';

  const pluginInstance = invokePluginFactory(plugin, mockApi, optionsInput, dirnameInput);

  assert.strictEqual(builderExecuted, true, 'builder function should be invoked');
  assert.strictEqual(pluginInstance.name, 'transform-sample-custom', 'plugin name should match');
  assert.strictEqual(pluginInstance.dirname, dirnameInput, 'dirname should pass through');
  assert.deepStrictEqual(pluginInstance.options, optionsInput, 'options should pass through');

  // 2. declare polyfills missing targets method returning an empty object
  assert.strictEqual(typeof pluginInstance.api.targets, 'function', 'targets method should be polyfilled');
  assert.deepStrictEqual(pluginInstance.api.targets(), {}, 'polyfilled targets should return an empty object');

  // 3. declare polyfills missing assumption method returning undefined
  assert.strictEqual(typeof pluginInstance.api.assumption, 'function', 'assumption method should be polyfilled');
  assert.strictEqual(pluginInstance.api.assumption('pureGetters'), undefined, 'polyfilled assumption should return undefined');

  // 4. declare polyfills missing addExternalDependency method as a callable no-op
  assert.strictEqual(typeof pluginInstance.api.addExternalDependency, 'function', 'addExternalDependency method should be polyfilled');
  assert.strictEqual(pluginInstance.api.addExternalDependency('some-config.json'), undefined, 'addExternalDependency should be callable no-op');

  // 5. declare polyfills assertVersion which throws BABEL_VERSION_UNSUPPORTED when version is incompatible
  assert.strictEqual(typeof pluginInstance.api.assertVersion, 'function', 'assertVersion method should be polyfilled');
  assert.throws(
    () => {
      pluginInstance.api.assertVersion('^8.0.0');
    },
    (err) => {
      return err.code === 'BABEL_VERSION_UNSUPPORTED';
    },
    'assertVersion should throw BABEL_VERSION_UNSUPPORTED for incompatible version range'
  );

  // 6. declare preserves pre-existing api methods without overwriting them
  const customTargets = { node: '18.0.0' };
  const customApi = {
    version: '7.29.7',
    targets: () => customTargets,
    assumption: (name) => name === 'noDocumentAll',
    addExternalDependency: (file) => `registered:${file}`,
    assertVersion: (_range) => true,
  };

  const customPlugin = createPlugin((api) => api);
  const receivedApi = invokePluginFactory(customPlugin, customApi);

  assert.strictEqual(receivedApi.targets(), customTargets, 'custom targets method should be preserved');
  assert.strictEqual(receivedApi.assumption('noDocumentAll'), true, 'custom assumption method should be preserved');
  assert.strictEqual(receivedApi.assumption('unknown'), false, 'custom assumption method should return expected value');
  assert.strictEqual(receivedApi.addExternalDependency('dep.js'), 'registered:dep.js', 'custom addExternalDependency should be preserved');
  assert.strictEqual(receivedApi.assertVersion('^7.0.0'), true, 'custom assertVersion should be preserved');

  // 7. declare defaults options parameter to an empty object when omitted or undefined
  const optionsTestingPlugin = createPlugin((_api, options) => options);
  const defaultOptionsWhenOmitted = invokePluginFactory(optionsTestingPlugin, mockApi);
  const defaultOptionsWhenNull = invokePluginFactory(optionsTestingPlugin, mockApi, null);
  const defaultOptionsWhenUndefined = invokePluginFactory(optionsTestingPlugin, mockApi, undefined);

  assert.deepStrictEqual(defaultOptionsWhenOmitted, {}, 'options should default to empty object when omitted');
  assert.deepStrictEqual(defaultOptionsWhenNull, {}, 'options should default to empty object when null');
  assert.deepStrictEqual(defaultOptionsWhenUndefined, {}, 'options should default to empty object when undefined');

  // 8. declarePreset functions as an exact alias of declare
  assert.strictEqual(declarePreset, declare, 'declarePreset should be an exact alias of declare');

  const preset = createPreset((api, options) => ({ presetOption: options.presetOption, polyfilled: typeof api.targets === 'function' }));
  const presetResult = invokePluginFactory(preset, mockApi, { presetOption: 'active' });

  assert.strictEqual(presetResult.presetOption, 'active', 'preset options should be passed');
  assert.strictEqual(presetResult.polyfilled, true, 'preset api should receive polyfills');

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

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

오리진 시더

익명