Skip to content

Instantly share code, notes, and snippets.

View meeroslav's full-sized avatar
:octocat:
Githubin'

Miroslav Jonaš meeroslav

:octocat:
Githubin'
View GitHub Profile
@meeroslav
meeroslav / script.js
Last active July 15, 2025 13:43
Script to detect circular dependencies and their common culprits
#!/usr/bin/env node
import { readCachedProjectGraph } from '@nx/devkit';
import chalk from 'chalk';
const graph = readCachedProjectGraph();
const adjList = buildAdjList(graph);
const circularChains = findCircularChains(adjList);
/**
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
adjList[node] = [];
matrix[node] = {};
});
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
adjList[node] = [];
const initMatrixValues = {};
for (let j = 0; j < nodes.length; j++) {
initMatrixValues[nodes[j]] = false;
});
matrix[node] = { ...initMatrixValues };
function buildMatrix(graph) {
const dependencies = graph.dependencies;
const nodes = Object.keys(graph.nodes);
const adjList = {};
const matrix = {};
const initMatrixValues = nodes.reduce((acc, value) => {
return { ...acc, [value]: false };
}, {});
function buildMatrix(graph) {
const dependencies = graph.dependencies;
const nodes = Object.keys(graph.nodes);
const adjList = {};
const matrix = {};
const initMatrixValues = nodes.reduce((acc, value) => {
return { ...acc, [value]: false };
}, {});
function buildMatrix(graph) {
const dependencies = graph.dependencies;
const nodes = Object.keys(graph.nodes);
const adjList = {};
const matrix = {};
const initMatrixValues = nodes.reduce((acc, value) => {
return { ...acc, [value]: false };
}, {});
for (let i = 0; i < nodes.length; i++) {
const v = nodes[i];
{
"nodes": {
"project-a": {
// ... other fields
"data": {
// ... other fields
"files": [
{ "file": "packages/project-a/a.ts", "hash": "...", "ext": "ts" },
// ...
]
{
"nodes": {
"project-a": {
// ... other fields
"data": {
// ... other fields
"files": [
{ "file": "packages/project-a/a.ts", "hash": "...", "ext": "ts" },
// ...
]
{
"nodes": {
"project-a": {
// ... other fields
"data": {
// ... other fields
"files": {
"packages/project-a/a": { "file": "packages/project-a/a.ts", "hash": "...", "ext": "ts" },
// ...
}
{
"nodes": {
"project-a": {
// ... other fields
"data": {
// ... other fields
"files": [
{ "file": "packages/project-a/a.ts", "hash": "...", "ext": "ts" },
// ...
]