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

provide a way to list lerna deps as an adjacency matrix #1970

Closed
wants to merge 3 commits into from

Conversation

yacineb
Copy link

@yacineb yacineb commented Mar 10, 2019

Description

For large monorepo there is a need to show packages dependencies , i added a 'graph' option to lerna 'list' command in order to print out a json showing dependencies for each package.

Dependency graph could then be rendered using a nice tool such as https://www.npmjs.com/package/dependo

Types of changes

  • [ x] New feature (non-breaking change which adds functionality)

Checklist:

  • [ x] My code follows the code style of this project.
  • [ x] My change requires a change to the documentation.
  • [ x] I have updated the documentation accordingly.
  • [ x ] I have read the CONTRIBUTING document.
  • [ x] I have added tests to cover my changes.
  • [ x] All new and existing tests passed.

@evocateur
Copy link
Member

This seems a bit too special-cased to be a top-level CLI option, better suited for a third-party tool that reuses existing lerna packages. lerna ls isn't meant to be a general replacement for npm ls, and only deals with a small subset of metadata. Lerna's PackageGraph would even do most of the collation for you.

#!/usr/bin/env node

const { getPackages } = require('@lerna/project');
const PackageGraph = require('@lerna/package-graph');

(async function () {
  const cwd = process.cwd(); // or process.argv?
  const pkgs = await getPackages(cwd);
  const graph = new PackageGraph(pkgs);
  const json = {};

  graph.forEach((node, name) => {
    json[name] = [
      ...node.externalDependencies.keys(),
      ...node.localDependencies.keys(),
    ].sort();
  });

  console.log(JSON.stringify(json, null, 2));
})();

Copy that code, paste it into a script file, and you can get output like this (when run on the lerna source):

Adjacency graph of lerna/lerna

