0.2.1 ā€¢ Published 2 months ago

typle v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

typle

šŸ“¦ Scan and install missing Typescript type definitions for dependencies in package.json.

npm npm bundle size npm bundle size npm download count License

Table of Contents

Features

  • āœ”ļø Highly customazible and easy to use.
  • āœ”ļø Detects whether a library has built-in typings or provided by DefinitelyTyped
  • āœ”ļø Supports multiple package.json files and monorepos.
  • āœ”ļø Matches version of @types with its corresponding package. See here for details.
  • āœ”ļø Installs them with automatically detected package manager or just updates package.json file.

Install

Install package either locally in your project or globally:

# locally
npm install typle --save-dev

# globally
npm install typle -g

Alternatively, use npx directly:

npx typle

Quick start

Run typle in the root of your project with package.json inside it. This will scan package.json for missing typescript declarations and install them:

npx typle

Usage

typle [paths/to/package.json] [--options]

Paths can be either file paths or glob patterns, e.g. typle packages/* when working with a monorepo.

Install command

typle install <package-names> [--options]

Simply install packages with their corresponding type declarations.\ All flags will be passed to a given package manager's options.

Available under alias i.

CLI Help

$ typle -h
typle

Usage
  $ typle [flags...] [patterns...]

Scan and install missing Typescript type definitions for dependencies in 'package.json'.

Commands
  install    Install packages with their corresponding type declarations. (alias: 'i')

Options
  -h, --help                         Show help.
  -v, --version                      Get version.
  --silent                           Run install silently.
  --install                          Whether to install packages automatically or just update package.json.
  --pkg-manager [manager]            Which package manager to use.
  --ignore-packages [packages...]    List of packages to ignore.
  --ignore-deps [deps...]            List of certain dependency fields to ignore e.g. 'dev'.
  --config [path]                    Path to the config file.
  --dry-run                          It won't cause any changes to package.json.

Examples
  $ typle --ignore-packages nodemon eslint
  $ typle packages/*

Options

Options that aren't prefixed with double dash (--) are strictly for CLI.

OptionDescriptionDefault
--silentRun install silently.true
--installWhether to install packages automatically or just update package.json.true
--pkg-managerWhich package manager to use. Allowed: npm, yarn, pnpm or bun.Automatically detected.
--ignore-packagesList of packages to ignore.-
--ignore-depsList of certain dependency fields to ignore, e.g. to ignore devDependencies use --ignore-deps devDependencies or --ignore-deps dev for shorthand.-
--configPath to the config file.-
--dry-runIf specified, it won't make any changes in package.json or install any packages.false
patternsPaths or globs where package.json files will be scanned.-
additionalArgsAdditional arguments for package install.-
-v, --versionShow version.-
-h, --helpShow help.-

Config file

Alternatively, you can use a configuration file instead with the same options in: .typlerc.js file (or any other config file supported) or typleConfig field in your package.json. See lilconfig for more details.\ You might also find use of defineConfig wrapper function that will help you with defining configuration:

// .typlerc.js
import { defineConfig } from 'typle';

export default defineConfig({
    silent: false,
    patterns: 'packages/*',
    ignorePackages: ['nodemon', 'eslint'],
    /** etc... */
});

Supported config file paths

  • package.json
  • .typlerc.js
  • .typlerc.cjs
  • .typlerc.json
  • typle.config.js
  • typle.config.cjs
  • .config/typlerc
  • .config/typlerc.json
  • .config/typlerc.js
  • .config/typlerc.cjs
  • .typlerc.ts
  • .typlerc.mts
  • .typlerc.cts
  • typle.config.ts
  • typle.config.mts
  • typle.config.cts
  • .config/typlerc.ts
  • .config/typlerc.mts
  • .config/typlerc.cts

If you wish to store config in some other file path use --config option.

Monorepos

You can use typle in a monorepo too!

ā””ā”€ā”€ā”€ typle (root folder)
     ā””ā”€ā”€ā”€ packages
     ā”‚    ā”œā”€ā”€ā”€ typle
     ā”‚    ā”œā”€ā”€ā”€ typle-core
     ā”‚    ā””ā”€ā”€ā”€ typle-util
     ā”œā”€ā”€ā”€ .typlerc.json
     ā””ā”€ā”€ā”€ package.json

In this example monorepo, in order to scan every folder in packages directory we can use the following config:

// .typlerc.json
{
    "patterns": "packages/*"
}

Then run typle in the root directory.

Why?

Installing typings manually is just annoying and sometimes quite vague.

Acknowledgements

Typle was heavly inspired by typesync, but with many improvements and new features.

License

MIT šŸ’–