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

@stemn/tsc-path-prefix

v1.0.0

Published

Prefix paths in Typescript compiler output for VS Code terminal path detection.

Downloads

2

Readme

TypeScript Compiler Path Prefixer

CircleCI

Fix VS Code terminal links when using lerna by prefixing file paths in tsc output.

VS Code Demo

Motivation

When building TypeScript packages in a monorepository using lerna, file paths in tsc output are relative to the package folder, not the root folder of the monorepository. This breaks VS Code's terminal hyperlink functionality.

This utility prefixes file paths in tsc output so they are relative to the root of the monorepository and recognized by VS Code.

Install

yarn add --dev tsc-path-prefix

Shell Usage

After invoking tsc in a package with lerna --prefix, pipe it through tsc-path-prefix. The lerna project configuration will be inspected and the tsc output path prefixed with the package path.

yarn lerna build:watch --parallel --prefix | tsc-path-prefix

You can use tsc-path-prefix independently of lerna by supplying a prefix as an argument on invocation:

yarn build:watch --parallel | tsc-path-prefix 'libraries/my-library'

Gotchas

When piping to tsc-path-prefix from lerna the parent shell will have its process.stdout.isTTY set to false causing the underlying chalk library used by lerna not to output colours. Set the FORCE_COLOUR environment variable to force coloured output when piping to tsc-path-prefix.

FORCE_COLOR=1 yarn build:watch --parallel --prefix | tsc-path-prefix

Errors reported by tsc are sent to stderr and not piped downstream via stdout. To redirect tsc stderr to stdout you must invoke lerna with either --paralell or --stream, or use tsc 2>&1 | tsc-path-prefix.

Monorepository Usage

Use tsc-path-prefix in your root package.json scripts:

{
  "devDependencies": {
    "@stemn/tsc-path-prefix": "^0.0.1",
    "lerna": "^3.4.3"
  },
  "lerna": {
    "packages": [
      "libraries/*"
    ],
    "version": "3.4.3"
  },
  "name": "monorepo",
  "scripts": {
    "build:watch": "yarn lerna run build:watch --parallel | tsc-path-prefix"
  }
}

libraries/my-library/package.json

{
  "name": "@monorepo/my-library",
  "devDependencies": {
    "typescript": "^3.1.3"
  },
  "scripts": {
    "build:watch": "tsc --watch"
  }
}

Example

Before

Lerna output will contain tsc paths relative to the root folder of the package.

@monorepo/my-library: [10:08:07 AM] Starting compilation in watch mode...
@monorepo/my-library: src/index.ts:9:6 - error TS2339: Property 'badProperty' does not exist on type 'ITestInterface'.
@monorepo/my-library: 9 test.badProperty = 'error';
@monorepo/my-library:        ~~~~~~~~~~~
@monorepo/my-library: [10:08:12 AM] Found 1 error. Watching for file changes.

After

Lerna output will contain tsc paths relative to the root folder of the monorepository.

@monorepo/my-library: [10:08:07 AM] Starting compilation in watch mode...
@monorepo/my-library: libraries/my-library/src/index.ts:9:6 - error TS2339: Property 'badProperty' does not exist on type 'ITestInterface'.
@monorepo/my-library: 9 test.badProperty = 'error';
@monorepo/my-library:        ~~~~~~~~~~~
@monorepo/my-library: [10:08:12 AM] Found 1 error. Watching for file changes.

Diff

$ tsc

-@monorepo/my-library: src/index.ts:9:6
+@monorepo/my-library: libraries/my-library/src/index.ts:9:6

Testing

git clone [email protected]:stemn/tsc-path-prefix.git
cd tsc-path-prefix
yarn install
yarn test