File dependency resolution and input expansion functionality that determines which files to include in documentation generation based on import/require relationships and configuration options.
Resolves file dependencies and expands input file lists based on configuration settings for comprehensive documentation coverage.
/**
* Resolve dependencies for given input files based on configuration
* @param indexes - Files to process (string or array of strings)
* @param config - Configuration object containing processing options
* @returns Promise resolving to array of resolved file paths
*/
function expandInputs(
indexes: string[] | string,
config: Config
): Promise<string[]>;
interface Config {
/** Whether to avoid dependency parsing */
shallow?: boolean;
/** Whether to document only exported values */
documentExported?: boolean;
/** String regex/glob patterns for external modules to include */
external?: string[];
/** Additional file extensions to treat as JavaScript */
extension?: string | string[];
/** Parse additional file extensions */
parseExtension?: string[];
/** Files and directories to exclude */
exclude?: string[];
/** Base directory for file resolution */
cwd?: string;
/** Module resolution configuration */
resolve?: ResolveConfig;
}
interface ResolveConfig {
/** Additional module directories */
modules?: string[];
/** File extensions to resolve */
extensions?: string[];
/** Module alias mappings */
alias?: { [key: string]: string };
}Usage Examples:
import { expandInputs } from "documentation";
// Basic input expansion with dependency resolution
const files = await expandInputs(['index.js'], {
shallow: false,
external: ['lodash', 'express']
});
console.log(files); // ['index.js', 'lib/utils.js', 'lib/api.js', ...]
// Shallow processing - no dependency resolution
const files = await expandInputs(['src/'], {
shallow: true
});
// Document only exported values
const files = await expandInputs(['lib/index.js'], {
documentExported: true,
shallow: false
});
// Custom file extensions
const files = await expandInputs(['src/'], {
extension: ['ts', 'tsx', 'vue'],
parseExtension: ['ts', 'tsx']
});The input processing system supports two main strategies for file discovery:
Analyzes import/require statements to build a complete dependency graph:
const files = await expandInputs(['index.js'], {
shallow: false
});This approach:
import and require statementsProcesses only explicitly specified files without dependency resolution:
const files = await expandInputs(['src/**/*.js'], {
shallow: true
});This approach:
Configure which external dependencies to include in documentation:
const files = await expandInputs(['index.js'], {
external: [
'lodash.*', // Include all lodash submodules
'express', // Include express module
'@company/.*' // Include all @company scoped packages
]
});External module patterns support:
'lodash' matches only lodash'lodash.*' matches lodash.get, lodash.set, etc.'@company/.*' matches all packages in the @company scopeControl which file types are processed as JavaScript:
const files = await expandInputs(['src/'], {
extension: ['ts', 'tsx', 'vue', 'jsx'],
parseExtension: ['ts', 'tsx']
});Configuration options:
js, es6, jsx, mjsExclude specific files or directories from processing:
const files = await expandInputs(['src/'], {
exclude: [
'src/test/**',
'src/**/*.test.js',
'src/legacy/**',
'node_modules/**'
]
});Exclusion supports:
node_modules, .git, common build directoriesConfigure how modules are resolved for dependency analysis:
const files = await expandInputs(['src/'], {
resolve: {
modules: ['node_modules', 'src', 'lib'],
extensions: ['.js', '.ts', '.tsx', '.json'],
alias: {
'@utils': './src/utils',
'@components': './src/components'
}
}
});Resolution configuration:
Set the base directory for file resolution:
const files = await expandInputs(['lib/'], {
cwd: '/path/to/project',
shallow: false
});The working directory affects:
Focus documentation on only exported values:
const files = await expandInputs(['lib/index.js'], {
documentExported: true
});This mode:
Input processing performance can be optimized based on project characteristics:
// Use shallow processing for faster builds
const files = await expandInputs(['src/'], {
shallow: true,
exclude: ['src/test/**', 'src/**/*.test.js']
});// Document only specific modules
const files = await expandInputs(['src/api.js', 'src/utils.js'], {
shallow: true
});// Process only changed files
const changedFiles = getChangedFiles(); // Custom implementation
const files = await expandInputs(changedFiles, {
shallow: true
});Input processing handles various error conditions gracefully:
try {
const files = await expandInputs(['nonexistent.js'], {});
} catch (error) {
if (error.code === 'ENOENT') {
console.error('Input file not found');
} else if (error.message.includes('Cannot resolve module')) {
console.error('Module resolution failed');
}
}Common error scenarios:
Input processing integrates well with various build tools:
// Webpack-style configuration
const files = await expandInputs(['src/index.js'], {
resolve: {
modules: ['node_modules', 'src'],
alias: {
'@': './src'
}
}
});
// TypeScript project
const files = await expandInputs(['src/'], {
extension: ['ts', 'tsx'],
parseExtension: ['ts', 'tsx'],
resolve: {
extensions: ['.ts', '.tsx', '.js']
}
});