@modern-js/module-tools
Version:
Simple, powerful, high-performance modern npm package development solution.
140 lines (138 loc) • 4.24 kB
JavaScript
;
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);
var error_exports = {};
__export(error_exports, {
InternalBuildError: () => InternalBuildError,
InternalDTSError: () => InternalDTSError,
ModuleBuildError: () => ModuleBuildError,
isExecaError: () => isExecaError,
isInternalError: () => isInternalError,
padSpaceWith: () => padSpaceWith
});
module.exports = __toCommonJS(error_exports);
var import_utils = require("@modern-js/utils");
const padSpaceWith = (str, targetL, opts = {}) => {
const { endStr = "|", style } = opts;
const l = str.length;
const endStrL = endStr.length;
const resetL = targetL - l - endStrL;
if (resetL === 0) {
return (style ? style(str) : str) + endStr;
}
if (resetL > 0) {
const padStr = str.padEnd(targetL - 1, " ");
if (style) {
return style(str) + padStr.replace(str, "") + endStr;
}
return padStr + endStr;
}
return str;
};
class InternalBuildError extends Error {
toString() {
return this.formatError().join("\n");
}
formatError() {
var _this_stack;
const msgs = [];
const { buildType, target, format } = this;
const textL = 25;
const title = `│ ${padSpaceWith(`${buildType} failed:`, textL - 2, {
style: import_utils.chalk.red.underline,
endStr: "│"
})}`;
const formatMsg = padSpaceWith(`│ - format is "${format}"`, textL, {
endStr: "│"
});
const targetMsg = padSpaceWith(`│ - target is "${target}"`, textL, {
endStr: "│"
});
const startLine = padSpaceWith("╭".padEnd(textL - 1, "─"), textL, {
endStr: "╮"
});
const endLine = padSpaceWith("╰".padEnd(textL - 1, "─"), textL, {
endStr: "╯"
});
msgs.push(startLine, title, formatMsg, targetMsg, endLine, import_utils.chalk.blue.bold.underline(`
Detailed Information: `));
msgs.push(((_this_stack = this.stack) === null || _this_stack === void 0 ? void 0 : _this_stack.substring(7)) || this.message);
return msgs;
}
constructor(e, opts) {
super(e.stack);
Error.captureStackTrace(this, this.constructor);
this.buildType = opts.buildType;
this.target = opts.target;
this.format = opts.format;
}
}
class InternalDTSError extends Error {
toString() {
return this.formatError().join("\n");
}
formatError() {
const msgs = [];
const { e, buildType } = this;
msgs.push(import_utils.chalk.red.bold(`${buildType} DTS failed:`));
if (isExecaError(e)) {
if (e.stack) {
var _e_stack;
msgs.push((_e_stack = e.stack) === null || _e_stack === void 0 ? void 0 : _e_stack.replace(`${e.name}: ${e.shortMessage}`, ""));
}
} else {
msgs.push(e.stack);
}
return msgs;
}
constructor(e, opts) {
super(e.message);
Error.captureStackTrace(this, this.constructor);
this.e = e;
this.buildType = opts.buildType;
}
}
class ModuleBuildError extends Error {
constructor(e) {
super(`
${e}`);
Error.captureStackTrace(this, this.constructor);
this.name = "ModuleBuildError";
}
}
const isInternalError = (e) => {
if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
return true;
}
return false;
};
const isExecaError = (e) => {
if (e.stdout) {
return true;
}
return false;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InternalBuildError,
InternalDTSError,
ModuleBuildError,
isExecaError,
isInternalError,
padSpaceWith
});