Skip to content

ArthurKa/ts-add

Repository files navigation

All dependencies Reported vulnerabilities Commits NPM-version Total downloads Developed by
Publish size Install size Minified size Minified + gzipped size

ts-add@1.2.0

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

Installation

ts-add is available via NPM and recomended to install globally:

$ npm i -g ts-add@1.2.0

You can also use ts-add via NPX without explicit installation:

$ npx ts-add ...

Synopsis

ts-add [-c completion] [-v version] [-h help]
ts-add [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 ts-add 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

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

image

-D, --save-dev

Use if you want to save main packages into devDependencies.

image

-P, --save-prod

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

Install only correspondent @types packages for requested packages.

image

-i, --ignore-package-json

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 ts-add -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

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

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

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

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

Testing

Manually tested by the developer during development. Automated tests are not provided.


Your improve suggestions and bug reports are welcome any time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published