workspace-sieve
Version:
A flexible workspace package filter for monorepos
192 lines (187 loc) • 5.87 kB
TypeScript
interface ExportFields {
import?: string;
require?: string;
default?: string;
}
type PackageBin = string | {
[commandName: string]: string;
};
type Dependencies = Record<string, string>;
type ProjectRootDir = string & {
__brand: 'ProjectRootDir';
};
type PackageScripts = {
[name: string]: string;
} & {
prepublish?: string;
prepare?: string;
prepublishOnly?: string;
prepack?: string;
postpack?: string;
publish?: string;
postpublish?: string;
preinstall?: string;
install?: string;
postinstall?: string;
preuninstall?: string;
uninstall?: string;
postuninstall?: string;
preversion?: string;
version?: string;
postversion?: string;
pretest?: string;
test?: string;
posttest?: string;
prestop?: string;
stop?: string;
poststop?: string;
prestart?: string;
start?: string;
poststart?: string;
prerestart?: string;
restart?: string;
postrestart?: string;
preshrinkwrap?: string;
shrinkwrap?: string;
postshrinkwrap?: string;
};
interface PeerDependenciesMeta {
[dependencyName: string]: {
optional?: boolean;
};
}
interface DependenciesMeta {
[dependencyName: string]: {
injected?: boolean;
node?: string;
patch?: string;
};
}
interface PublishConfig extends Record<string, unknown> {
directory?: string;
linkDirectory?: boolean;
executableFiles?: string[];
registry?: string;
}
interface TypesVersions {
[version: Version]: {
[pattern: Pattern]: string[];
};
}
interface BaseManifest {
name?: string;
version?: string;
bin?: PackageBin;
description?: string;
directories?: {
bin?: string;
};
files?: string[];
dependencies?: Dependencies;
devDependencies?: Dependencies;
optionalDependencies?: Dependencies;
peerDependencies?: Dependencies;
peerDependenciesMeta?: PeerDependenciesMeta;
dependenciesMeta?: DependenciesMeta;
bundleDependencies?: string[] | boolean;
bundledDependencies?: string[] | boolean;
homepage?: string;
repository?: string | {
url: string;
};
scripts?: PackageScripts;
config?: object;
engines?: {
node?: string;
npm?: string;
pnpm?: string;
};
cpu?: string[];
os?: string[];
libc?: string[];
main?: string;
module?: string;
typings?: string;
types?: string;
publishConfig?: PublishConfig;
typesVersions?: TypesVersions;
readme?: string;
keywords?: string[];
author?: string;
license?: string;
exports?: Record<string, string>;
}
interface ProjectManifest extends BaseManifest {
packageManager?: string;
workspaces?: string[];
private?: boolean;
resolutions?: Record<string, string>;
}
interface Package {
manifest: BaseManifest;
dirPath: string;
}
interface PackageNode<P extends Package> {
package: P;
dependencies: PackageNode<P>[];
}
interface PackageGraph<P extends Package> {
[id: string]: PackageNode<P>;
}
interface SupportedArchitectures {
os?: string[];
cpu?: string[];
libc?: string[];
}
interface PackageMetadata {
manifest: ProjectManifest;
manifestPath: string;
dirPath: string;
}
declare function searchForPackageRoot(current: string, root?: string): string;
declare function searchForWorkspaceRoot(current: string, root?: string): string;
declare function createWorkspacePatternWASM(patterns: string[], debug?: boolean): {
match: (input: string) => boolean;
dispose: () => void;
};
interface FindWorkspacePackagesOpts {
patterns?: string[];
supportedArchitectures?: SupportedArchitectures;
verbose?: 'info' | 'error' | 'silent';
}
declare const DEFAULT_IGNORE: string[];
type PackagesMetadata = Awaited<ReturnType<typeof findWorkspacePackages>>['packagesMetadata'];
declare function findWorkspacePackages(wd: string, options?: FindWorkspacePackagesOpts): Promise<{
packagesMetadata: {
manifest: ProjectManifest;
manifestPath: string;
dirPath: string;
}[];
errorMsgs: Error[];
}>;
interface FilterWorkspacePackagesOutput {
selected: string[];
unmatchedFilters: string[];
}
interface FilterOptions extends FindWorkspacePackagesOpts {
filter?: string[];
experimental?: {
debug: boolean;
};
}
interface FilterWorkspaceResult {
unmatchedFilters: string[];
matchedProjects: string[];
matchedGraphics: Record<string, Package>;
}
interface FilterWorkspacePackagesFromDirectoryResult extends FilterWorkspaceResult {
allProjects: PackagesMetadata;
}
declare function filterWorkspacePackagesFromDirectory(workspaceRoot: string, options?: FilterOptions): Promise<FilterWorkspacePackagesFromDirectoryResult>;
interface FilterWorkspacePackagesByGraphicsOptions {
experimental?: {
debug: boolean;
};
}
declare function filterWorkspacePackagesByGraphics(packageGraph: Record<string, Package>, patterns: string[], options?: FilterWorkspacePackagesByGraphicsOptions): FilterWorkspaceResult;
export { type BaseManifest, DEFAULT_IGNORE, type Dependencies, type DependenciesMeta, type ExportFields, type FilterOptions, type FilterWorkspacePackagesByGraphicsOptions, type FilterWorkspacePackagesFromDirectoryResult, type FilterWorkspacePackagesOutput, type FilterWorkspaceResult, type FindWorkspacePackagesOpts, type Package, type PackageBin, type PackageGraph, type PackageMetadata, type PackageNode, type PackageScripts, type PackagesMetadata, type PeerDependenciesMeta, type ProjectManifest, type ProjectRootDir, type PublishConfig, type SupportedArchitectures, type TypesVersions, createWorkspacePatternWASM, filterWorkspacePackagesByGraphics, filterWorkspacePackagesFromDirectory, findWorkspacePackages, searchForPackageRoot, searchForWorkspaceRoot };