@jsdevtools/npm-publish
Version:
Fast, easy publishing to NPM
102 lines • 3.59 kB
JavaScript
import os from "node:os";
import { ACCESS_PUBLIC, ACCESS_RESTRICTED, STRATEGY_ALL, STRATEGY_UPGRADE, } from "./options.js";
export class InvalidPackageError extends TypeError {
constructor(value) {
super(`Package must be a directory, package.json, or .tgz file, got "${String(value)}"`);
this.name = "PackageJsonReadError";
}
}
export class PackageJsonReadError extends Error {
constructor(manifestPath, originalError) {
const message = [
`Could not read package.json at ${manifestPath}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageJsonReadError";
}
}
export class PackageTarballReadError extends Error {
constructor(tarballPath, originalError) {
const message = [
`Could not read package.json from ${tarballPath}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageTarballReadError";
}
}
export class PackageJsonParseError extends SyntaxError {
constructor(packageSpec, originalError) {
const message = [
`Invalid JSON, could not parse package.json for ${packageSpec}`,
originalError instanceof Error ? originalError.message : "",
]
.filter(Boolean)
.join(os.EOL);
super(message);
this.name = "PackageJsonParseError";
}
}
export class InvalidPackageNameError extends TypeError {
constructor(value) {
super(`Package name is not valid, got "${String(value)}"`);
this.name = "InvalidPackageNameError";
}
}
export class InvalidPackageVersionError extends TypeError {
constructor(value) {
super(`Package version must be a valid semantic version, got "${String(value)}"`);
this.name = "InvalidPackageVersionError";
}
}
export class InvalidPackagePublishConfigError extends TypeError {
constructor(value) {
super(`Publish config must be an object, got "${String(value)}"`);
this.name = "InvalidPackagePublishConfigError";
}
}
export class InvalidRegistryUrlError extends TypeError {
constructor(value) {
super(`Registry URL invalid, got "${String(value)}"`);
this.name = "InvalidRegistryUrlError";
}
}
export class InvalidTokenError extends TypeError {
constructor() {
super("Token must be a non-empty string.");
this.name = "InvalidTokenError";
}
}
export class InvalidTagError extends TypeError {
constructor(value) {
super(`Tag must be a non-empty string, got "${String(value)}".`);
this.name = "InvalidTagError";
}
}
export class InvalidAccessError extends TypeError {
constructor(value) {
super(`Access must be "${ACCESS_PUBLIC}" or "${ACCESS_RESTRICTED}", got "${String(value)}".`);
this.name = "InvalidAccessError";
}
}
export class InvalidStrategyError extends TypeError {
constructor(value) {
super(`Strategy must be "${STRATEGY_UPGRADE}" or "${STRATEGY_ALL}", got "${String(value)}".`);
this.name = "InvalidStrategyError";
}
}
export class NpmCallError extends Error {
constructor(command, exitCode, stderr) {
super([
`Call to "npm ${command}" exited with non-zero exit code ${exitCode}`,
stderr,
].join(os.EOL));
this.name = "NpmCallError";
}
}
//# sourceMappingURL=errors.js.map