Helps you conveniently add packages with their corresponding types to your project.
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 ...
ts-add [-c completion] [-v version] [-h help]
ts-add [options]... package[@version] [[options] [package[@version]]]...
tsa
— forts-add
tsi
— forts-add -i
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. |
- Look into
package.json
file of requested package. If there istypes
ortypings
field orfiles
array includes.d.ts
ending string in it so package has explicit types. Job's done. - 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 topackage.json
versions and may have discrepancies in versions of main package and its@types
. So consider to use-i
flag to avoid this.
- for latest requested package — latest
- If still not found — assume that package has no types.
Use if you want to check what packages are supposed to install without their actual installation.
Use if you want to save main packages into devDependencies.
Similarly to save-dev but save @types
packages into regular dependencies.
Note: you can use -D
and -P
flags at the same time, which means to swap packages install destination.
Install only correspondent @types
packages for requested packages.
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"
}
}
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
.
Include to search pool @types
prerelease package versions such as 2.3.5-beta-1, 3.0.1-rc-4 and so on.
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.
Provide credentials for registry authentication.
tsi my-awesome-module -a=<my-awesome-auth-basic-token>
tsi my-awesome-module -l=<login> -p=<password>
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.
Run tsa -c >> ~/.bashrc
command to append CLI autocomplection into .bashrc
file.
Manually tested by the developer during development. Automated tests are not provided.
Your improve suggestions and bug reports are welcome any time.