Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@semrel-extra/topo

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@semrel-extra/topo - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.2.0](https://github.com/semrel-extra/topo/compare/v1.1.0...v1.2.0) (2021-12-27)
### Features
* add pkg manifests to topoContext ([117a0b2](https://github.com/semrel-extra/topo/commit/117a0b2a893d0d164f1db769776c10f8beda8644))
# [1.1.0](https://github.com/semrel-extra/topo/compare/v1.0.0...v1.1.0) (2021-12-26)

@@ -2,0 +9,0 @@

2

package.json
{
"name": "@semrel-extra/topo",
"version": "1.1.0",
"version": "1.2.0",
"description": "Helper to resolve monorepo dependencies graph",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -19,3 +19,4 @@ # @semrel-extra/topo

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

@@ -30,3 +31,15 @@

['pkg-y', 'pkg-x'],
]
],
packages: {
'pkg-a': {
manifest: {
name: 'pkg-a',
dependencies: {}
},
manifestPath: '/absolute/path/to/packages/a/package.json',
path: 'packages/pkg-a'
},
'pkg-b': {...},
...
}
}

@@ -33,0 +46,0 @@ ```

import toposort from 'toposort'
import glob from 'fast-glob'
import {join} from 'path'
import {dirname, join, relative} from 'path'
import {promises} from 'fs'

@@ -21,3 +21,10 @@

export type IPackageEntry = {
manifest: IPackageJson
manifestPath: string
path: string
}
export interface ITopoContext {
packages: Record<string, IPackageEntry>
queue: string[]

@@ -28,9 +35,26 @@ nodes: string[]

export const topo = async (otions: ITopoOtions): Promise<ITopoContext> => {
const manifestsPaths = await getManifestsPaths(otions)
const manifests = await Promise.all(manifestsPaths.map(p => readFile(p, 'utf-8').then(JSON.parse)))
const { edges, nodes } = getGraph(manifests)
export const getPackages = async (options: ITopoOtions): Promise<Record<string, IPackageEntry>> => {
const manifestsPaths = await getManifestsPaths(options)
const manifests: IPackageJson[] = await Promise
.all(manifestsPaths.map(p => readFile(p, 'utf-8')
.then(JSON.parse)))
return manifests.reduce<Record<string, IPackageEntry>>((m, p, i) => {
m[p.name] = {
manifest: p,
manifestPath: manifestsPaths[i],
path: relative(options.cwd, dirname(manifestsPaths[i])),
}
return m
}, {})
}
export const topo = async (options: ITopoOtions): Promise<ITopoContext> => {
const packages = await getPackages(options)
const { edges, nodes } = getGraph(Object.values(packages).map(p => p.manifest))
const queue = toposort.array(nodes, edges)
return {
queue: toposort.array(nodes, edges),
queue,
packages,
edges,

@@ -37,0 +61,0 @@ nodes,

@@ -20,3 +20,3 @@ import { test } from 'uvu'

test('`topo` returns monorepo release queue', async () => {
test('`topo` returns monorepo digest: release queue, deps graph, package manifests', async () => {
const cwd = resolve(fixtures, 'regular-monorepo')

@@ -31,2 +31,28 @@ const workspaces = ['packages/*']

],
packages: {
a: {
manifest: {
name: 'a'
},
manifestPath: join(cwd, 'packages/a/package.json'),
path: 'packages/a'
},
c: {
manifest: {
name: 'c',
dependencies: {
e: '*'
},
},
manifestPath: join(cwd, 'packages/c/package.json'),
path: 'packages/c'
},
e: {
manifest: {
name: 'e'
},
manifestPath: join(cwd, 'packages/e/package.json'),
path: 'packages/e'
}
}
}

@@ -33,0 +59,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc