Skip to content

zheeeng/glob-esm-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

glob-esm-graph

Match files by glob pattern and generate their dependencies graph.

Install

npm install glob-esm-graph

# or

yarn add glob-esm-graph

# or

pnpm install glob-esm-graph

API

globMatch

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.

analyze

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.

buildGraph

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 paths
  • getSortedByDependencies will sort the dependencies which are related and keep the other's original order. The sorting priority accords to dependent depth in the graph.

Usage

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)

About

Generate ESM dependencies graph by glob-matching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published