pncat
Version:
Enhanced pnpm catalogs management with advanced workspace dependency control.
170 lines (163 loc) • 4.9 kB
text/typescript
import { PackageJson } from 'pkg-types';
import { PnpmWorkspaceYamlSchema, PnpmWorkspaceYaml } from 'pnpm-workspace-yaml';
declare const MODE_CHOICES: readonly ["detect", "migrate", "add", "remove", "clean", "revert"];
declare const DEPS_FIELDS: readonly ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies", "packageManager", "pnpm.overrides", "resolutions", "overrides", "pnpm-workspace"];
type RangeMode = typeof MODE_CHOICES[number];
type DepType = typeof DEPS_FIELDS[number];
type DepFieldOptions = Partial<Record<DepType, boolean>>;
interface SpecifierRule {
/**
* Semver range, e.g., ">=3.0.0", "<3.0.0"
*/
specifier: string;
/**
* Specific packages this version range applies to.
* If not specified, applies to all packages matched by the parent CatalogRule.
* Supports same format as CatalogRule.match: string, RegExp, or array of both.
*/
match?: string | RegExp | (string | RegExp)[];
/**
* Complete catalog name, takes priority over suffix
*/
name?: string;
/**
* Catalog suffix, e.g., "v3", "v2"
*/
suffix?: string;
}
interface CatalogRule {
name: string;
match: string | RegExp | (string | RegExp)[];
depFields?: DepType[];
priority?: number;
specifierRules?: SpecifierRule[];
}
interface CommonOptions {
cwd?: string;
recursive?: boolean;
force?: boolean;
ignorePaths?: string | string[];
ignoreOtherWorkspaces?: boolean;
include?: string | string[];
exclude?: string | string[];
/**
* Fields in package.json to be checked
* By default all fields will be checked
*/
depFields?: DepFieldOptions;
/**
* Allowed protocols in specifier to not be converted to catalog
*/
allowedProtocols: string[];
/**
* Rules to group and name dependencies in the catalog output
*/
catalogRules?: CatalogRule[];
/**
* Options to control how specifier ranges are processed
*/
specifierOptions?: SpecifierOptions;
}
interface CatalogOptions extends CommonOptions {
mode?: RangeMode;
/**
* Prompt for confirmation
*
* @default true
*/
yes?: boolean;
/**
* Install dependencies after execution
*
* @default true
*/
install?: boolean;
}
interface RawDep {
name: string;
specifier: string;
source: DepType;
parents?: string[];
catalog: boolean;
}
interface BasePackageMeta {
/**
* Package name
*/
name: string;
/**
* Is private package
*/
private?: boolean;
/**
* Package version
*/
version?: string;
/**
* Absolute filepath
*/
filepath: string;
/**
* Relative filepath to the root project
*/
relative: string;
/**
* Dependencies
*/
deps: RawDep[];
}
interface PackageJsonMeta extends BasePackageMeta {
/**
* Package type
*/
type: 'package.json';
/**
* Raw package.json Object
*/
raw: PackageJson;
}
interface PnpmWorkspaceMeta extends BasePackageMeta {
type: 'pnpm-workspace.yaml';
raw: PnpmWorkspaceYamlSchema;
context: PnpmWorkspaceYaml;
}
type PackageMeta = PackageJsonMeta | PnpmWorkspaceMeta;
interface SpecifierOptions {
/**
* Whether to skip complex version ranges (e.g., "||", "-", ">=16.0.0")
* @default true
*/
skipComplexRanges?: boolean;
/**
* List of specific range types to skip (overrides skipComplexRanges)
* Example: ["||", "-", ">=", "<", "x", "*", "pre-release"]
*/
skipRangeTypes?: SpecifierRangeType[];
/**
* Whether to allow pre-release versions (e.g., "4.0.0-beta")
* @default true
*/
allowPreReleases?: boolean;
/**
* Whether to allow wildcard versions (e.g., "3.x", "*")
* @default false
*/
allowWildcards?: boolean;
}
type SpecifierRangeType = '||' | '-' | '>=' | '<=' | '>' | '<' | 'x' | '*' | 'pre-release';
interface ParsedSpec {
name: string;
specifier?: string;
catalog?: string;
specifierSource?: 'user' | 'catalog' | 'workspace' | 'npm';
}
declare const DEFAULT_CATALOG_RULES: CatalogRule[];
interface MergeOptions {
mergeDefaults?: boolean;
arrayMerge?: (target: any[], source: any[]) => any[];
}
declare function mergeCatalogRules(options: MergeOptions, ...rules: CatalogRule[][]): CatalogRule[];
declare function mergeCatalogRules(...rules: CatalogRule[][]): CatalogRule[];
declare function defineConfig(config: Partial<CatalogOptions>): Partial<CatalogOptions>;
export { DEFAULT_CATALOG_RULES, defineConfig, mergeCatalogRules };
export type { BasePackageMeta, CatalogOptions, CatalogRule, CommonOptions, DepFieldOptions, DepType, MergeOptions, PackageJsonMeta, PackageMeta, ParsedSpec, PnpmWorkspaceMeta, RangeMode, RawDep, SpecifierOptions, SpecifierRangeType, SpecifierRule };