Skip to content

Instantly share code, notes, and snippets.

@3rdp
Created March 22, 2020 10:13
Show Gist options
  • Save 3rdp/fd9c52a5936ec8c3f0a8f19fa25a4dbb to your computer and use it in GitHub Desktop.
Save 3rdp/fd9c52a5936ec8c3f0a8f19fa25a4dbb to your computer and use it in GitHub Desktop.
get dependencies of a package in a monorepo
cat depcruise-out.json | ramda .modules 'filter (x) -> /^treemap.src/.test(x.source)' \
'
reduce (m, x) ->
m[x.source] = x.dependencies.map (x) -> x.resolved
return m
, {}
'
# ramda is a dependency, get it at https://www.npmjs.com/package/ramda-cli

Motivation

I have this awesome tool madge. I do

madge --extensions ts,tsx,js,jsx --json .

to get a nice view of local (read non-NPM) dependencies.

I have this awesome tool depcruise. I do

depcruise --output-type json .

to get a thorough view of dependencies (NPM included), summary with some stats and beyond that.

Now, if I write the output from last command to a file, I run the command below to reduce the thorough view to a nice view of all dependencies.

I may also run

madge --extensions ts,tsx,js,jsx --include-npm --json .

but then I get not as nice output, depcruise resolves symlinks which is just what I need working in a lerna monorepo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment