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

v2.2.0

Published

A way to visualize which files & types are hurting your TypeScript project compilation time.

Downloads

18

Readme

ts-rank

A way to visualize which files & types are hurting your TypeScript project compilation time.

Usage

Should work on most TypeScript projects:

npm run tsc --noEmit  --generateTrace .tsTrace && npx ts-rank

When using incremental builds, do this to ensure all files are traced:

npm run tsc --noEmit --generateTrace .tsTrace --incremental false --tsBuildInfoFile null && npx ts-rank

Will output something like this:

# 2        705.05 ms (18 % of total metrics) (312 metrics)

  201 ms   StyledComponentBase            ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:167:133
  138 ms   StyledComponentProps           ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:59:9
  115 ms   StyledComponentProps           ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:59:9
  26 ms    StyledComponentBase            ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:167:133
  8 ms     StyledComponent                ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:158:38
  8 ms     StyledComponentBase            ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:167:133
  8 ms     StyledComponentProps           ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:59:9
  7 ms     ReactDefaultizedProps          ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:55:13
  7 ms     Defaultize                     ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:44:65
  7 ms     StyledComponentBase            ../DHI/femo-frontend/node_modules/@types/styled-components/index.d.ts:167:133

# 1        757.79 ms (20 % of total metrics) (5438 metrics)

  22 ms    IModelType                     ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:79:2
  21 ms    named                          ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:81:32
  20 ms    named                          ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:81:32
  14 ms    IModelType                     ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:79:2
  13 ms    named                          ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:81:32
  13 ms    IModelType                     ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:79:2
  12 ms    named                          ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:81:32
  11 ms    IModelType                     ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:79:2
  10 ms    ModelInstanceType              ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:70:20
  9 ms     IModelType                     ../DHI/femo-frontend/node_modules/mobx-state-tree/dist/types/complex-types/model.d.ts:79:2

Further usage:

# Get help info
npx ts-rank --help

# Provide location to the trace files generated by generateTrace
npx ts-rank --TRACE_FILE trace/trace.json --TYPES_FILE trace/types.json

# Use --pattern as a glob to filter rankings based on file path
npx ts-rank --PATTERN "**/someFolder/**"  

Package json scripts:

{
  "scripts": {
    "trace": "tsc --noEmit --generateTrace .tsTrace && npx ts-rank",
    "trace:full": "tsc --noEmit --incremental false --tsBuildInfoFile null --generateTrace .tsTrace && npx ts-rank",
  }
}

How it works / Caveats

Basically sums up durations based on the sturcturedTypeRelatedTo metrics - which is a significant but still only part of the story.

This metric correlates to type compilation time but more importantly for this tool, it contains information on where the type comes from in an easy-to-parse way.

Hopefully this trace info becomes easier to parse in future. Perhaps someone with more experience can contribute further detail.