Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@glideapps/ts-helper

Package Overview
Dependencies
Maintainers
8
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glideapps/ts-helper

Analyze TypeScript projects

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.4K
increased by3.11%
Maintainers
8
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 25 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc