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

merge-tsconfigs

v0.2.2

Published

Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want 🛣️

Downloads

41

Readme

Merge-Tsconfigs

Typed with TypeScript npm version unpkg skypack ci Github Twitter

Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want. 💪


Why do I want this? | Example | How do I use this? | CLI API | Node API | How do I start using this?


Why do I want this?

Tsconfig files are copied, pasted, or left as out-of-sync widows 😥 throughout projects. Merge-tsconfigs provides a CLI and node functions to merge tsconfigs files and compilerOptions into the single tsconfig file you want at a given time.

For example, if you have a monorepo with multiple packages and you want to deploy one of them with a single tsconfig, you might need to copy a tsconfig from root, or write another static tsconfig just for deployment. Well, with Merge-tsconfigs you can run the CLI to write a temporary tsconfig to be used for deployment.

By providing an easy way to create the tsconfig you want, your everyday tsconfig code remains the same, your dockerfiles require less context into other directories, and your deployment process is dynamically more exact.


For example

By running merge-tsconfigs ./tsconfig.build.json you'll merge tsconfig.json

{
  "compilerOptions": {
    "allowJS": true
  }
}

and, tsconfig.build.json

{
  "compilerOptions": {
    "target": "esnext"
  },
  "extends": "./tsconfig.json"
}

into tsconfig.merged.json

{
  "compilerOptions": {
    "allowJS": true,
    "target": "esnext"
  }
}

Which you can now use for deployment, dockerfiles, or any other use case. And, you don't have to worry about copying, pasting, or keeping track of multiple tsconfigs! 🎉


How do I use this?

Merge-tsconfigs is built to be uses as a CLI first and foremost. It also exports node functions which can be used to preform the same merge operation.


CLI API

Listed below are the CLI options and arguments to execute merge-tsconfigs. To *view all cli options in your browser, run merge-tsconfigs --help!

Usage: merge-tsconfigs [options] [files...]

Merge-tsconfigs is a CLI and node tool for merging tsconfig files into the exact tsconfig file you want 🛣️

Arguments:
  files                       files to check, matches an array pattern

Options:
  -o, --out [out]             output file
  -i, --include [include...]  files to include, matches a glob or array pattern
  -e, --exclude [exclude...]  files to exclude, matches a glob or array pattern
  -p, --path <path>           a json parseable string wrapped object, e.g. {"item/*": ["foo": "bar"]}
  -h, --help                  display help for command

*compilerOptions are not added above for readability (but they can be leveraged). To view all cli options, run merge-tsconfigs --help! compilerOptions.paths is a string wrapped object.

Recipes

Merge tsconfig files into a single tsconfig

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json

Merge tsconfig files a specific tsconfig file

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --out ./tsconfig.out.json
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json

Merge tsconfig files with unique include and exclude strings

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --include 'src/**.ts' --exclude 'test/**.ts'
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
// tsconfig.merged.json
{
  "compilerOptions": {
    // ...options
  },
  "include": ["src/**.ts"],
  "exclude": ["test/**.ts", "config/*.ts"]
}

Merge tsconfig files with unique include and exclude or by using arrays

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --include 'src/**.ts' --exclude 'test/**.ts' 'config/*.ts'
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
// tsconfig.merged.json
{
  "compilerOptions": {
    // ...options
  },
  "include": ["src/**.ts"],
  "exclude": ["test/**.ts", "config/*.ts"]
}

Sprinkle in some compilerOptions to the mix

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --out ./tsconfig.out.json --allowJs true --noEmit true
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json
// tsconfig.out.json
{
  "compilerOptions": {
    "allowJS": true,
    "noEmit": true,
  }
}

Delete a compiler option

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --allowJS --noEmit 'delete'
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
// tsconfig.merged.json
{
  "compilerOptions": {
    "allowJS": true,
    // "noEmit": true, // deleted
  }
}

Add a path to compilerOptions.paths

merge-tsconfigs ./tsconfig.json ./tsconfig.build.json --path '{"item/*": ["foo": "bar"]}'
# ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json
// tsconfig.merged.json
{
  "compilerOptions": {
    "paths": {
      "item/*": ["foo": "bar"]
    }
  }
}

Node API

The node API works exactly the same as the CLI API.

import mergeTsconfigs from 'merge-tsconfigs';

mergeTsconfigs({
  files: ['./tsconfig.json', './tsconfig.build.json'],
  out: './tsconfig.out.json',
  include: ['src/**.ts'],
  exclude: ['test/**.ts'],
  compilerOptions: {
    allowJs: true,
    noEmit: true,
  },
});

You can use any compiler options provided by Typescript. Object keys aren't currently implemented but can be upon feature request.

Recipes

Merge tsconfig files into a single tsconfig

const config = mergeTsconfigs({
  files: ['./tsconfig.json', './tsconfig.build.json'],
});
// ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.merged.json

Merge tsconfig files into a custom output file

const config = mergeTsconfigs({
  files: ['./tsconfig.json', './tsconfig.build.json'],
  out: './new-dir/tsconfig.out.json',
});
// ./tsconfig.json + ./tsconfig.build.json => ./tsconfig.out.json

How do I start using this?

Install merge-tsconfigs with your preferred package manager.

npm install merge-tsconfigs --save-dev

*Untested: In, Deno, Snowpack, or other options, you can import merge-tsconfigs directly into your project.

import mergeTsconfigs from 'npm:merge-tsconfigs';
// or
import mergeTsconfigs from "https://cdn.skypack.dev/merge-tsconfigs@latest";
// or
import mergeTsconfigs from "https://unpkg.com/merge-tsconfigs@latest/dist/index.js";

Made by @yowainwright, MIT 2023