@moonsong-labs/moonwall-cli
Version:
Testing framework for the Moon family of projects
103 lines (101 loc) • 3.94 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/internal/localNode.ts
var localNode_exports = {};
__export(localNode_exports, {
launchNode: () => launchNode
});
module.exports = __toCommonJS(localNode_exports);
var import_child_process = require("child_process");
var import_chalk = __toESM(require("chalk"), 1);
var import_debug = __toESM(require("debug"), 1);
var import_fs = require("fs");
var debugNode = (0, import_debug.default)("global:node");
async function launchNode(cmd, args, name) {
if (cmd.includes("moonbeam") && !(0, import_fs.existsSync)(cmd)) {
throw new Error(
`No binary file found at location: ${cmd}
Are you sure your ${import_chalk.default.bgWhiteBright.blackBright(
"moonwall.config.json"
)} file has the correct "binPath" in launchSpec?`
);
}
let runningNode;
const onProcessExit = () => {
runningNode && runningNode.kill();
};
const onProcessInterrupt = () => {
runningNode && runningNode.kill();
};
process.once("exit", onProcessExit);
process.once("SIGINT", onProcessInterrupt);
runningNode = (0, import_child_process.spawn)(cmd, args);
runningNode.once("exit", () => {
process.removeListener("exit", onProcessExit);
process.removeListener("SIGINT", onProcessInterrupt);
debugNode(`Exiting dev node: ${name}`);
});
runningNode.on("error", (err) => {
if (err.errno == "ENOENT") {
console.error(
`\x1B[31mMissing Moonbeam binary at(${cmd}).
Please compile the Moonbeam project\x1B[0m`
);
} else {
console.error(err);
}
process.exit(1);
});
const binaryLogs = [];
await new Promise((resolve, reject) => {
const timer = setTimeout(() => {
console.error(import_chalk.default.redBright("Failed to start Moonbeam Test Node."));
console.error(`Command: ${cmd} ${args.join(" ")}`);
console.error(`Logs:`);
console.error(binaryLogs.map((chunk) => chunk.toString()).join("\n"));
reject("Failed to launch node");
}, 1e4);
const onData = async (chunk) => {
debugNode(chunk.toString());
binaryLogs.push(chunk);
if (chunk.toString().match(/Development Service Ready/) || chunk.toString().match(/ RPC listening on port/)) {
clearTimeout(timer);
runningNode.stderr.off("data", onData);
runningNode.stdout.off("data", onData);
resolve();
}
};
runningNode.stderr.on("data", onData);
runningNode.stdout.on("data", onData);
});
return runningNode;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
launchNode
});