package.json engines field with tilde followed by greater than sign (~>) - javascript

If a package.json file has an engines field like this:
"engines" : {
"node" : "~>12"
},
What does the ~> mean?

engines Sets which versions of Node.js and other commands this package/app work on
example:
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0",
"yarn": "^0.13.0"
}
So if you see ~>12.0.1 it means to install version 12.0.1 or the latest patch version such as 12.0.4

Related

Yarn Install - how to force the latest minor version and patch of node (10.x.x)

I have a Node app that is tested on node 10. I am using yarn as a dependency manager. As my app test is run on CI with the latest version of node 10, I want to make sure that all developers have installed the latest 10.x.x version when running any yarn command.
For example, let's say the current latest node version is 10.22.1, then I want to stop the yarn install if the developer is on 10.22.0 or 10.11.1.
Using the engine directive in package.json I tried the following syntax but no avail.
{
"engines": {
"node": "^10.x.x",
}
}
{
"engines": {
"node": "^10",
}
}
{
"engines": {
"node": ">10.0.0 <11.0.0",
}
}
{
"engines": {
"node": "10",
}
}
All of these allow any node with major version 10.
As per the yarn documentation (https://classic.yarnpkg.com/en/docs/package-json/), the preinstall is called before the package is installed.
If defined, the preinstall script is called by yarn before your package is installed.
So I would go with something like this in your package.json:
"scripts": {
....
"preinstall": "./scripts/preinstall.sh",
}
Your preinstall.sh could be:
#!/bin/bash
currentver="$(node -v)"
requiredver="v10.0.0"
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then
echo "Version is good so let's go with install"
else
echo "Please install the node version greater than v10.0.0"
exit -1
fi
So if your developer has a version less than v10.0.0, the above script will fail and will in turn fail the yarn install command.
Note: Credit to https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script for shell script for version comparison.
As we have in the npm doc :
to specify acceptable version ranges up to 1.0.4, use the following syntax:
Patch releases: 1.0 or 1.0.x or ~1.0.4
Minor releases: 1 or 1.x or ^1.0.4
Major releases: * or x
So, if you want to ask for only the 10.22.1 version or newer you should use ~10.22.1 or ^10.22.1
And it's another option to pin the version (you can read more about it from this link) by using the exact version like:
{
"engines": {
"node": "10.22.1",
}
}

Engines field is required but was not found in functions\package.json

I have this error. Please help me.
Engines field is required but was not found in functions\package.json.
To fix this, add the following lines to your package.json:
"engines": {
"node": "8"
}
my package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.4",
"lodash": "^4.17.10"
},
"private": true
}
Need update firebase cli;
npm install -g firebase-tools
Reference:
https://firebase.google.com/docs/cli#macos
You should insert the node engines into your package.json. Try this:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"firebase-admin": "^6.0.0",
"firebase-functions": "^2.0.4",
"lodash": "^4.17.10"
},
"engines": {
"node": ">= 8.0.0"
},
"private": true
}
For more information, checkout the documentation if you're interested.
Edit:
Some commenters mentioned that setting the node version sould be done without the decimals. So try:
"engines": {
"node": ">= 8"
}
also.
=== Deploying to 'datingmuslimanetchat'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
Error: package.json in functions directory has an engines field which is unsupported. The only valid choices are: {"node": "8"} and {"node": "10"}. Note that Node.js 6 is now deprecated.
PS C:\Users\samir\Desktop\folder>

Node engine 8.x or 10.x in package.json

I tried to specify the node engine in a package.json to accept both 8 and 10 version.
I tried to type this:
"engines": {
"node": "8.x|10.x"
},
But running yarn results in:
The engine "node" is incompatible with this module. Expected version "8.x|10.x"
If I replace with:
"engines": {
"node": "10.x"
},
... it works (i.e no error).
Is there a way to accept two versions of node engine in a package.json?
You just need the double pipe || instead of a single.
"engines": {
"node": "^8 || ^10"
}
Would match either v8.x.x or v10.x.x but not v9.
You can read more about it here, or https://github.com/npm/node-semver#versions
See the documentation which includes examples.
Provide a space separated list of engines with greater/less than symbols.
{
"engines" : {
"node" : ">=8.0.0 <11.0.0"
}
}

Bower: replace the latest dependency version by its actual number

My bower.json:
{
"...." : "...."
"name": "myproject",
"dependencies": {
"angular": "1.2.20",
"bootstrap": "latest"
}
}
I'd like to replace "latest" in bootstrap dependency by its actual version number. Is there any way to do that via bower command ? (not via a custom script)
No, bower doesn't have shrinkwrap feature.
It is a long-standing issue: https://github.com/bower/bower/issues/505

Bower dependency tilde in Node

In bower (a node dependency package manager), on some dependencies the version is preceded by a tilde. What does this mean?
{
"name": "mean",
"version": "1.0.0",
"dependencies": {
"bootstrap": "3.0.0",
"angular": "~1.0.6"
}
{
~1.2.3 := >=1.2.3-0 <1.3.0-0 "Reasonably close to 1.2.3". When using
tilde operators, prerelease versions are supported as well, but a
prerelease of the next significant digit will NOT be satisfactory, so
1.3.0-beta will not satisfy ~1.2.3.
From the documentation of the underlying semver

Categories