npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-call-graph

v0.1.0

Published

ts-call-graph

Downloads

30

Readme

ts-call-graph

Automatically generate graphs from source code written in TypeScript/JavaScript using TypeScript language service and its AST.

Sample images are in example directory.

prerequisite

You'll need either dot command to generate call graph, which converts .dot file to particular files like .svg, .png and whatnot, or modern web browser which enables to use hpcc-js-wasm.

If you specify server parameter true or nothing, then you'll use a web browser to generate call graphs in SVG format. If specified server parameter with false, then you'll use dot command, which is supposed to be installed in advance. See the server parameter details shown below.

example image

When executing below command, the following image will be output.

ts-call-graph test/ -d true -f png

test

And other example output images of well-known libraries are under example folders.

color meaning

  • background color

    • standard library which is under node_modules/@types/node and node_modules/typescript/lib

      #adedad

    • other packages under node_modules

      #e6ecfa

  • stroke

    • When a node doesn't have children, even if it has originally holds. For example, when interactive mode, it might remove its children, for sure can be added again.

      #3b82f6

install

npm

npm install ts-call-graph --save-dev
yarn add --dev ts-call-graph

How to generate call graph

  • example
ts-call-graph ./path/to/entry-file.ts -f svg
  • available options
Options:
      --version      Show version number                               [boolean]
  -r, --rootDir      root directory where we'll recursively walk through source
                     files. Default directory is current working directory.
                                                              [string] [default:
                                                          "current working directory"]
  -o, --outDir       output directory                         [string] [default:
                                                   "current working directory/output"]
      --tsconfig     path to tsconfig.json which is TypeScript transpile config
                                                                        [string]
  -f, --format       out put format
      [string] [choices: "jpg", "jpeg", "jpe", "jp2", "pdf", "png", "ps", "ps2",
                           "psd", "sgi", "svg", "svgz", "webp"] [default: "svg"]
  -d, --declaration  is include declaration           [boolean] [default: false]
  -v, --verbose      Use verbose output               [boolean] [default: false]
  -l, --line         The line number where call graph starts            [number]
      --server       Whether you use server to render call graphs or dot
                     command.                          [boolean] [default: true]
      --help         Show help                                         [boolean]
  • ./path/to/entry-file.ts First command line arg, as in entry file or directory where we'll walk through to generate call graph. If this is a directory, We'll all files in the directory, and if a file, just output the only call graphs about the file.

  • rootDir When we output graphviz, this directory will be the base directory. Default value is current working directory. <rootDir>/path/to/entry-file.ts

    example) rootDir parameter will remove the output files' directory names.

~ $ pwd
/Users/xxxx
~ $ ls
test     package.json
~ $ ls test/call-hierarchy
one.ts          three.ts        two.ts
~ $ npm run ts-call-graph ./test/call-hierarchy/
~ $ ls output/test/call-hierarchy/
one.ts#callThreeTwice:4.dot     three.ts#log:8.svg              two.ts#tada:7.dot               two.ts#tada:8.svg
one.ts#callThreeTwice:4.svg     three.ts#print:4.dot            two.ts#tada:7.svg
three.ts#log:8.dot              three.ts#print:4.svg            two.ts#tada:8.do