UNPKG

@sizium/core

Version:

Get the actual size of any local or remote package

107 lines (101 loc) 3.52 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 PackageJSON = JSONSchemaForNPMPackageJsonFiles & { name: string; version: string; }; type lifeCycleScripts = typeof LIFE_CYCLE_SCRIPTS[number]; type PackageInfo = { name: string; version: string; description?: string; license?: string; isESM: boolean; isCommonJS: boolean; 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']; 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; }> { } declare class PackageSuper { #private; input: string; opts?: { /** Skip error on package dependence and return undefined */ skipError: boolean; } | 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; constructor(input: string, opts?: { /** Skip error on package dependence and return undefined */ skipError: boolean; } | undefined); private processedPackages; protected LIFE_CYCLE_SCRIPTS: readonly ["preinstall", "install", "postinstall", "prepublish", "preprepare", "prepare", "postprepare"]; protected getMainPkgData(allPackages: PackageInfo[]): { id: string; packageNum: number; size: number; sizeKB: number; sizeMB: number; packages: PackageInfo[]; }; protected getPkgData(data: PackageJSON, level?: number, unpackedSize?: number, installedBy?: string | string[]): PackageInfo; protected getRegistryData(packageName: string, version: string, level?: number, installedBy?: string): Promise<PackageInfo>; protected getPackagesData(mainPackage: PackageInfo): Promise<PackageInfo[]>; } export { type PackageInfo as P, type SiziumResponse as S, type PackageJSON as a, PackageSuper as b };