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

typescript-tooling

v4.1.0

Published

This package helps keep TypeScript configuration and tooling synced up between seperate projects.

Downloads

61

Readme

Typescript Tooling // tst

A tool for creating and managing TypeScript projects with minimal configuration.

Features

TypeScript Tooling...

  • 🛠️ Provides reasonable defaults for TypeScript, TSLint, Jest, and Nodemon
  • 🐉 Uses a monorepo project structure with help from Lerna
  • 📦 Bundles packages into ready-to-use JavaScript with Parcel
  • 🏗️ Installs and saves the devDependencies you need to get up and running
  • 📝 Generates useful NPM scripts for your packages (test, test:watch, dev, and build)

Getting Started

  1. Install and save tst... ignore warnings for missing peerDependencies
npm install --save-dev typescript-tooling
  1. Run the init command...
npx tst init
  1. That's it! Here's a few scripts you can use with the example package...
npm run example:test
npm run example:dev
npm run example:build

Usage

npx tst help

Usage

How does TST work?

Running tst init copies config files for various tools into a new .tst directory in the root of your project. Under the hood, TST's CLI executes normal commands which use those defaults. For example, tst test <package-name> runs the command npx jest packages/<package-name> (which is also echo'ed out for reference). This works since TST creates a jest.config.js at the root of your project which extends .tst/jest.config.js. Settings and commands for other tools operate the same way.

Nothing special is happening here! TST is just a bunch of config files and shortcuts for writing long CLI commands which can always be executed directly without using TST. Since no magic is involved, it's easy to stop using this tool, just move config files from .tst into the project root and add the commands TST generates to the scripts section of your package.json. For example...

// `package.json`

{
  "scripts": {
    "<package-name>:build": "tst build <package-name>"
  }
}

...would become...

// `package.json`

{
  "scripts": {
    "<package-name>:build": "parcel build packages/<package-name>/src/index.ts --out-dir packages/<package-name>/dist --target node"
  }
}

What's in the defaults?

If you're interested in seeing TST's defaults for TypeScript, Lerna, Nodemon, and Jest, check out the configs folder; these files are copied into .tst during a tst init.

Overriding TypeScript and TSLint Settings

TST creates or modifies <tsconfig|tslint>.json in your project root to extend the defaults in the .tst directory...

// `<tsconfig|tslint>.json`

{
  // TST adds this line if it isn't already set
  "extends": "./.tst/<tsconfig|tslint>.json"
}

If you want to add or modify any settings, <tsconfig|tslint>.json behaves just as you'd expect, just modify the file...

// `tslint.json`

{
  "extends": "./.tst/tslint.json",
  "rules": {
    // Allow `console.log`s across all packages
    "no-console": false
  }
}

It's easy to change settings for individual packages too. Imagine you want to enable TypeScript's DOM library for a ui package, you would just need to create packages/ui/tsconfig.json...

// `packages/ui/tsconfig.json`

{
  // Extend the base configuration in your project root
  "extends": "../../tsconfig.json",

  // Change the setting we're interested in...
  "compilerOptions": {
    "lib": ["es2018", "dom"]
  }
}

You can do the same thing for TSLint settings.

Overriding Jest Settings

TST exports a Jest configuration object from .tst/jest.config.js which can be modified and re-exported from your project's jest.config.js...

// `jest.config.js`

module.exports = {
  ...require(".tst/jest.config.js"),

  verbose: true,
  bail: true
};

Working with a Monorepo

TypeScript Tooling is built to be used with Lerna, which means it's easy to separate code into multiple packages within the same project. Want to have independently versioned/deployed types, api, and ui packages? No problem!

Creating a New Package

  1. First, make a new folder at packages/<package-name>

  2. Create packages/<package-name>/package.json and make sure its name field matches <package-name>. For packages only used within your project, make sure to set "private": true. Private packages only require the name and private fields.

  3. TST looks for packages/<package-name>/src/index.ts as the entry point. You can generate NPM scripts (test, test:watch, dev, and build) by running...

npm run tst:scripts

...or...

npx tst scripts

Delegating NPM Scripts to Packages

It's useful to keep all NPM scripts available from the project root so you aren't constantly bouncing around with cd. However, an overly complicated set of NPM scripts in one gigantic package.json isn't so great.

Luckily, Lerna allows you to execute NPM Scripts from any package without leaving the project root. Let's say you want to use Parcel to build deployable bundles for a ui package; you could add the build script in packages/ui/package.json...

// `packages/ui/package.json`

{
  "scripts": {
    "build": "parcel build public/index.html"
  }
}

To enable npm run ui:build from the root, we need to modify the NPM script in the base package.json...

// `package.json`

{
  "scripts": {
    // Use Lerna to execute the NPM script defined in `packages/ui/package.json`
    "ui:build": "lerna run build --stream --scope ui"
  }
}

It's important to note npx tst scripts or npm run tst:scripts won't override scripts you've defined.

Notes

  • Test files are expected to live next to the code they cover are named <module-name>.spec.<ts|tsx>, i.e. Dog.ts would be tested by Dog.spec.ts

  • Run npx tst init after upgrading TST or cloning down a project with TST to ensure .tst is up-to-date

  • You can upgrade dependencies TST relies on, but know that there is no guarentee everything will still work together (normally you can bump major TypeScript versions without problems)

Disclaimer

This is my first usable open-source tool! Any help making TST more "professional" would be greatly appreciated. Please open an issue if you have any comments, suggestions, or feedback...

License

MIT