CodeSampleX

샘플

cross-spawn 7.0.6: execute child process with cross-spawn and cross-spawn.sync

검증된 샘플 — npm cross-spawn 7.0.6: execute child process with cross-spawn and cross-spawn.sync. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.

sha256:c92afed6c986dbf6e1d569c08eeaed85fa755d53fe3f8e0ec3cf5981e9aa5dd7

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

케이스

HOW
목표
execute child process with cross-spawn and cross-spawn.sync
패키지
심벌
  • spawn
  • sync
생성일
2026-08-26T08:56:04Z

컨트랙트

  1. spawn.sync executes command and captures stdout and exit status synchronously
  2. spawn.sync returns non-zero status when child process exits with non-zero code
  3. spawn.sync returns ENOENT error in result when command executable does not exist
  4. spawn.sync passes input option to child process stdin
  5. spawn executes command asynchronously and streams stdout data
  6. spawn emits error event with ENOENT when command executable does not exist

파일

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

소스 아티팩트 내려받기 (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: execute child process with cross-spawn and cross-spawn.sync
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/cross-spawn@7.0.6
Demonstrate these symbols/APIs:
  - spawn
  - sync

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:fb9249f10bd2ae935b0cd742defa5da9606c8686f0dcac64d75b9bbc96f509c8","contract":["spawn.sync executes command and captures stdout and exit status synchronously","spawn.sync returns non-zero status when child process exits with non-zero code","spawn.sync returns ENOENT error in result when command executable does not exist","spawn.sync passes input option to child process stdin","spawn executes command asynchronously and streams stdout data","spawn emits error event with ENOENT when command executable does not exist"],"goal":"execute child process with cross-spawn and cross-spawn.sync","kind":"HOW","packages":["pkg:npm/cross-spawn@7.0.6"],"schemaVersion":1,"symbols":["spawn","sync"]},"contractCommand":["node","test/contract.js"],"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/cross-spawn@7.0.6"],"schemaVersion":1,"subject":"pkg:npm/cross-spawn@7.0.6","symbols":["spawn","sync"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-cross-spawn",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-cross-spawn",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "cross-spawn": "7.0.6"
      }
    },
    "node_modules/cross-spawn": {
      "version": "7.0.6",
      "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
      "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
      "license": "MIT",
      "dependencies": {
        "path-key": "^3.1.0",
        "shebang-command": "^2.0.0",
        "which": "^2.0.1"
      },
      "engines": {
        "node": ">= 8"
      }
    },
    "node_modules/isexe": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
      "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
      "license": "ISC"
    },
    "node_modules/path-key": {
      "version": "3.1.1",
      "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
      "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/shebang-command": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
      "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
      "license": "MIT",
      "dependencies": {
        "shebang-regex": "^3.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/shebang-regex": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
      "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/which": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
      "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
      "license": "ISC",
      "dependencies": {
        "isexe": "^2.0.0"
      },
      "bin": {
        "node-which": "bin/node-which"
      },
      "engines": {
        "node": ">= 8"
      }
    }
  }
}
package.json
{
  "name": "sample-cross-spawn",
  "version": "1.0.0",
  "description": "execute child process with cross-spawn and cross-spawn.sync",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "cross-spawn": "7.0.6"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "execute child process with cross-spawn and cross-spawn.sync",
  "kind": "HOW",
  "packages": [
    "pkg:npm/cross-spawn@7.0.6"
  ],
  "symbols": [
    "spawn",
    "sync"
  ]
}
src/index.js
'use strict';

const spawn = require('cross-spawn');

function runSync(command, args = [], options = {}) {
  return spawn.sync(command, args, options);
}

function runAsync(command, args = [], options = {}) {
  return spawn(command, args, options);
}

function runCommandCapture(command, args = [], options = {}) {
  const result = spawn.sync(command, args, {
    encoding: 'utf8',
    ...options,
  });
  return {
    status: result.status,
    stdout: result.stdout,
    stderr: result.stderr,
    error: result.error,
  };
}

module.exports = {
  runSync,
  runAsync,
  runCommandCapture,
  spawn,
};
test/contract.js
'use strict';

const assert = require('node:assert');
const spawn = require('cross-spawn');
const { runSync, runAsync, runCommandCapture } = require('../src/index.js');

async function testSyncExecution() {
  // 1. spawn.sync executes command and captures stdout and exit status synchronously
  const res = spawn.sync('node', ['-e', 'process.stdout.write("spawn-sync-ok")'], { encoding: 'utf8' });
  assert.strictEqual(res.status, 0, 'status should be 0');
  assert.strictEqual(res.stdout, 'spawn-sync-ok', 'stdout should match');
  assert.ok(!res.error, 'error should not be present on success');

  const helperRes = runCommandCapture('node', ['-e', 'process.stdout.write("helper-ok")']);
  assert.strictEqual(helperRes.status, 0);
  assert.strictEqual(helperRes.stdout, 'helper-ok');
}

async function testNonZeroExit() {
  // 2. spawn.sync returns non-zero status when child process exits with non-zero code
  const res = spawn.sync('node', ['-e', 'process.exit(5)']);
  assert.strictEqual(res.status, 5, 'exit status should be 5');

  const helperRes = runCommandCapture('node', ['-e', 'process.exit(12)']);
  assert.strictEqual(helperRes.status, 12, 'helper status should be 12');
}

async function testMissingCommandSync() {
  // 3. spawn.sync returns ENOENT error in result when command executable does not exist
  const res = spawn.sync('nonexistent_command_xyz_12345');
  assert.ok(res.error, 'error property should exist');
  assert.strictEqual(res.error.code, 'ENOENT', 'error code should be ENOENT');
}

async function testSyncInput() {
  // 4. spawn.sync passes input option to child process stdin
  const res = spawn.sync('node', ['-e', 'process.stdin.pipe(process.stdout)'], {
    input: 'hello from stdin',
    encoding: 'utf8'
  });
  assert.strictEqual(res.status, 0);
  assert.strictEqual(res.stdout, 'hello from stdin');
}

function testAsyncExecution() {
  // 5. spawn executes command asynchronously and streams stdout data
  return new Promise((resolve, reject) => {
    const child = spawn('node', ['-e', 'process.stdout.write("async-stream-data")']);
    let stdout = '';
    child.stdout.on('data', (chunk) => {
      stdout += chunk;
    });
    child.on('error', reject);
    child.on('close', (code) => {
      try {
        assert.strictEqual(code, 0, 'child process should exit with code 0');
        assert.strictEqual(stdout, 'async-stream-data', 'stdout should match');
        resolve();
      } catch (err) {
        reject(err);
      }
    });
  });
}

function testAsyncMissingCommand() {
  // 6. spawn emits error event with ENOENT when command executable does not exist
  return new Promise((resolve, reject) => {
    const child = spawn('nonexistent_command_xyz_12345');
    child.on('error', (err) => {
      try {
        assert.strictEqual(err.code, 'ENOENT', 'async spawn should emit ENOENT error');
        resolve();
      } catch (e) {
        reject(e);
      }
    });
    child.on('close', () => {
      resolve();
    });
  });
}

async function main() {
  await testSyncExecution();
  await testNonZeroExit();
  await testMissingCommandSync();
  await testSyncInput();
  await testAsyncExecution();
  await testAsyncMissingCommand();
  console.log('Contract tests passed successfully.');
}

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

오리진 시더

익명