UNPKG

@pact-foundation/pact-cli

Version:
76 lines 3.27 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.standalone = exports.spawnSync = exports.getExePath = void 0; const path = __importStar(require("node:path")); const childProcess = __importStar(require("node:child_process")); const pact_environment_1 = __importDefault(require("./pact-environment")); function getExePath() { const { arch } = process; const os = pact_environment_1.default.isWindows() ? 'windows' : process.platform; const packageName = `@pact-foundation/pact-cli`; const platformArchSpecificPackage = `${packageName}-${os}-${arch}`; try { const lib = require.resolve(`${platformArchSpecificPackage}/package.json`); return lib.replace('package.json', ''); } catch (_) { throw new Error(`Couldn't find application binary for ${os}-${arch}:\n 💡 check if ${platformArchSpecificPackage} has been downloaded in your node_modules`); } } exports.getExePath = getExePath; function spawnSync(command, args) { const isWindowsExeFile = pact_environment_1.default.isWindows() && command.endsWith('.exe'); if (pact_environment_1.default.isWindows()) { command = `"${command}"`; } const spawnOptions = { stdio: 'inherit', ...(isWindowsExeFile && { shell: true }), }; const result = childProcess.spawnSync(command, args, spawnOptions); if (result.error) { return { error: result.error }; } return { status: result.status ?? undefined }; } exports.spawnSync = spawnSync; const standalone = (platform = process.platform) => { const exeName = (name) => `${name}${pact_environment_1.default.isWindows(platform) ? '.exe' : ''}`; const pact = exeName('pact'); const basePath = path.join('standalone'); const exePath = getExePath(); return { cwd: pact_environment_1.default.cwd, pactPath: path.join(basePath, pact), pactFullPath: path.resolve(exePath, basePath, pact).trim(), }; }; exports.standalone = standalone; exports.default = (0, exports.standalone)(); //# sourceMappingURL=pact-standalone.js.map