CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-flow-typed

A CLI tool for managing high-quality Flow type definitions for third-party JavaScript libraries

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

installation.mddocs/

Installation and Management

Core functionality for installing, updating, and managing Flow type definitions for third-party libraries. This system provides automated discovery and installation of type definitions from the flow-typed repository.

Capabilities

Library Definition Installation

Install Flow type definitions for your project's dependencies.

/**
 * Install library definitions into the ./flow-typed directory
 * Automatically detects project dependencies and installs compatible definitions
 * @param args - Installation configuration options
 * @returns Promise resolving to exit code (0 for success)
 */
function install(args: InstallArgs): Promise<number>;

interface InstallArgs {
  /** Flow version that fetched libdefs must be compatible with */
  flowVersion?: string;
  /** Overwrite existing library definitions */
  overwrite?: boolean;
  /** Do not generate stubs for missing libdefs */
  skip?: boolean;
  /** Do not update cache prior to installing libdefs */
  skipCache?: boolean;
  /** Do not restart flow after installing libdefs */
  skipFlowRestart?: boolean;
  /** Print additional verbose info while installing libdefs */
  verbose?: boolean;
  /** Use a custom directory to install libdefs */
  libdefDir?: string;
  /** Custom cache directory */
  cacheDir?: string;
  /** Directory containing package.json */
  packageDir?: string;
  /** Array of dependency names to ignore during installation */
  ignoreDeps?: Array<string>;
  /** Root directory for the project */
  rootDir?: string;
  /** Use cache until specified time in milliseconds */
  useCacheUntil?: number;
  /** Explicitly specify packages to install */
  explicitLibDefs?: Array<string>;
}

Usage Examples:

import { install } from "flow-typed";

// Install all dependencies
const result = await install({
  verbose: true,
  flowVersion: "v0.83.0"
});

// Install specific libraries
const result = await install({
  explicitLibDefs: ["lodash", "express", "react"],
  overwrite: true,
  libdefDir: "custom-flow-typed"
});

// Install with dependency exclusions
const result = await install({
  ignoreDeps: ["dev-only-package", "testing-lib"],
  skip: false // Generate stubs for missing definitions
});

Cache Repository Management

Manage the local cache of library definitions from the flow-typed repository.

/**
 * Get the cache repository directory path
 * @returns Path to the cache repository directory
 */
function getCacheRepoDir(): string;

/**
 * Set a custom cache directory (internal function)
 * @param dir - Custom cache directory path
 */
function _setCustomCacheDir(dir: string): void;

/** Cache repository expiry time constant */
const CACHE_REPO_EXPIRY: number;

NPM Library Definition Management

Functions for working with npm-specific library definitions and package resolution.

/**
 * Get cached npm library definitions
 * @param cacheExpiry - Cache expiry time in milliseconds
 * @param skipCache - Skip cache update if true
 * @returns Promise resolving to array of npm library definitions
 */
function getCacheNpmLibDefs(
  cacheExpiry: number,
  skipCache: boolean = false
): Promise<Array<NpmLibDef>>;

/**
 * Check if package version matches library definition version
 * @param pkgVersion - Package version to check
 * @param libDefVersion - Library definition version
 * @returns Boolean indicating if versions match
 */
function pkgVersionMatch(pkgVersion: string, libDefVersion: string): boolean;

/**
 * Find npm library definition for a package
 * @param pkgName - Package name to find definition for
 * @param pkgVersion - Package version
 * @param flowVersion - Flow version for compatibility
 * @param libDefs - Array of available library definitions
 * @returns Library definition or null if not found
 */
function findNpmLibDef(
  pkgName: string,
  pkgVersion: string,
  flowVersion: FlowVersion,
  libDefs: Array<NpmLibDef>
): NpmLibDef | null;

/**
 * Get installed npm library definitions
 * @param flowVersion - Flow version for compatibility
 * @param libdefDir - Directory containing library definitions
 * @returns Promise resolving to array of installed definitions
 */
function getInstalledNpmLibDefs(
  flowVersion: FlowVersion,
  libdefDir: string
): Promise<Array<NpmLibDef>>;

/**
 * Get npm library definitions for a directory
 * @param defsDir - Directory containing definitions
 * @param libdefDir - Library definition directory
 * @returns Promise resolving to array of npm library definitions
 */
function getNpmLibDefs(
  defsDir: string,
  libdefDir: string
): Promise<Array<NpmLibDef>>;

/**
 * Get version hash for npm library definition
 * @param libDef - Library definition to get hash for
 * @returns Promise resolving to version hash string
 */
function getNpmLibDefVersionHash(libDef: NpmLibDef): Promise<string>;

/**
 * Get scoped package name for library definition
 * @param libDef - Library definition
 * @returns Scoped package name string
 */
function getScopedPackageName(libDef: NpmLibDef): string;

interface NpmLibDef extends LibDef {
  npmPackageName: string;
  npmVersionRange: string;
}

Package.json Integration

Functions for working with package.json files and dependency resolution.

/**
 * Find package dependency version string
 * @param pkgJsonPath - Path to package.json
 * @param pkgName - Package name to find
 * @returns Promise resolving to version string or null
 */
function findPackageJsonDepVersionStr(
  pkgJsonPath: string,
  pkgName: string
): Promise<string | null>;

/**
 * Find package.json file path starting from a directory
 * @param pathStr - Starting directory path
 * @returns Promise resolving to package.json path
 */
function findPackageJsonPath(pathStr: string): Promise<string>;

/**
 * Find workspace packages in a monorepo
 * @param rootPath - Root path to search from
 * @returns Promise resolving to array of workspace package paths
 */
function findWorkspacesPackages(rootPath: string): Promise<Array<string>>;

/**
 * Get package.json dependencies
 * @param pkgJson - Parsed package.json object
 * @param includeDevDeps - Include development dependencies
 * @returns Object with dependency name to version mappings
 */
function getPackageJsonDependencies(
  pkgJson: PkgJson,
  includeDevDeps?: boolean
): { [string]: string };

/**
 * Merge multiple package.json dependency objects
 * @param deps - Array of dependency objects to merge
 * @returns Merged dependency object
 */
function mergePackageJsonDependencies(
  deps: Array<{ [string]: string }>
): { [string]: string };

/**
 * Get package.json data from file path
 * @param pathStr - Path to package.json file
 * @returns Promise resolving to parsed package.json object
 */
function getPackageJsonData(pathStr: string): Promise<PkgJson>;

/**
 * Load PnP resolver for Yarn PnP projects
 * @param rootPath - Root path of the project
 * @returns Promise resolving to PnP resolver or null
 */
function loadPnpResolver(rootPath: string): Promise<any | null>;

interface PkgJson {
  name?: string;
  version?: string;
  dependencies?: { [string]: string };
  devDependencies?: { [string]: string };
  peerDependencies?: { [string]: string };
  workspaces?: Array<string> | { packages: Array<string> };
}

Code Signing and Verification

Security features for verifying the integrity of library definitions.

/**
 * Sign code stream with cryptographic signature
 * @param codeStream - Stream containing code to sign
 * @returns Promise resolving to signed code stream
 */
function signCodeStream(codeStream: any): Promise<any>;

/**
 * Verify signed code for authenticity
 * @param signedCode - Signed code to verify
 * @returns Promise resolving to verification result
 */
function verifySignedCode(signedCode: string): Promise<boolean>;

/**
 * Parse signed code version information
 * @param versionStr - Version string from signed code
 * @returns Parsed version information
 */
function parseSignedCodeVersion(versionStr: string): any;

Installation Workflow

The installation process follows this workflow:

  1. Project Analysis: Determine Flow version and scan package.json for dependencies
  2. Cache Update: Optionally update local cache of available definitions (unless skipCache is true)
  3. Definition Discovery: Find matching definitions for project dependencies
  4. Installation: Copy definitions to the flow-typed directory
  5. Stub Generation: Create stubs for missing definitions (unless skip is true)
  6. Flow Restart: Restart Flow server to pick up new definitions (unless skipFlowRestart is true)

Error Handling

  • Installation functions return exit codes (0 for success, non-zero for errors)
  • Common errors include network issues, version incompatibilities, and file system permissions
  • Verbose mode provides detailed logging for troubleshooting installation issues

docs

cli-commands.md

creation.md

flow-versions.md

index.md

installation.md

libdefs.md

search.md

tile.json