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

update-ts-references

v3.4.0

Published

Updates TypeScript references automatically while using workspaces

Downloads

47,178

Readme

Test

update-ts-references

If your repository is a multi package repository (via lerna.js, yarn workspaces, pnpm workspaces or since v7 npm workspaces) in combination with project references from TypeScript, this tool will be very helpful by reading dependencies out of the package.json and applying them to the tsconfig.json as references.

There's a blog post that's a good introduction to it Optimizing multi-package apps with TypeScript Project References.

Usage

You can just use it via npx

npx update-ts-references --help

  Usage: update-ts-references [options]

  Options:
    --configName    The name of the config files which needs to be updated. Default: tsconfig.json
    --rootConfigName    The name of the root config file which needs to be updated. Default: tsconfig.json
    --withoutRootConfig  If you will not have a tsconfig in the root directory or don't want to update it. Default: false
    --check         Checks if updates would be necessary (without applying them)
    --help          Show help
    --createTsConfig  Create default TS configs for packages where the main entry in the package.json have a ts|tsx extension (Note: respects the --configName parameter)
    --createPathMappings Create paths mappings under compilerOptions for a better IDE support. It respects the rootDir if no rootDir available it falls back to "src"
    --cwd           Set working directory. Default: /Users/john-doe/projects/my-project
    --verbose       Show verbose output. Default: false
    --usecase       Use a specific usecase configuration. Default: update-ts-references.yaml
    --strict    Expects always a tsconfig.json in the package directory. Default: false

or you add it as dev dependency and include it in the postinstall script in the package.json

yarn add update-ts-references --dev -W

 "scripts": {
   "postinstall": "update-ts-references"
 },
 "husky": {
    "hooks": {
      "pre-push": "update-ts-references --check"
    }
  },

enable pre-push via husky

npx husky add .husky/pre-push "npx update-ts-references --check"
git add .husky/pre-push

using --createTsConfig

Creates a basic tsconfig file for each package where the main entry in the package.json have a .ts or .tsx extension. It will respect the --configName parameter.

The output for the created file looks like the following

{
  "extends": "../tsconfig.base.json", // add's extends in case you have a base config in the root directory 
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "src"
  },
  "references": [ // will be added after running update-ts-references 
    {
      "path": "../some-other-package"
    }
  ]
}

using --createPathMappings

will create path mappings under compilerOptions for a better IDE support. It assumes the source files are under src.

{
  "extends": "../tsconfig.base.json", // add's extends in case you have a base config in the root directory 
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "src",
    "paths": { // will be added after running update-ts-references with --createPathMappings
      "@my-project/some-other-package": ["../some-other-package/src"]
    }
  },
  "references": [ // will be added after running update-ts-references 
    {
      "path": "../some-other-package"
    }
  ]
}

using update-ts-references.yaml for configurations

You can configure workspace paths via the update-ts-references.yaml file. This is useful if your repo is having no package.json or pnp-workspace.yaml in the root folder. Additional to that it can also being used to extend the paths config next to the normal workspace setup via npm, pnpm, yarn and lerna so you can include or exclude some packages.

Additional to that you can configure also the following options:

  • configName (default: tsconfig.json)
  • rootConfigName (default: tsconfig.json)
  • createPathMappings (default: false)
  • withoutRootConfig (default: false)

Example configuration see here

using multiple configurations for different usecases

Executing update-ts-references with different configurations via the parameter --usecase.

FAQ

Why is my pnpm workspace alias not working?

update-ts-references is currently not supporting Referencing workspace packages through aliases yet. See issue #13

License

Copyright 2023 mobile.de Developer: Mirko Kruschke

Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.