Skip to content

Instantly share code, notes, and snippets.

@philipjfulcher
Last active September 17, 2021 19:07
Show Gist options
  • Save philipjfulcher/2802b40d874146dfb0593625497c1c01 to your computer and use it in GitHub Desktop.
Save philipjfulcher/2802b40d874146dfb0593625497c1c01 to your computer and use it in GitHub Desktop.
Nx Dep Graph script examples
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();
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();
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