NPM Install add custom warning message - node.js

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?

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:
https://docs.npmjs.com/cli/deprecate
https://docs.npmjs.com/deprecating-and-undeprecating-packages-or-package-versions
$ 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 some-lib#0.1.5: πŸ™Œ 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

Related

How do I determine what is asking for a specific submodule in yarn install?

I am running code in node 12. There are plans to upgrade, but this is not an option today. I am trying to do a yarn install but somewhere there is some dependency with a dependency of a dependency of camelcase 7.0.0 but, of course, this is not compatible with node 12. So I get
error camelcase#7.0.0: The engine "node" is incompatible with this module. Expected version ">=14.16". Got "12.22.12"
error Found incompatible module.
No yarn.lock is generated, so I can't see what is causing this. Is there a way to see what the yarn dependency tree would be before generating a yarn.lock?
I've tried the following:
% yarn why camelcase#7.0.0
yarn why v1.22.19
[1/4] πŸ€” Why do we have the module "camelcase#7.0.0"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] πŸ” Finding dependency...
error We couldn't find a match!
✨ Done in 1.13s.
% yarn install
yarn install v1.22.19
[1/4] πŸ” Resolving packages...
[2/4] 🚚 Fetching packages...
error camelcase#7.0.0: The engine "node" is incompatible with this module. Expected version ">=14.16". Got "12.22.12"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Yarn doesn't seem to be installing Less and Less-watch-compiler

I am trying to install Less and Less-watch-compiler with Yarn. But I get a command not found when I check the lessc version.
I have OSX 10.11.6 El Capitan
I installed Yarn using Homebrew. I have Yarn version 1.9.4.
Then I used:
yarn global add less
This resulted in:
yarn global v1.9.4
[1/4] πŸ” Resolving packages...
[2/4] 🚚 Fetching packages...
warning Pattern ["less#^3.8.1"] is trying to unpack in the same destination "/Users/jem/Library/Caches/Yarn/v2/npm-less-3.8.1-f31758598ef5a1930dd4caefa9e4340641e71e1d" as pattern ["less#^3.0.4"]. This could result in non-deterministic behavior, skipping.
[----------------------------------------------------------------------------] 0/83(node:1407) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[3/4] πŸ”— Linking dependencies...
[4/4] πŸ“ƒ Building fresh packages...
success Installed "less#3.8.1" with binaries:
- lessc
✨ Done in 1.51s.
Then I used Yarn to get less-watch-compiler. Using the command:
yarn global add less-watch-compiler
That resulted in:
yarn global v1.9.4
[1/4] πŸ” Resolving packages...
[2/4] 🚚 Fetching packages...
[-----------------------------------------------------------------------------------] 0/83(node:1597) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[3/4] πŸ”— Linking dependencies...
[4/4] πŸ“ƒ Building fresh packages...
success Installed "less-watch-compiler#1.11.3" with binaries:
- less-watch-compiler
✨ Done in 1.27s.
After doing this I checked the version of less by typing
lessc β€”version. The result is:
-bash: lessc: command not found
In my ~/Library/Caches/Yarn/v2 directory I can see:
npm-less-3.8.1-f31758598ef5a1930dd4caefa9e4340641e71e1d
npm-less-watch-compiler-1.11.3-eb1fc62423898fae48fde1bed4968bb81bf220f2
I’m not sure if this means that Less was installed.
I saw this question: lessc: command not found
It says I should Export the location of lessc into the PATH. But I need to know where lessc is? But I’m not sure if the above items in the Cache file are the ones I need. I’ve tried removing node, yarn and nvm from my machine. I’ve removed and reinstalled yarn. But I get the same results each time.
Also, on my machine is another program called less. It's a unix page reader. http://www.greenwoodsoftware.com/less/
This has made things confusing.
I’m new to this, and I’ve reached a dead end. Any help is appreciated.
Edit: I also tried to install yarn with npm.
sudo npm i -g yarn
sudo npm i -g less
sudo npm i -g less-watch-compiler
That didn't work either.
Also, when I look for lessc or less-watch-compiler using
$ which lessc
I don't get a response.

Issue with Jhipster upgrade from 4.5.2 to 4.14.1

