Last active
September 17, 2021 19:07
-
-
Save philipjfulcher/2802b40d874146dfb0593625497c1c01 to your computer and use it in GitHub Desktop.
Nx Dep Graph script examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as yargs from 'yargs'; | |
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph'; | |
async function main() { | |
const graph = await createProjectGraphAsync(); | |
const libToFind = yargs.argv._[0]; | |
console.log(`These projects depend on ${libToFind}`); | |
Object.values(graph.dependencies).forEach((deps) => { | |
deps.forEach((dep) => { | |
if (dep.target === `npm:${libToFind}`) { | |
console.log(` - ${dep.source}`); | |
} | |
}); | |
}); | |
} | |
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph'; | |
async function main() { | |
const graph = await createProjectGraphAsync(); | |
const packageJson = require('../package.json'); | |
const packageRecord: { [key: string]: number } = {}; | |
Object.keys(graph.dependencies).forEach((projectName) => { | |
const deps = graph.dependencies[projectName]; | |
const libNames = deps | |
.filter((dep) => dep.target.startsWith('npm')) | |
.map((dep) => dep.target); | |
libNames.forEach((libName) => { | |
if (packageRecord[libName] === undefined) { | |
packageRecord[libName] = 1; | |
} else { | |
packageRecord[libName]++; | |
} | |
}); | |
}); | |
Object.keys(packageJson.dependencies).forEach((libName) => { | |
if (!packageRecord[`npm:${libName}`]) { | |
console.log(libName); | |
} | |
}); | |
} | |
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createProjectGraphAsync } from '@nrwl/workspace/src/core/project-graph'; | |
import * as yargs from 'yargs'; | |
async function main() { | |
const graph = await createProjectGraphAsync(); | |
const libToFind = yargs.argv._[0]; | |
console.log(`Dependencies of lib ${libToFind}`); | |
graph.dependencies[libToFind].forEach((dep) => { | |
console.log(` - ${dep.target}`); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment