UNPKG

@-xun/project

Version:

A library to help me wrangle the complex landscape between monorepos and polyrepos

86 lines (85 loc) 3.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.XPackageJsonNotParsableError = exports.ProjectError = exports.NotAGitRepositoryError = exports.DuplicatePackageNameError = exports.DuplicatePackageIdError = exports.CommonErrorMessage = void 0; var _types = require("node:util/types"); var _error = require("@-xun/error"); const { ProjectError } = (0, _error.makeNamedError)(class ProjectError extends Error { constructor(reason, options = {}, message = undefined, superOptions = {}) { let { cause } = options; message = message ?? (typeof reason === 'string' ? reason : reason?.message) ?? CommonErrorMessage.Generic(); if (!('cause' in options)) { cause = typeof reason === 'string' ? undefined : reason; } super(message, { cause, ...superOptions }); } }, 'ProjectError'); exports.ProjectError = ProjectError; const { NotAGitRepositoryError } = (0, _error.makeNamedError)(class NotAGitRepositoryError extends ProjectError { constructor(message = undefined) { super(message ?? CommonErrorMessage.NotAGitRepositoryError()); } }, 'NotAGitRepositoryError'); exports.NotAGitRepositoryError = NotAGitRepositoryError; const { XPackageJsonNotParsableError } = (0, _error.makeNamedError)(class XPackageJsonNotParsableError extends ProjectError { constructor(packageJsonPath, reason, message = undefined) { super(message ?? CommonErrorMessage.PackageJsonNotParsable(packageJsonPath, reason)); this.packageJsonPath = packageJsonPath; this.reason = reason; } }, 'XPackageJsonNotParsableError'); exports.XPackageJsonNotParsableError = XPackageJsonNotParsableError; const { DuplicatePackageNameError } = (0, _error.makeNamedError)(class DuplicatePackageNameError extends ProjectError { constructor(packageName, firstPath, secondPath, message = undefined) { super(message ?? CommonErrorMessage.DuplicatePackageName(packageName, firstPath, secondPath)); this.packageName = packageName; this.firstPath = firstPath; this.secondPath = secondPath; } }, 'DuplicatePackageNameError'); exports.DuplicatePackageNameError = DuplicatePackageNameError; const { DuplicatePackageIdError } = (0, _error.makeNamedError)(class DuplicatePackageIdError extends ProjectError { constructor(id, firstPath, secondPath, message = undefined) { super(message ?? CommonErrorMessage.DuplicatePackageId(id, firstPath, secondPath)); this.id = id; this.firstPath = firstPath; this.secondPath = secondPath; } }, 'DuplicatePackageIdError'); exports.DuplicatePackageIdError = DuplicatePackageIdError; const CommonErrorMessage = exports.CommonErrorMessage = { Generic() { return 'an error occurred that caused this software to crash'; }, GuruMeditation() { return 'an impossible scenario occurred'; }, NotAGitRepositoryError() { return 'unable to locate git repository root'; }, PackageJsonNotParsable(packageJsonPath, reason) { return `unable to parse ${packageJsonPath}: ${(0, _types.isNativeError)(reason) ? reason.message : String(reason)}`; }, DuplicatePackageName(packageName, firstPath, secondPath) { return `the following packages must not have the same name "${packageName}":\n` + ` ${firstPath}\n` + ` ${secondPath}`; }, DuplicatePackageId(id, firstPath, secondPath) { return `the following unnamed packages must not have the same package-id "${id}":\n` + ` ${firstPath}\n` + ` ${secondPath}`; } };