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

tsc-absolute

v1.0.1

Published

TypeScript compiler (tsc), but errors have absolute paths

Downloads

8,529

Readme

tsc-absolute

👇 TypeScript compiler (tsc), but errors have absolute paths.

Inspired by this 2016 TypeScript issue, and a similar one opened in 2020. Given it seems to be a feature many people want, but the TypeScript team seem to be avoiding, this acts as a simple wrapper that implements this feature.

This is particularly useful for navigating to errors in monorepo setups, or for automating error detection and location from logs.

Installation

npm install --save-dev typescript tsc-absolute

Usage

Just use it as a drop-in replacement for tsc wherever you use it. All arguments are passed right through. For example:

"scripts": {
-  "build": "tsc --strict"
+  "build": "tsc-absolute --strict"
}

This turns your logs from relative paths:

src/some/path/code.ts(20,9): error TS2322: Type 'number' is not assignable to type 'string'.

to absolute ones:

/home/domdomegg/my-workspace/my-package/src/some/path/code.ts(20,9): error TS2322: Type 'number' is not assignable to type 'string'.

Which TypeScript version does it use?

It supports any version of TypeScript released in the last 12 months, mirroring the TypeScript team's security support window. This is validated with intregration tests that run in CI.

The library accepts TypeScript as a peer dependency, so just install TypeScript like normal to your preferred version and tsc-absolute will use that one.

It may work with older versions, but this is not explicitly supported. You should probably update anyways to ensure you continue to recieve security updates.

GitHub problem matching

With this configuration, you can set up a GitHub problem matcher, for example in .github/matchers/tsc-absolute.json:

{
  "problemMatcher": [
    {
      "owner": "tsc-absolute",
      "pattern": [
        {
          "regexp": "(?:^|\\s)([^\\s][^:]*)[\\(:](\\d+)[,:](\\d+)(?:\\):\\s+|\\s+-\\s+)(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "code": 5,
          "message": 6
        }
      ]
    }
  ]
}

And in your workflow.yaml, add a step:

- name: Configure TSC problem matcher
  run: |
    echo "::remove-matcher owner=tsc::"
    echo "::add-matcher::.github/matchers/tsc-absolute.json"

As an example, when you're done you can get output like this on your commits and PRs: https://github.com/domdomegg/tsc-absolute-github-actions-example/commit/cf254dc82fac7099070fbaa3cd78f83989c70d5a#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80

Accuracy note

This is a best-efforts approach at correcting the error output and is usually very accurate. However, as the TypeScript compiler does not provide structured logging nor is it part of their public interface, it may break if TypeScript's logging format changes.

Additionally, the way the logs are (un)structured the regex can make mistakes if you have extremely odd filenames. The filenames have to be to the point that you'd probably have to be trying to break this, i.e. ones that have both spaces and brackets with numbers at just the wrong places in them - but if you're accepting any kind of input it's one to be aware of.

Contributing

Pull requests are welcomed on GitHub! To get started:

  1. Install Git and Node.js
  2. Clone the repository
  3. Install dependencies with npm install
  4. Run npm run test to run tests
  5. Build with npm run build

Releases

Versions follow the semantic versioning spec.

To release:

  1. Use npm version <major | minor | patch> to bump the version
  2. Run git push --follow-tags to push with tags
  3. Wait for GitHub Actions to publish to the NPM registry.