UNPKG

@plugjs/plug

Version:
87 lines (85 loc) 2.79 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // asserts.ts var asserts_exports = {}; __export(asserts_exports, { BuildFailure: () => BuildFailure, assert: () => assert, assertPromises: () => assertPromises, fail: () => fail }); module.exports = __toCommonJS(asserts_exports); var import_github = require("./logging/github.cjs"); var buildFailure = Symbol.for("plugjs:plug:types:BuildFailure"); var BuildFailure = class _BuildFailure extends Error { errors; /** Construct a {@link BuildFailure} */ constructor(message, errors = []) { super(message || ""); if (message) { (0, import_github.githubAnnotation)({ type: "error", title: "Build Failure" }, message); } Error.captureStackTrace(this, _BuildFailure); if (errors.length) this.errors = Object.freeze([...errors]); } static fail() { return new _BuildFailure(void 0, []); } static withMessage(message) { return new _BuildFailure(message, []); } static withErrors(errors) { return new _BuildFailure(void 0, errors); } static [Symbol.hasInstance](instance) { return instance && instance[buildFailure] === buildFailure; } static { this.prototype[buildFailure] = buildFailure; this.prototype.name = this.name; } }; async function assertPromises(promises) { const settlements = await Promise.allSettled(promises); const results = []; const failures = /* @__PURE__ */ new Set(); settlements.forEach((settlement) => { if (settlement.status === "fulfilled") { results.push(settlement.value); } else { failures.add(settlement.reason); } }); if (failures.size) throw BuildFailure.withErrors([...failures]); return results; } function assert(assertion, message) { if (!assertion) throw BuildFailure.withMessage(message); } function fail(message) { throw BuildFailure.withMessage(message); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BuildFailure, assert, assertPromises, fail }); //# sourceMappingURL=asserts.cjs.map