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

@glideapps/ts-helper

v5.0.0

Published

Analyze TypeScript projects

Downloads

102,676

Readme

ts-helper

This is a simple TypeScript tool we use at Glide for two purposes so far:

  1. It finds cyclic imports in our source files. We used to use ESLint's import/no-cycle rule for this, but on our project it's both very slow and sometimes doesn't find existing cycles.
  2. It outputs a dependency graph of all the TypeScript source files in our project which we can use for further analysis.

Caveats

We've only implemented as much as we needed to make this work on our codebase, so there might be cases it doesn't support, or on which it crashes on. If you run into such a case, please considering sending us a PR, or at least report the issue with a reproduction.

A few of the things that are missing, in particular:

  • We don't respect exclude in the project configuration.
  • We only look at import (and export), not require.
  • We treat type import calls such as type X = import("foo").Bar as regular "strong" imports.

Usage

-p|--project TS-PROJECT

Adds a project. TS-PROJECT can be either a directory with a tsconfig.json file in it, or the path to a TypeScript config file. ts-helper will add project references recursively, but you can add more than one root project if you need to.

-r|--root SOURCE-FILE

Adds a root TypeScript source file. This file must be in one of the specified projects. You can add more than one.

-c|--detect-cycles

Runs cycle detection on all the source files reachable from the roots. If it detects a cycle it will print one of the cycles it found and exit with an error status.

Note that it only considers "strong" imports for cycle detection, vs type imports and lazy imports.

-o|--output FILENAME

Outputs a JSON file with the dependency graph.

-v|--verbose

Print messages when it's reading and processing projects.

Example

In our main repository for Glide we have two TypeScript projects - one for the frontend and one for the backend. The frontend one has one root source file and the backend has two - one for the actual backend and one for a CLI. Here's how we run ts-helper to detect cycles in that codebase:

npx "@glideapps/ts-helper" \
    -p ~/Work/glide/functions \
    -r ~/Work/glide/functions/src/cli.ts \
    -r ~/Work/glide/functions/src/index.ts \
    -p ~/Work/glide/app \
    -r ~/Work/glide/app/src/index.tsx \
    -c