UNPKG

@sizium/core

Version:

Get the actual size of any local or remote package

154 lines (148 loc) 4.29 kB
import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; declare const ERROR_ID: { readonly INVALID_PKG_NAME: "INVALID_PKG_NAME"; readonly GETTING_PKG_NAME: "GETTING_PKG_NAME"; readonly GETTING_REGISTRY_DATA: "GETTING_REGISTRY_DATA"; readonly GETTING_LOCAL_DATA: "GETTING_LOCAL_DATA"; }; declare const LIFE_CYCLE_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepublish", "preprepare", "prepare", "postprepare"]; type Any = any; type PackageJSON = JSONSchemaForNPMPackageJsonFiles & { name: string; version: string; }; type RegistryPackageJSON = PackageJSON & { _id: string; dist?: { unpackedSize: number; }; [key: string]: Any; }; type lifeCycleScripts = typeof LIFE_CYCLE_SCRIPTS[number]; type PackageInfo = { /** * The id of the package: `name@version` */ id: string; /** * The name of the package */ name: string; /** * The version of the package */ version: string; /** * The description of the package */ description?: string; /** * The license of the package */ license?: string; /** * If the package is written in ESM */ isESM: boolean; /** * If the package is written in CommonJS */ isCommonJS: boolean; /** * If the package has types */ types: boolean; author?: { name: string; url: string; }; url: { npm: string; homepage?: string; repository?: string; funding?: string; unpkg?: string; }; /** Unpacked size in bytes */ unpackedSize: number; unpackedSizeKB: number; unpackedSizeMB: number; dependencies?: PackageJSON['dependencies']; devDependencies?: PackageJSON['devDependencies']; /** * Life cycle scripts like: * - {post,pre}install * - {post,pre}publish * - {post,pre}prepare */ lifeCycleScripts?: { [key in lifeCycleScripts]?: string; }; installedBy?: string[]; /** Level of the dependence installation. Main packages is 0 */ level: number; }; type SiziumResponse = { id: string; /** Number of total packages installed */ packageNum: number; /** Size in bytes */ size: number; /** Size in kylobytes */ sizeKB: number; /** Size in megabytes */ sizeMB: number; /** All data from packages */ packages: PackageInfo[]; }; declare class TypedError<M extends string = string, D = undefined> extends Error { data: D | undefined; constructor(message: M, data?: D); } type SiziumErrorID = typeof ERROR_ID[keyof typeof ERROR_ID]; declare class SiziumError extends TypedError<SiziumErrorID, { msg: string; e?: unknown; }> { } type PackageSuperOptions = { /** Skip error on package dependence and return undefined */ skipError: boolean; }; declare class PackageSuper { #private; input: string; opts?: PackageSuperOptions | undefined; ERROR_ID: { readonly INVALID_PKG_NAME: "INVALID_PKG_NAME"; readonly GETTING_PKG_NAME: "GETTING_PKG_NAME"; readonly GETTING_REGISTRY_DATA: "GETTING_REGISTRY_DATA"; readonly GETTING_LOCAL_DATA: "GETTING_LOCAL_DATA"; }; Error: typeof SiziumError; protected LIFE_CYCLE_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepublish", "preprepare", "prepare", "postprepare"]; constructor(input: string, opts?: PackageSuperOptions | undefined); protected getMainPkgData(allPackages: PackageInfo[]): { id: string; packageNum: number; size: number; sizeKB: number; sizeMB: number; packages: PackageInfo[]; }; protected getPkgData(opts: { data: PackageJSON; level?: number; unpackedSize?: number; installedBy?: string | string[]; }): PackageInfo; protected getRegistryData(opts: { name: string; version: string; level?: number; installedBy?: string; }): Promise<PackageInfo>; protected getPackagesData(mainPackage: PackageInfo): Promise<PackageInfo[]>; } export { SiziumError as a, PackageSuper as c }; export type { PackageInfo as P, RegistryPackageJSON as R, SiziumResponse as S, PackageJSON as b };