UNPKG

typesync

Version:

Install missing TypeScript typings for your dependencies.

247 lines (238 loc) 5.88 kB
/** * Globber interface. */ interface IGlobber { /** * Globs for directory names. * * @param root */ globDirs(this: void, root: string, patterns: Array<string>, ignore?: Array<string>): Promise<Array<string>>; } /** * Service for fetching monorepo workspaces in a standardized format agnostic of the package manager used. * It is used to allow syncing all types in a workspace when run from the root of a monorepo. */ interface IWorkspaceResolverService { /** * Reads, parses, and normalizes a workspaces configuration from the following files, in this order: * - `package.json` `workspaces` field, as an array of globs. * - `package.json` `workspaces` field, as an object with a `packages` field, which is an array of globs. * - `pnpm-workspace.yaml` `packages` field, as an array of globs. * * Path is relative to the current working directory. * Note that this returns a list of directories, not paths to the manifests themselves. */ getWorkspaces(this: void, packageJson: IPackageFile, root: string, globber: IGlobber, ignored: IWorkspacesArray): Promise<IWorkspacesArray>; } /** * @example * ```json * "workspaces": [ * "packages/*", * ] * ``` */ type IWorkspacesArray = Array<string>; /** * @example * ```yaml * packages: * - 'packages/*' * ``` */ interface IWorkspacesObject { packages?: IWorkspacesArray; } /** * @see {@link IWorkspacesArray} */ type NpmWorkspacesConfig = IWorkspacesArray; /** * Yarn is a special snowflake. * * @example * ```json * "workspaces": { * "packages": [ * "packages/*", * ], * "nohoist": [] * } * ``` */ type YarnWorkspacesConfig = IWorkspacesArray | (IWorkspacesObject & { nohoist?: Array<string> }); /** * @see {@link IWorkspacesArray} */ type BunWorkspacesConfig = IWorkspacesArray; /** * Section in `package.json` representing workspaces. */ type IWorkspacesSection = NpmWorkspacesConfig | YarnWorkspacesConfig | BunWorkspacesConfig; /** * The guts of the program. */ interface ITypeSyncer { sync(this: void, filePath: string, flags: ICLIArguments["flags"]): Promise<ISyncResult>; } /** * Sync options. */ interface ISyncOptions { /** * Ignore certain deps. */ ignoreDeps?: Array<IDependencySection>; /** * Ignore certain packages. */ ignorePackages?: Array<string>; /** * Skip resolution of certain projects in the workspace. */ ignoreProjects?: IWorkspacesArray; } /** * Package.json file. */ interface IPackageFile { name?: string; dependencies?: IDependenciesSection; devDependencies?: IDependenciesSection; peerDependencies?: IDependenciesSection; optionalDependencies?: IDependenciesSection; workspaces?: IWorkspacesSection; [key: string]: unknown; } /** * Section in package.json representing dependencies. */ type IDependenciesSection = Record<string, string>; /** * Package + version record, collected from the {"package": "^1.2.3"} sections. */ interface IPackageVersion { name: string; version: string; } /** * Describes how a package may be typed. */ interface IPackageTypingDescriptor { typingsName: string; codePackageName: string; typesPackageName: string; } /** * A type definition with the corresponding code package name. */ interface ISyncedTypeDefinition extends IPackageTypingDescriptor { codePackageName: string; } /** * Sync result. */ interface ISyncResult { /** * The files that were synced. */ syncedFiles: Array<ISyncedFile>; } /** * A file that was synced. */ interface ISyncedFile { /** * The cwd-relative path to the synced file. */ filePath: string; /** * The package file that was synced. */ package: IPackageFile; /** * The new typings that were added. */ newTypings: Array<ISyncedTypeDefinition>; } /** * Dependency sections. */ declare enum IDependencySection { dev = "dev", deps = "deps", optional = "optional", peer = "peer", } /** * CLI arguments. */ interface ICLIArguments { flags: Record<string, boolean | string | undefined>; args: Array<string>; } /** * Config Service. */ interface IConfigService { /** * Get typesync config. */ readConfig(this: void, filePath: string, flags: ICLIArguments["flags"]): Promise<ISyncOptions>; } declare function createConfigService(): IConfigService; /** * Version descriptor for versions returned in remote package info. */ interface IPackageVersionInfo { version: string; containsInternalTypings: boolean; } /** * Fetches info about a package. */ interface IPackageSource { /** * Fetches package info from an external source. * * @param packageName */ fetch(this: void, packageName: string): Promise<IPackageInfo | null>; } /** * Interface for the Package Info structure. */ interface IPackageInfo { name: string; latestVersion: string; deprecated: boolean; versions: Array<IPackageVersionInfo>; } /** * Creates a package source. */ declare function createPackageSource(): IPackageSource; /** * File service. */ interface IPackageJSONService { /** * Reads and parses JSON from the specified file. Path is relative to the current working directory. */ readPackageFile(this: void, filePath: string): Promise<IPackageFile>; /** * Writes the JSON to the specified file. */ writePackageFile(this: void, filePath: string, fileContents: IPackageFile): Promise<void>; } /** * Creates a type syncer. * * @param packageJSONservice * @param typeDefinitionSource */ declare function createTypeSyncer(packageJSONService: IPackageJSONService, workspaceResolverService: IWorkspaceResolverService, packageSource: IPackageSource, configService: IConfigService, globber: IGlobber): ITypeSyncer; export { type ICLIArguments, type IConfigService, type IDependenciesSection, IDependencySection, type IPackageFile, type IPackageInfo, type IPackageSource, type IPackageTypingDescriptor, type IPackageVersion, type ISyncOptions, type ISyncResult, type ISyncedFile, type ISyncedTypeDefinition, type ITypeSyncer, createConfigService, createPackageSource, createTypeSyncer };