How should I got about adding a warning message when a user tries to install a given version of a library?
For example, when you install babel-preset-es2015
you get the following warning:
š Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update!
By inspecting their code I saw they add a deprecated
entry in their package.json as follows:
"deprecated": "š Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.io/env to update! ",
I can easily add that, but I'm not actually deprecating anything. I just want to warn users that they are installing an alpha version and there may be changes in the API.
Question
Is there a similar entry to deprecated
that can do the job?
The npm WARN deprecated message means that the package installed on your project is not recommended for use. This may be due to issues found with the package or it's no longer maintained. You may not even see these packages in your package.
There's not necessarily a way you can do that, or not with given fields like "deprecated"
What you can do, which is a little bit of a workaround, is adding a post-install script, that outputs a string to the console if you mark a version as alpha.
// package.json
{
"version": "1.2.3-alpha.2",
"scripts": {
"postinstall": "node postinstall.js"
}
}
// postinstall.js
const package = require('./package.json')
if (package.version.includes('alpha')) {
console.log('You are using an alpha version. Beware!')
}
Please check out belows:
$ npm deprecate <pkg>[@<version>] <message>
Example:
$ npm deprecate some-lib@"< 1.0.0" "š Thanks for using it. we recommend using new version, 1.x.x. Please check out https://example.com"
then,
$ yarn
yarn install v1.16.0
info No lockfile found.
[1/4] š Resolving packages...
warning [email protected]: š Thanks for using it. we recommend using new version, 1.x.x. Please check out https://example.com
[2/4] š Fetching packages...
[3/4] š Linking dependencies...
[4/4] šØ Building fresh packages...
success Saved lockfile.
āØ Done in 5.25s.
Time: 0h:00m:06s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With