Detalhes do pacote

@semrel-extra/topo

semrel-extra79kMIT1.14.1

Helpers to assist monorepo dependencies traversals

topo, graph, monorepo

readme (leia-me)

@semrel-extra/topo

CI Maintainability Test Coverage

Helpers to assist monorepo dependencies traversals

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/a', // legacy
      relPath: 'packages/a',
      absPath: '/path/to/project/root/packages/a'
    },
    'pkg-b': {...},
    ...
  }
}

pkgFilter() / 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
})

depFilter()

Applies filter to any kind of pkg dependencies to omit them from the graph.

const gpaph = topo({
  workspaces: ['packages/*'],
  cwd: '/path/to/project/root',
  depFilter: ({version}) => version.startsWith('workspace:') // include only workspace deps
})

workspacesExtra

Injects extra pattern to the resolved workspaces value from package.json / pnpm-workspace.yaml

const gpaph = topo({
  workspacesExtra: ['!packages/foo'],
  cwd: '/path/to/project/root'
})

traverseDeps()

Iterates up to the pkg deps graph.

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

const {packages} = topo({
  workspaces: ['packages/*'],
  cwd: '/path/to/project/root'
})
const pkg = packages['pkg-a']
const cb = async ({name, pkg}: IDepEntry) => {
  await traverseDeps({pkg, packages, cb})
}

await traverseDeps({packages, pkg, cb})

traverseQueue()

Iterates over the queue of packages in the order of their dependencies.

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

const {queue, prev} = await topo({
  workspaces: ['packages/*'],
  cwd: '/path/to/project/root'
})
const cb = async (name: string) => {
  // some async action
}
await traverseQueue({ queue, prev, cb })

iterateDeps()

Walks through the package dependencies and applies the cb() for each.

const results: any[] = []
const manifest = {
  name: 'foo',
  version: '0.0.0',
  dependencies: {
    bar: '1.0.0'
  },
  devDependencies: {
    baz: '2.0.0'
  }
}

iterateDeps(manifest, ({ name, version, scope, deps }) => {
  results.push({ name, version, scope, deps })
})

License

MIT

changelog (log de mudanças)

1.14.1 (2023-12-18)

Fixes & improvements

1.14.0 (2023-08-14)

Features

  • feat: export iterateDeps helper (0eed98f)

1.13.1 (2023-08-14)

Fixes & improvements

  • fix: add missing version to IPackageJson iface (19a9be3)
  • perf: up deps (526d51c)
  • fix: deps revision (86efb9e)

1.13.0 (2023-05-25)

Features

  • feat: add manifestRelPath to IPackageEntry (6949ae0)

1.12.1 (2023-05-24)

Fixes & improvements

  • fix: handle yarn wokspaces.packages directive (979cc99)

1.12.0 (2023-05-24)

Features

  • feat: add workspacesExtra option (0a1c55c)

1.11.0 (2023-05-24)

Features

  • feat: provide support for bolt and pnpm workspaces (b23752c)

1.10.0 (2023-04-08)

Features

  • feat: add manifestRaw field to IPackageEntry (a833ba9)

1.9.2 (2023-04-03)

Fixes & improvements

  • docs: tweak up usage examples (5be06ba)

1.9.1 (2023-04-02)

Fixes & improvements

  • refactor: inner deps iterator (d641f97)

1.9.0 (2023-04-02)

Features

  • feat: add scope field to IDepEntry (0647fcc)

1.8.1 (2023-04-01)

Fixes & improvements

  • fix: add missing iface reexport (57d391a)

1.8.0 (2023-04-01)

Features

  • feat: add traverseDeps and traverseQueue helpers (31c6c78)

1.7.0 (2023-03-28)

Features

  • feat: introduce depFilter option (9a0eeec)

1.6.0 (2023-03-16)

Features

  • feat: mix graph sources to result (fb00824)

1.5.0 (2023-02-24)

Features

  • feat: mix toposource graphs to result (db00d12)

1.4.4 (2023-01-05)

Bug Fixes

  • update fast-glob to v3.2.12 (d414511)

1.4.3 (2022-07-29)

Bug Fixes

  • add missing types field to pkg.json (ece19f3), closes #13

1.4.2 (2022-07-03)

1.4.1 (2022-06-13)

Bug Fixes

  • types: let workspaces field be optional (cfd5713)

1.4.0 (2022-06-13)

Features

  • add abs pkg path to entry data (7271961)
  • add pkg name to entry (f80aa8d)
  • add root pkg entry to context (5d670cc)
  • check pkg names duplicates (6c18d81)

1.3.1 (2022-06-01)

Performance Improvements

1.3.0 (2021-12-29)

Features

1.2.0 (2021-12-27)

Features

  • add pkg manifests to topoContext (117a0b2)

1.1.0 (2021-12-26)

Features

  • add nodes and edges to topoContext (18f60c0)

1.0.0 (2021-12-25)

Bug Fixes

Features

  • add monorepo graph resolver topo (2ae82fa)