@visulima/package
Version:
One Package to rule them all, finds your root-dir, monorepo, or package manager.
54 lines (50 loc) • 1.78 kB
JavaScript
;
const packageManager = require('../package-manager.cjs');
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class PackageNotFoundError extends Error {
static {
__name(this, "PackageNotFoundError");
}
/**
* @param {string} packageName - The name of the package that was not found.
* @param {string} packageManager - The package manager used to install the package.
*/
constructor(packageName, packageManager$1) {
if (typeof packageName === "string") {
packageName = [packageName];
}
if (packageName.length === 0) {
super("Package was not found.");
return;
}
if (packageManager$1 === void 0) {
try {
const foundManager = packageManager.findPackageManagerSync();
packageManager$1 = foundManager.packageManager;
} catch {
}
}
if (packageManager$1 === void 0) {
packageManager$1 = "npm";
}
super(`Package '${packageName.join(" ")}' was not found. Please install it using '${packageManager$1} install ${packageName.join(" ")}'`);
}
// eslint-disable-next-line class-methods-use-this
get code() {
return "PACKAGE_NOT_FOUND";
}
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
set code(_name) {
throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND");
}
// eslint-disable-next-line class-methods-use-this
get name() {
return "PackageNotFoundError";
}
// eslint-disable-next-line class-methods-use-this,@typescript-eslint/explicit-module-boundary-types
set name(_name) {
throw new Error("Cannot overwrite name of PackageNotFoundError");
}
}
module.exports = PackageNotFoundError;