Skip to content

Latest commit

 

History

History
127 lines (95 loc) · 5.77 KB

myREADME.md

File metadata and controls

127 lines (95 loc) · 5.77 KB

Helps you conveniently add packages with their corresponding types to your project.

Synopsis

<pkg.name> [-c completion] [-v version] [-h help]
<pkg.name> [options]... package[@version] [[options] [package[@version]]]...

Aliases

  • tsa — for ts-add
  • tsi — for ts-add -i

Options

Alias, name Type Description
-d, --dry-run boolean Run without installing any packages.
-D, --save-dev boolean Save regular (not @types) packages into devDependencies.
-P, --save-prod boolean Save @types packages into regular dependencies.
-t, --types-only boolean Install only @types packages.
-i, --ignore-package-json boolean Add "latest" tag for all installing packages in case of latest versions are required to install.
--ap, --allow-prerelease boolean Allow to install prerelease versions of @types packages.
-s, --silent boolean Hide output messages.
-r, --registry string Specify any other package registry besides https://registry.npmjs.org (this value can be stored in .npmrc as registry key).
-a, --_auth string Set Auth Basic token for custom registry (this value can be stored in .npmrc as _auth key).
-l, --login string Set Auth Basic username for custom registry (this value can be stored in .npmrc as login key).
-u, --username string Alias for login.
-p, --password string Set Auth Basic password for custom registry (this value can be stored in .npmrc as password key).
-c, --completion boolean Output bash CLI autocompletion alias and exit.
-v, --version boolean Output version information and exit.
-h, --help boolean Display this help and exit.

Searching @types algorithm

  1. Look into package.json file of requested package. If there is types or typings field or files array includes .d.ts ending string in it so package has explicit types. Job's done.
  2. If not — search for @types package. If there is @types package search for its corresponding version:
    • for latest requested package — latest @types package;
    • for any other version — take max satisfying version by <major>.<minor>.x, where <major> and <minor> parts are taken from requested package.
      Notice: if you use <pkg.name> without -i flag packages will be installed according to package.json versions and may have discrepancies in versions of main package and its @types. So consider to use -i flag to avoid this.
  3. If still not found — assume that package has no types.

Examples

<-d, --dry-run|#d>

Use if you want to check what packages are supposed to install without their actual installation.

image

<-D, --save-dev|#D>

Use if you want to save main packages into devDependencies.

image

<-P, --save-prod|#P>

Similarly to save-dev but save @types packages into regular dependencies.

image

Note: you can use -D and -P flags at the same time, which means to swap packages install destination.

image

<-t, --types-only|#t>

Install only correspondent @types packages for requested packages.

image

<-i, --ignore-package-json|#i>

If there are no versions requested for installing packages NPM will rely on version ranges into package.json by default. If you don't want to involve package.json ranges just use -i flag or <pkg.name> -i alias: tsi.

In case of the next dependencies:

{
  "dependencies": {
    "node-fetch": "~2.1.0"
  },
  "devDependencies": {
    "@types/node-fetch": "~2.1.7"
  }
}

image

The --ignore-package-json flag simply add latest tag for packages with no provided versions so NPM doesn't rely on already installed packages in package.json.

image

<--ap, --allow-prerelease|#ap>

Include to search pool @types prerelease package versions such as 2.3.5-beta-1, 3.0.1-rc-4 and so on.

<-r, --registry|#r>

Provide a custrom registry to search for packages.

tsi my-awesome-module -r=https://my-awesome-registry.com

The registry key can also conveniently be stored in the .npmrc file.

<-a, --_auth, -l, --login, -p, --password|#credentials>

Provide credentials for registry authentication.

By Auth Basic token

tsi my-awesome-module -a=<my-awesome-auth-basic-token>

By Basic login + password pair

tsi my-awesome-module -l=<login> -p=<password>

By credential embedded into registry URL

tsi my-awesome-module -r=https://<login>:<password>@my-awesome-registry.com

Keys _auth, login and password can also conveniently be stored in the .npmrc file.

<-c, --completion|#c>

Run tsa -c >> ~/.bashrc command to append CLI autocomplection into .bashrc file.