Skip to content

Commit

Permalink
feat: export iterateDeps helper
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 14, 2023
1 parent 661d402 commit 0eed98f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Maintainability](https://api.codeclimate.com/v1/badges/48b31cd38b905b729beb/maintainability)](https://codeclimate.com/github/semrel-extra/topo/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/48b31cd38b905b729beb/test_coverage)](https://codeclimate.com/github/semrel-extra/topo/test_coverage)

Helper to resolve monorepo dependencies graph by package workspaces
> Helpers to assist monorepo dependencies traversals
## Install
```shell
Expand Down Expand Up @@ -108,5 +108,25 @@ const cb = async (name: string) => {
await traverseQueue({ queue, prev, cb })
```

### `iterateDeps()`
Walks through the package dependencies and applies the `cb()` for each.
```ts
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](./LICENSE)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@semrel-extra/topo",
"version": "1.13.1",
"description": "Helper to resolve monorepo dependencies graph",
"description": "Helpers to assist monorepo dependencies traversals",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/topo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const traverseDeps = async ({
await Promise.all(results)
}

const iterateDeps = (
export const iterateDeps = (
manifest: IPackageJson,
cb: (ctx: IDepEntry & { deps: IPackageDeps }) => any,
scopes = defaultScopes
Expand Down
34 changes: 34 additions & 0 deletions src/test/ts/topo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
topo,
traverseQueue,
traverseDeps,
iterateDeps,
ITopoOptions,
IDepEntry,
IPackageEntry,
Expand Down Expand Up @@ -408,4 +409,37 @@ test('`traversDeps` applies cb up to the deps tree', async () => {
assert.equal(result, expected)
})

test('`iterateDeps` walks through the pkg deps', () => {
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 })
})

assert.equal(results, [
{
name: 'bar',
version: '1.0.0',
scope: 'dependencies',
deps: manifest.dependencies
},
{
name: 'baz',
version: '2.0.0',
scope: 'devDependencies',
deps: manifest.devDependencies
}
])
})

test.run()

0 comments on commit 0eed98f

Please sign in to comment.