@semrel-extra/topo

Helper to resolve monorepo dependencies graph

Usage no npm install needed!

<script type="module">
  import semrelExtraTopo from 'https://cdn.skypack.dev/@semrel-extra/topo';
</script>

README

@semrel-extra/topo

CI Maintainability Test Coverage

Helper to resolve monorepo dependencies graph by workspaces

Install

yarn add @semrel-extra/topo

Usage

import { topo } from '@semrel-extra/topo'

const graph = topo({
  workspaces: ['packages/*'],
  cwd: '/path/to/project/root'
})

{
  queue: ['pkg-a', 'pkg-b', 'pkg-z', 'pkg-y', 'pkg-x'],
  nodes: ['pkg-a', 'pkg-b', 'pkg-x', 'pkg-y', 'pkg-z'],
  edges: [
    ['pkg-a', 'pkg-b'],
    ['pkg-z', 'pkg-y'],
    ['pkg-y', 'pkg-x'],
  ],
  // packages entries map
  packages: {
    'pkg-a': {
      manifest: {
        name: 'pkg-a',
        dependencies: {}
      },
      manifestPath: '/path/to/project/root/packages/a/package.json',
      path: 'packages/pkg-a'
    },
    'pkg-b': {...},
    ...
  }
}

filter()

Filter option is a function: gets IPackageEntry as argument, returns boolean

const graph = topo({
  workspaces: ['packages/*'],
  cwd: '/path/to/project/root',
  filter: ({manifest}) => !manifest.private // to omit private packages from graph
})

License

MIT