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-depdraw

v0.1.12

Published

Visualisation of typescript project dependencies.

Downloads

14

Readme

ts-depDraw

Catching a hidden dependency!

Aim

Prototype a novel way to interact and explore your projects dependencies.

Introduction

Typescript was chosen as the language due to the language services that they provide. Due to the opt-in nature of Typescript, dependencies / dependents may be missed if the compiler doesn't recognise them.

The dynamic nature of JavaScript makes discovering some dependency cases very difficult (when looking at token by token cases). This is further compounded by what can be discovered using the Typescript language services.

However the scope of the project isn't to work out the best way to draw these dependencies, but also a novel way to explore your project using the dragonfly view. The Dragonfly view allows you to traverse your dependencies while keeping a history of your path. If you want to further visualise your path, it is then drawn into a network view, where all the tokens are checked for dependencies between one another.

This helps reveal any hidden dependencies that you might not have seen.

Finally if there is an issue or something that you want to highlight, the diagram is savable and thus shared with others (without needing to share your project files).

Installation

Install with npm install -g ts-depdraw. using npm to install ts-depdraw

Start Server:

    Usage: ts-depDraw <file path>

    Current limitations:
        - Requires you to initialize the program from the
          directory containing tsconfig.json.

    Options:

    -h, --help           output help

This will start the server that traverses your project.

Example initiation:

If you have a project with the structure:

.
├── src
│   └── app.ts
└── tsconfig.json

You must start the server from the folder with the tsconfig.json and with the filepath of a .ts file.

In this case we'll start the server on app.ts.

ts-depDraw src/app.ts

Exploring your code

Let's explore a simple single file example (multiple files are supported).

Continuing on from the above example, imagine app.ts has the following code:

function A(){
    return "Hello";
}

function B(){
    return A() + "World!"
}

When the server starts it will open the browser to http://localhost:8080/ and you'll be greeted by the following screen:

Welcome screen

If you've got a saved diagram, you can load it, otherwise just press continue.

UI

Blank UI

Notice your code appears at the bottom. The blank space is where the diagram will be created.

As you explore, additional files may be traversed and they'll be added next to the current one (src/app.ts).

In this case we want to check what dependencies function B has.

dragonfly popup

Instead of just clicking tokens, we can also click the dependencies and dependents in the dragonfly popup.

This will build up a path (or dragonfly tail) of the tokens you've traversed.

Building Dragonfly tail

Clicking the dragonfly's tail or path will commit them to the diagram. When nodes are added to the diagram, all dependencies between the committed nodes are added.

This allows you to discover hidden dependencies between tokens.

In this example we click on the functions in the order A() -> B() -> C(), and the dependency between C and A is picked up.

Commiting

Finding nodes in code

Just click on the node in the diagram to be taken to the token in the code.

Removing a node

Double click on a node to remove it from the diagram.

Contribution

I need help making it presentable. If this idea excites you, please contact me on twitter.

Contribution to frontend

To work on the frontend you'll need to clone this frontend repo.

Contribution to backend

Clone this repo.

npm install

To run:

npm start <filePath> is the same as ts-depDraw <filePath>

Testing

npm test

High level architecture

High level cloud architecture of ts-depdraw

Task list

  • [x] Get text from file.
  • [x] Get token information from file.
  • [x] Get rough dependencies for a token.
  • [x] Get rough dependents for a token.
  • [x] Create frontend repo.
  • [ ] Fix tests so that things are legit.
  • [x] Share/[Save/Load] diagram
  • [ ] Able to add text nodes
  • [x] Fix edge between the same node.
  • [x] All edges added between nodes
  • [ ] Add projectless server to allow loading of other projects.
  • [x] Integrate front end with backend.
  • [x] Refactor end points in front end to be easily changed.
  • [ ] Refactor end points in back end to be easily changed.
  • [x] Use opn to open browser.
  • [ ] Create completely unique user ID's for sessions (and logging)
  • [x] Set up logging server.
  • [ ] Set up database.
  • [ ] Log to the server.

Known Bugs

  • [ ] Dependencies are anything in scope. Regardless if they are actual dependencies.
  • [ ] If a function is represented in a single line, a scope tree doesn't form properly.
  • [x] Function declaration headers are listed as dependencies.
  • [x] Duplicated dependents for some tokens.
  • [x] tsserver chunks responses which can break JSON parse.
  • [ ] Template literal strings don't tokenize properly.
  • [x] ex5.ts line 1, offset 13 - causes error
  • [ ] Sometimes parameters infinitely nest in the definition dragonfly list.
  • [ ] Large files crash the server when buffering the tsserver responses is required.