Match files by glob pattern and generate their dependencies graph.
npm install glob-esm-graph
# or
yarn add glob-esm-graph
# or
pnpm install glob-esm-graph
type Options = {
/**
* The current working directory in which to search.
*/
cwd: string,
/**
* Glob patterns to match against.
*/
pattern: string | string[],
}
declare function globMatch (options: Options): string[]
Input the work dir and the glob pattern(s), returns the matched files in under dependent modules.
type DependenciesAnalysis = { module: string, dependencies: string[]}
declare function analyze(entries: string[], cwd: string): Promise<DependenciesAnalysis[]>
Input the esm format files as entries and the work dir, returns the analysis which contain the module info and their dependencies info.
type Graph = {
getNodes: () => string[],
getEdges: () => [from: string, to: string][],
getEntryNodes: () => string[],
getEndNodes: () => string[],
getPaths: () => string[][],
getCircular: () => string[][],
getSortedByDependencies: () => string[][],
}
declare function buildGraph (dependenciesAnalysis: DependenciesAnalysis[]): Graph
Input the dependencies analysis comes from
analyze
, returns the graph stats.
getPaths
doesn't contains circular pathsgetSortedByDependencies
will sort the dependencies which are related and keep the other's original order. The sorting priority accords to dependent depth in the graph.
import { globMatch, analyze, buildGraph } from 'glob-esm-graph'
const cwd = `${__dirname}/foo-test`
const pattern = '**/*.module.ts'
const matched = globMatch({ cwd, pattern })
const dependenciesAnalysis = await analyze(matched, cwd)
const graph = buildGraph(dependenciesAnalysis)