Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding internal dependency graph (and script) #510

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions dependency-graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
digraph G {
rankdir="TD";

abi [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
account [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
api [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
auth [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
core [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
guard [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
indexer [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
metadata [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
migration [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
multicall [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
network [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
provider [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
relayer [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
sessions [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
signhub [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
utils [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
wallet [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
"ethers@^5.5.2" [shape=hexagon, penwidth=1, fontsize=8.0]
"ethauth@^0.8.1" [shape=hexagon, penwidth=1, fontsize=8.0]
deployer [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
estimator [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
"wallet-contracts@^1.10.0" [shape=hexagon, penwidth=1, fontsize=8.0]
"ethers@^5.7.2" [shape=hexagon, penwidth=1, fontsize=8.0]
"@databeat/tracker@^0.9.1" [shape=hexagon, penwidth=1, fontsize=8.0]
"eventemitter2@^6.4.5" [shape=hexagon, penwidth=1, fontsize=8.0]
"webextension-polyfill@^0.10.0" [shape=hexagon, penwidth=1, fontsize=8.0]
replacer [fillcolor="#e5ccff", style="filled" shape=hexagon, penwidth=1]
"idb@^7.1.1" [shape=hexagon, penwidth=1, fontsize=8.0]
simulator [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
tests [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
"js-base64@^3.7.2" [shape=hexagon, penwidth=1, fontsize=8.0]
waas [fillcolor="#e5ccff", style="filled" shape=hexagon, penwidth=1]
"@aws-sdk/client-cognito-identity-provider@^3.445.0" [shape=hexagon, penwidth=1, fontsize=8.0]
"json-canonicalize@^1.0.6" [shape=hexagon, penwidth=1, fontsize=8.0]
"jwt-decode@^4.0.0" [shape=hexagon, penwidth=1, fontsize=8.0]
"waas-ethers" [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]

abi -> account
core -> account
migration -> account
network -> account
relayer -> account
sessions -> account
utils -> account
wallet -> account
"ethers@^5.5.2" -> account
abi -> auth
account -> auth
api -> auth
core -> auth
"ethauth@^0.8.1" -> auth
indexer -> auth
metadata -> auth
migration -> auth
network -> auth
sessions -> auth
signhub -> auth
wallet -> auth
utils -> auth
abi -> core
account -> guard
core -> guard
signhub -> guard
utils -> guard
"ethers@^5.7.2" -> guard
abi -> migration
core -> migration
wallet -> migration
"ethers@^5.5.2" -> migration
abi -> multicall
network -> multicall
utils -> multicall
core -> network
indexer -> network
relayer -> network
utils -> network
abi -> provider
account -> provider
auth -> provider
core -> provider
migration -> provider
network -> provider
relayer -> provider
utils -> provider
wallet -> provider
"@databeat/tracker@^0.9.1" -> provider
"eventemitter2@^6.4.5" -> provider
"webextension-polyfill@^0.10.0" -> provider
abi -> relayer
core -> relayer
utils -> relayer
core -> sessions
migration -> sessions
replacer -> sessions
"ethers@^5.5.2" -> sessions
"idb@^7.1.1" -> sessions
core -> signhub
"ethers@^5.5.2" -> signhub
"js-base64@^3.7.2" -> utils
abi -> wallet
core -> wallet
network -> wallet
signhub -> wallet
relayer -> wallet
utils -> wallet
utils -> deployer
abi -> estimator
core -> estimator
utils -> estimator
"wallet-contracts@^1.10.0" -> estimator
abi -> replacer
core -> replacer
core -> simulator
"wallet-contracts@^1.10.0" -> simulator
core -> tests
network -> waas
"@aws-sdk/client-cognito-identity-provider@^3.445.0" -> waas
"idb@^7.1.1" -> waas
"json-canonicalize@^1.0.6" -> waas
"jwt-decode@^4.0.0" -> waas
waas -> "waas-ethers"
}
96 changes: 96 additions & 0 deletions internal-dependency-graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
digraph G {
rankdir="TD";

abi [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
account [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
api [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
auth [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
core [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
guard [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
indexer [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
metadata [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
migration [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
multicall [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
network [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
provider [fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]
relayer [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
sessions [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
signhub [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
utils [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
wallet [fillcolor="#e597ff", style="filled" shape=hexagon, penwidth=2]
deployer [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
estimator [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
replacer [fillcolor="#e5ccff", style="filled" shape=hexagon, penwidth=1]
simulator [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
tests [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]
waas [fillcolor="#e5ccff", style="filled" shape=hexagon, penwidth=1]
"waas-ethers" [fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]

abi -> account
core -> account
migration -> account
network -> account
relayer -> account
sessions -> account
utils -> account
wallet -> account
abi -> auth
account -> auth
api -> auth
core -> auth
indexer -> auth
metadata -> auth
migration -> auth
network -> auth
sessions -> auth
signhub -> auth
wallet -> auth
utils -> auth
abi -> core
account -> guard
core -> guard
signhub -> guard
utils -> guard
abi -> migration
core -> migration
wallet -> migration
abi -> multicall
network -> multicall
utils -> multicall
core -> network
indexer -> network
relayer -> network
utils -> network
abi -> provider
account -> provider
auth -> provider
core -> provider
migration -> provider
network -> provider
relayer -> provider
utils -> provider
wallet -> provider
abi -> relayer
core -> relayer
utils -> relayer
core -> sessions
migration -> sessions
replacer -> sessions
core -> signhub
abi -> wallet
core -> wallet
network -> wallet
signhub -> wallet
relayer -> wallet
utils -> wallet
utils -> deployer
abi -> estimator
core -> estimator
utils -> estimator
abi -> replacer
core -> replacer
core -> simulator
core -> tests
network -> waas
waas -> "waas-ethers"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"dev": "preconstruct dev",
"postinstall": "preconstruct dev",
"coverage": "rimraf ./coverage && rimraf ./.nyc_output && nyc pnpm test",
"prepare": "husky install"
"prepare": "husky install",
"dep-graph": "node ./scripts/graph-sequence-internal-dependencies.js ./packages > internal-dependency-graph.dot",
"dep-graph-full": "node ./scripts/graph-sequence-internal-dependencies.js ./packages -e > dependency-graph.dot"
},
"husky": {
"hooks": {
Expand Down
121 changes: 121 additions & 0 deletions scripts/graph-sequence-internal-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
const fs = require('fs').promises
const path = require('path')

// Takes the first command-line argument as the search folder path
const searchFolder = process.argv[2]
const includeExternalDeps = process.argv.includes('-e')

if (!searchFolder) {
console.error('Please provide a folder path as an argument.')
process.exit(1)
}

async function findDependenciesWithSequence() {
try {
const subfolders = await fs.readdir(searchFolder, { withFileTypes: true })

const nodes = new Map()

class Node {
constructor(_name, _isInternal) {
this.name = _name
this.isInternal = _isInternal
this.dependsOn = []
this.dependedOnBy = []
}
}

function getNode(name, isInternal) {
if (!nodes.has(name)) {
nodes.set(name, new Node(name, isInternal))
}
return nodes.get(name)
}

for (const folder of subfolders) {
if (folder.isDirectory()) {
const packageJsonPath = path.join(searchFolder, folder.name, 'package.json')
try {
const packageJson = await fs.readFile(packageJsonPath, 'utf8')
const dependencies = JSON.parse(packageJson).dependencies

if (dependencies) {
for (const [depName, version] of Object.entries(dependencies)) {
const isInternal = depName.includes('0xsequence') && version.includes('workspace')
const leftNode = getNode('@0xsequence/' + folder.name, true)
const rightNode = getNode(`${depName}@${version}`.replace('@workspace:*', ''), isInternal)
leftNode.dependsOn.push(rightNode.name)
rightNode.dependedOnBy.push(leftNode.name)
}
}
} catch (error) {
console.log(`Couldn't read or parse package.json in ${folder.name}: ${error.message}`)
}
}
}

return nodes
} catch (error) {
console.error(`Failed to read directory ${searchFolder}: ${error.message}`)
return new Dictionary()
}
}

function safeNodeName(nodeName) {
let safeName = nodeName.replace('@0xsequence/', '')
safeName =
safeName.includes('@') || safeName.includes('-') || safeName.includes('/') || safeName.startsWith('0x')
? `"${safeName}"`
: safeName
return safeName
}

const graphHeader = `digraph G {
rankdir="TD";
`

const defaultNodeStyle = '[shape=circle, penwidth=1, fontsize=8.0]'
const internalNodeStyle = '[fillcolor="#e5ccff", style="filled" shape=circle, penwidth=1]'
const internalExposedNodeStyle = '[fillcolor="#e597ff", style="filled" shape=circle, penwidth=2]'

findDependenciesWithSequence().then(nodesMap => {
const allNodes = Array.from(nodesMap.values())
console.log(graphHeader)
for (const node of allNodes) {
if (node.name === '@0xsequence/0xsequence') {
continue
}
let style = defaultNodeStyle
if (node.isInternal) {
style = node.dependedOnBy.includes('@0xsequence/0xsequence') ? internalExposedNodeStyle : internalNodeStyle
}
if (node.dependedOnBy.filter(n => n !== '@0xsequence/0xsequence').length > 0) {
style = style.replace('shape=circle', 'shape=hexagon')
}
if(includeExternalDeps || node.isInternal) {
console.log(` ${safeNodeName(node.name)} ${style}`)
}
}
console.log('')
for (const node of allNodes) {
if (node.name === '@0xsequence/0xsequence') {
continue
}
for (const dependent of node.dependsOn) {
if((nodesMap.get(dependent).isInternal && node.isInternal) || includeExternalDeps) {
console.log(` ${safeNodeName(dependent)} -> ${safeNodeName(node.name)}`)
}
}
}
// console.log(` subgraph cluster_l {
// label="LEGEND"
// rankdir="TD"
// `)
// console.log(` "internal package" ${internalNodeStyle}`)
// console.log(` "external dependency" ${defaultNodeStyle.replace('shape=circle', 'shape=hexagon')}`)
// console.log(` "internal dependency and 0xsequence package" ${internalExposedNodeStyle.replace('shape=circle', 'shape=hexagon')}`)
// console.log(` "internal dependency" ${internalNodeStyle.replace('shape=circle', 'shape=hexagon')}`)
// console.log(` "0xsequence package" ${internalExposedNodeStyle}`)
// console.log(` }`)
console.log('}')
})
Loading