Tools for creating new type definitions and stubs for libraries without existing definitions. This system provides both template generation for new definitions and automatic stub creation for missing libraries.
Create template library definitions for new packages that need Flow type definitions.
/**
* Create template library definitions in flow-typed repository format
* @param args - Creation configuration options
* @returns Promise resolving to exit code (0 for success)
*/
function createDef(args: CreateDefArgs): Promise<number>;
interface CreateDefArgs {
/** Name of the library to create definition for */
libName: string;
/** Version range to add (e.g., "1.x.x", "^2.0.0") */
ver: string;
}Usage Examples:
import { createDef } from "flow-typed";
// Create definition template for a specific library
const result = await createDef({
libName: "my-awesome-lib",
ver: "1.x.x"
});
// Create definition for scoped package
const result = await createDef({
libName: "@company/ui-components",
ver: "2.x.x"
});Create stub definitions for libraries that don't have existing Flow type definitions.
/**
* Create stub definitions for missing libraries
* Automatically generates basic type stubs based on the library's exports
* @param args - Stub creation configuration options
* @returns Promise resolving to exit code (0 for success)
*/
function createStub(args: CreateStubArgs): Promise<number>;
interface CreateStubArgs {
/** Name of the library to create stub for */
libName: string;
/** Directory to install stub definitions (default: "flow-typed") */
libdefDir?: string;
/** Overwrite existing stub definitions */
overwrite?: boolean;
/** Maximum number of lines to include in stub */
maxLines?: number;
}Usage Examples:
import { createStub } from "flow-typed";
// Create basic stub for a library
const result = await createStub({
libName: "unknown-package"
});
// Create stub with custom configuration
const result = await createStub({
libName: "complex-lib",
libdefDir: "custom-flow-typed",
overwrite: true,
maxLines: 100
});Low-level utilities for working with stub generation and package analysis.
/**
* Create stub definition for a package
* @param projectRoot - Root directory of the project
* @param packageName - Package name to create stub for
* @param explicitVersion - Explicit version string or null
* @param overwrite - Whether to overwrite existing stubs
* @param pnpjs - PnP resolver or null
* @param typescript - Whether to generate TypeScript stubs
* @param libdefDir - Optional directory to create stub in
* @param maxDepth - Optional maximum depth for stub generation
* @returns Promise resolving to boolean indicating success
*/
function createStub(
projectRoot: string,
packageName: string,
explicitVersion: string | null,
overwrite: boolean,
pnpjs: any | null,
typescript: boolean,
libdefDir?: string,
maxDepth?: number
): Promise<boolean>;
/**
* Check if a package has Flow files
* @param pkgPath - Path to the package directory
* @returns Promise resolving to boolean indicating if Flow files exist
*/
function pkgHasFlowFiles(pkgPath: string): Promise<boolean>;
interface PnpResolver {
resolveRequest: Function;
getMetadata: Function;
}Helper functions for file operations during definition creation.
/**
* Copy file from source to destination
* @param src - Source file path
* @param dest - Destination file path
* @returns Promise resolving when copy is complete
*/
function copyFile(src: string, dest: string): Promise<void>;
/**
* Create directory recursively (like mkdir -p)
* @param dirPath - Directory path to create
* @returns Promise resolving when directory is created
*/
function mkdirp(dirPath: string): Promise<void>;
/**
* Check if a file should be excluded from processing
* @param filePath - File path to check
* @returns Boolean indicating if file should be excluded
*/
function isExcludedFile(filePath: string): boolean;When creating template definitions, the system generates files with this structure:
// @flow
declare module 'package-name' {
// Export declarations go here
declare export default any;
declare export function functionName(): any;
}// @flow
declare module 'package-name' {
declare module.exports: {
// Module exports go here
+version: string,
+default: any,
// Add specific function signatures
};
}The stub generation process follows these steps:
Simple Package Stub:
// @flow
declare module 'simple-package' {
declare module.exports: any;
}Complex Package Stub:
// @flow
declare module 'complex-package' {
declare export default {
init(options?: Object): void,
process(data: any): Promise<any>,
configure(config: Object): void,
};
declare export var VERSION: string;
declare export function helper(input: string): string;
}any when possible