We are trying to upgrade our jhipster application to the latest version.
We are trying to upgrade manually as referred in the page [http://www.jhipster.tech/2018/02/27/jhipster-release-4.14.1.html][1]
currently our Jhipster version is 4.5.2
after executing the command
yarn global upgrade generator-jhipster
following is the output:
yarn global upgrade generator-jhipster
yarn global v1.5.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Rebuilding all packages...
info Lockfile not saved, no dependencies.
success Saved 0 new dependencies.
Done in 0.11s.
now if I check the Jhipster version it still shows 4.5.2
we want to upgrade to Jhipster 4.14.1
Other Version we use:
node version -> v8.9.4
npm version -> 5.6.0
yarn version -> 1.5.1
What is going wrong in our upgrade steps that we do?
It seems that you actually did not fully follow the release note.
Have you executed the second command ?
jhipster upgrade
EDIT:
If you follow the manual way to update, then have you follow this instruction ?
If you have an existing project, it will still use the JHipster
version with which it was generated. To upgrade your project, you must
first delete its node_modules folder and then run:
jhipster

How to ignore incompatible engine "node" error on installing npm dependencies with yarn?

Given this package.json:
{
"name": "yarn-install-fail",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "2.x.x",
"s3-streams": "^0.3.0"
}
}
I can install the dependencies successfully via npm:
$ npm install
added 27 packages in 1.844s
Yet yarn fails:
$ yarn install
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
error s3-streams#0.3.0: The engine "node" is incompatible with this module. Expected version "^1.2.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
It appears yarn has trouble installing the library s3-streams#0.3.0, yet I assumed it would fallback to install all the dependencies anyway like npm would.
You can indeed ignore such errors via --ignore-engines:
$ yarn install --ignore-engines
yarn install v0.24.5
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 1.41s.
This is also documented in the command's help:
$ yarn help | grep -- --ignore
--ignore-scripts don't run lifecycle scripts
--ignore-platform ignore platform checks
--ignore-engines ignore engines check
--ignore-optional ignore optional dependencies
yarn config set ignore-engines true is a one time fix for the "the engine node is incompatible with this module" problem. Once that is completed, you can do "create-react-app my-app"
--ignore-engines doesn't work with the yarn start command
So there are two solutions for that to get rid of it.
check your node version with:
node -v
check your npm version with:
npm -v
Open package.json and make sure the values you got from running the two commands above match with the versions of node and npm in the engines object.
OR
You can simply remove engines from the package.json file otherwise it will always check the version to match.
add --ignore-engines to remove the errors
$ yarn help
....
--ignore-scripts don't run lifecycle scripts
--ignore-platform ignore platform checks
--ignore-engines ignore engines check
--ignore-optional ignore optional dependencies
....
If you run into this problem, it might be because
you have several versions of node on your system.
For example, you might have run some command that installs an uptodate
version of node in one place, but be running a different version of
node because it's directory is ahead of the other one in $PATH.
So it might be a good idea to run
which -a node
If the nvm version is out-of-date, you could update it, e.g.
to a particular version: nvm install 15.4.0

yo cannot find jhipster after yarn global add generator-jhipster

I'm trying to generate a jHipster project using yarn - https://jhipster.github.io/installation/
I installed Node from its website and yarn with brew.
yarn version 0.19.1
node version v7.5.0
OSX Sierra 10.12.3
When I run yarn global add generator-jhipster, I could see jhispter generator being copied to /Users/{username}/.config/yarn/global/node_modules/
my-mac:~ user$ yarn global add generator-jhipster
yarn global v0.19.1
warning No license field
[1/4] πŸ” Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] πŸ”— Linking dependencies...
[4/4] πŸ“ƒ Building fresh packages...
warning undefined has no binaries
warning No license field
✨ Done in 30.68s.
As the next step, when I run yo jhipster, it cannot find jhipster. However, when I run yarn add generator-jhipster, yo can find jhipster from current folder. Not sure whats wrong with adding in global location.
my-mac:~ user$ echo $PATH
/usr/local/sbin:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/Cellar/node/7.5.0/bin:/Users/{user}/.config/yarn/global/node_modules/.bin
Will appreciate any help in identify whats going on or if there is any issue with latest yarn version.
my-mac:~ user$ yo jhipster
Error jhipster
You don’t seem to have a generator with the name β€œjhipster” installed.
I had the same problem and the cause was my laziness. I did not took time to read the notes of Local installation with Yarn documentation:
Note: if you have problem to use these tools globally, be sure you have $HOME/.config/yarn/global/node_modules/.bin in your path.
On Mac or Linux: export PATH="$PATH:$(yarn global bin):$HOME/.config/yarn/global/node_modules/.bin"
To fix this issue I needed to install yeoman globally with yarn.
yarn global add yo
I am using Ubuntu and I faced this issue too. Then I use sudo to add yo package
sudo yarn global add yo
Hope this will helpful to you.

Resources