{
  "@lerna/add": [
    "@lerna/bootstrap",
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/npm-conf",
    "@lerna/validation-error",
    "dedent",
    "npm-package-arg",
    "p-map",
    "pacote",
    "semver"
  ],
  "@lerna/bootstrap": [
    "@lerna/batch-packages",
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/has-npm-version",
    "@lerna/npm-install",
    "@lerna/package-graph",
    "@lerna/pulse-till-done",
    "@lerna/rimraf-dir",
    "@lerna/run-lifecycle",
    "@lerna/run-parallel-batches",
    "@lerna/symlink-binary",
    "@lerna/symlink-dependencies",
    "@lerna/validation-error",
    "dedent",
    "get-port",
    "multimatch",
    "npm-package-arg",
    "npmlog",
    "p-finally",
    "p-map",
    "p-map-series",
    "p-waterfall",
    "read-package-tree",
    "semver"
  ],
  "@lerna/changed": [
    "@lerna/collect-updates",
    "@lerna/command",
    "@lerna/listable",
    "@lerna/output",
    "@lerna/version"
  ],
  "@lerna/clean": [
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/prompt",
    "@lerna/pulse-till-done",
    "@lerna/rimraf-dir",
    "p-map",
    "p-map-series",
    "p-waterfall"
  ],
  "@lerna/create": [
    "@lerna/child-process",
    "@lerna/command",
    "@lerna/npm-conf",
    "@lerna/validation-error",
    "camelcase",
    "dedent",
    "fs-extra",
    "globby",
    "init-package-json",
    "npm-package-arg",
    "p-reduce",
    "pacote",
    "pify",
    "semver",
    "slash",
    "validate-npm-package-license",
    "validate-npm-package-name",
    "whatwg-url"
  ],
  "@lerna/diff": [
    "@lerna/child-process",
    "@lerna/command",
    "@lerna/validation-error",
    "npmlog"
  ],
  "@lerna/exec": [
    "@lerna/batch-packages",
    "@lerna/child-process",
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/run-parallel-batches",
    "@lerna/validation-error"
  ],
  "@lerna/import": [
    "@lerna/child-process",
    "@lerna/command",
    "@lerna/prompt",
    "@lerna/pulse-till-done",
    "@lerna/validation-error",
    "dedent",
    "fs-extra",
    "p-map-series"
  ],
  "@lerna/init": [
    "@lerna/child-process",
    "@lerna/command",
    "fs-extra",
    "p-map",
    "write-json-file"
  ],
  "@lerna/link": [
    "@lerna/command",
    "@lerna/package-graph",
    "@lerna/symlink-dependencies",
    "p-map",
    "slash"
  ],
  "@lerna/list": [
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/listable",
    "@lerna/output"
  ],
  "@lerna/publish": [
    "@lerna/batch-packages",
    "@lerna/check-working-tree",
    "@lerna/child-process",
    "@lerna/collect-updates",
    "@lerna/command",
    "@lerna/describe-ref",
    "@lerna/log-packed",
    "@lerna/npm-conf",
    "@lerna/npm-dist-tag",
    "@lerna/npm-publish",
    "@lerna/output",
    "@lerna/pack-directory",
    "@lerna/prompt",
    "@lerna/pulse-till-done",
    "@lerna/run-lifecycle",
    "@lerna/run-parallel-batches",
    "@lerna/validation-error",
    "@lerna/version",
    "figgy-pudding",
    "fs-extra",
    "libnpmaccess",
    "npm-package-arg",
    "npm-registry-fetch",
    "npmlog",
    "p-finally",
    "p-map",
    "p-pipe",
    "p-reduce",
    "pacote",
    "semver"
  ],
  "@lerna/run": [
    "@lerna/batch-packages",
    "@lerna/command",
    "@lerna/filter-options",
    "@lerna/npm-run-script",
    "@lerna/output",
    "@lerna/run-parallel-batches",
    "@lerna/timer",
    "@lerna/validation-error",
    "p-map"
  ],
  "@lerna/version": [
    "@lerna/batch-packages",
    "@lerna/check-working-tree",
    "@lerna/child-process",
    "@lerna/collect-updates",
    "@lerna/command",
    "@lerna/conventional-commits",
    "@lerna/github-client",
    "@lerna/output",
    "@lerna/prompt",
    "@lerna/run-lifecycle",
    "@lerna/validation-error",
    "chalk",
    "dedent",
    "minimatch",
    "npmlog",
    "p-map",
    "p-pipe",
    "p-reduce",
    "p-waterfall",
    "semver",
    "slash",
    "temp-write"
  ],
  "@lerna/child-process": [
    "chalk",
    "execa",
    "strong-log-transformer"
  ],
  "@lerna/cli": [
    "@lerna/global-options",
    "dedent",
    "npmlog",
    "yargs"
  ],
  "@lerna/command": [
    "@lerna/child-process",
    "@lerna/package-graph",
    "@lerna/project",
    "@lerna/validation-error",
    "@lerna/write-log-file",
    "dedent",
    "execa",
    "is-ci",
    "lodash",
    "npmlog"
  ],
  "@lerna/conventional-commits": [
    "@lerna/validation-error",
    "conventional-changelog-angular",
    "conventional-changelog-core",
    "conventional-recommended-bump",
    "fs-extra",
    "get-stream",
    "npm-package-arg",
    "npmlog",
    "pify",
    "semver"
  ],
  "@lerna/filter-options": [
    "@lerna/collect-updates",
    "@lerna/filter-packages",
    "dedent"
  ],
  "@lerna/global-options": [],
  "lerna": [
    "@lerna/add",
    "@lerna/bootstrap",
    "@lerna/changed",
    "@lerna/clean",
    "@lerna/cli",
    "@lerna/create",
    "@lerna/diff",
    "@lerna/exec",
    "@lerna/import",
    "@lerna/init",
    "@lerna/link",
    "@lerna/list",
    "@lerna/publish",
    "@lerna/run",
    "@lerna/version",
    "import-local",
    "npmlog"
  ],
  "@lerna/package-graph": [
    "@lerna/validation-error",
    "npm-package-arg",
    "semver"
  ],
  "@lerna/package": [
    "load-json-file",
    "npm-package-arg",
    "write-pkg"
  ],
  "@lerna/project": [
    "@lerna/package",
    "@lerna/validation-error",
    "cosmiconfig",
    "dedent",
    "dot-prop",
    "glob-parent",
    "globby",
    "load-json-file",
    "npmlog",
    "p-map",
    "resolve-from",
    "write-json-file"
  ],
  "@lerna/prompt": [
    "inquirer",
    "npmlog"
  ],
  "@lerna/validation-error": [
    "npmlog"
  ],
  "@lerna/batch-packages": [
    "@lerna/package-graph",
    "@lerna/validation-error",
    "npmlog"
  ],
  "@lerna/check-working-tree": [
    "@lerna/describe-ref",
    "@lerna/validation-error"
  ],
  "@lerna/collect-updates": [
    "@lerna/child-process",
    "@lerna/describe-ref",
    "minimatch",
    "npmlog",
    "slash"
  ],
  "@lerna/create-symlink": [
    "cmd-shim",
    "fs-extra",
    "npmlog"
  ],
  "@lerna/describe-ref": [
    "@lerna/child-process",
    "npmlog"
  ],
  "@lerna/filter-packages": [
    "@lerna/validation-error",
    "multimatch",
    "npmlog"
  ],
  "@lerna/get-npm-exec-opts": [
    "npmlog"
  ],
  "@lerna/get-packed": [
    "fs-extra",
    "ssri",
    "tar"
  ],
  "@lerna/github-client": [
    "@lerna/child-process",
    "@octokit/plugin-enterprise-rest",
    "@octokit/rest",
    "git-url-parse",
    "npmlog"
  ],
  "@lerna/has-npm-version": [
    "@lerna/child-process",
    "semver"
  ],
  "@lerna/listable": [
    "@lerna/batch-packages",
    "chalk",
    "columnify"
  ],
  "@lerna/log-packed": [
    "byte-size",
    "columnify",
    "has-unicode",
    "npmlog"
  ],
  "@lerna/map-to-registry": [
    "npm-package-arg",
    "npmlog"
  ],
  "@lerna/npm-conf": [
    "config-chain",
    "pify"
  ],
  "@lerna/npm-dist-tag": [
    "figgy-pudding",
    "npm-package-arg",
    "npm-registry-fetch",
    "npmlog"
  ],
  "@lerna/npm-install": [
    "@lerna/child-process",
    "@lerna/get-npm-exec-opts",
    "fs-extra",
    "npm-package-arg",
    "npmlog",
    "signal-exit",
    "write-pkg"
  ],
  "@lerna/npm-publish": [
    "@lerna/run-lifecycle",
    "figgy-pudding",
    "fs-extra",
    "libnpmpublish",
    "npmlog",
    "pify",
    "read-package-json"
  ],
  "@lerna/npm-run-script": [
    "@lerna/child-process",
    "@lerna/get-npm-exec-opts",
    "npmlog"
  ],
  "@lerna/output": [
    "npmlog"
  ],
  "@lerna/pack-directory": [
    "@lerna/get-packed",
    "@lerna/package",
    "@lerna/run-lifecycle",
    "figgy-pudding",
    "npm-packlist",
    "npmlog",
    "tar",
    "temp-write"
  ],
  "@lerna/pulse-till-done": [
    "npmlog"
  ],
  "@lerna/resolve-symlink": [
    "fs-extra",
    "npmlog",
    "read-cmd-shim"
  ],
  "@lerna/rimraf-dir": [
    "@lerna/child-process",
    "npmlog",
    "path-exists",
    "rimraf"
  ],
  "@lerna/run-lifecycle": [
    "@lerna/npm-conf",
    "figgy-pudding",
    "npm-lifecycle",
    "npmlog"
  ],
  "@lerna/run-parallel-batches": [
    "p-map",
    "p-map-series"
  ],
  "@lerna/symlink-binary": [
    "@lerna/create-symlink",
    "@lerna/package",
    "fs-extra",
    "p-map"
  ],
  "@lerna/symlink-dependencies": [
    "@lerna/create-symlink",
    "@lerna/resolve-symlink",
    "@lerna/symlink-binary",
    "fs-extra",
    "p-finally",
    "p-map",
    "p-map-series"
  ],
  "@lerna/timer": [],
  "@lerna/write-log-file": [
    "npmlog",
    "write-file-atomic"
  ]
}

@stale
Copy link

stale bot commented Apr 11, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants