script to auto-update version of packages in package.json - package.json

I manage a custom npm repository with several packages dependent each other.
When I modify a package (A), I updated its version. At this point, I should update all its references in other packages (B,C) to let them download the new version. Indeed, those packages (B,C) that use the new version, needs a new version number them too.
for instance:
#mypackage.A = 1.0.0
#mypackage.B = 1.0.0 (uses mypackage.A#1.0.0)
#mypackage.C = 1.0.0 (uses mypackage.A#1.0.0)
#mypackage.D = 1.0.0 (doesn't use mypackage.A)
Than I update #mypackage.A to 1.0.1
#mypackage.A = 1.0.1
#mypackage.B = 1.0.0 (should use mypackage.A#1.0.1)
#mypackage.C = 1.0.0 (should use mypackage.A#1.0.1)
#mypackage.D = 1.0.0 (doesn't use mypackage.A)
So I update its reference in other packages, updating them too
#mypackage.A = 1.0.1
#mypackage.B = 1.0.1 (uses mypackage.A#1.0.1)
#mypackage.C = 1.0.1 (uses mypackage.A#1.0.1)
#mypackage.D = 1.0.0 (doesn't use mypackage.A)
How could I automate this? I need a script that, if I update #mypackage.A to 1.0.1, it search in all the package.json of the other packages if there is a reference to A.
If there is, update it and increment the version of that package. At this point the same process should be recursively done of that package.
What can be used to do this? Grunt? Bash? Is there any specific package management techniques to do this?
Or, is there a way to let package.json using always the last version of a package?

Related

Node version needs upgrading?? but its higher than what its recommending?

Im trying to run
npm run serve
on a certain project.
and I get
vue-notus#1.1.0 serve F:\WEB_DEV\Github\vue-notus-main
vue-cli-service serve
ERROR You are using Node v13.14.0, but vue-cli-service requires
Node ^12.0.0
Please upgrade your Node version.
Which is confusing. Its asking me to upgrade but I clearly have a higher version that ^12.0??
Or does it want me to downgrade??
Whats happening here?
The current version of #vue/cli-service requires
"node": "^12.0.0 || >= 14.0.0"
but the error message doesn't show that for some reason.
Upgrade to Node >= 14; 13.x is not a LTS release, which is likely why it's not explicitly supported.
Node 16.x is the current LTS release.
The carat at the start of a version in package.json indicates that you must have a major version that is equal to the version specified.
According to the semver documentation:
Allows changes that do not modify the left-most non-zero element in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.
That is to say, your Node version of 13.14.0 is outside of the range 12.x.x (which is required by your version of vue-cli-service).
You will either need to downgrade Node, or upgrade vue-cli-service.

validate semver version in package.json dependency value

I am getting problems like this when validating that the right version of a dependency is installed:
package with name csvtojson is not satisfied. Installed version: 0.4.5 desired version: github:Keyang/node-csvtojson#16ba2237e0bd96d6e3773e4c4d6e36c70efa620e
I am trying to use the semver package to validate a desired dependency version:
const semver = require('semver');
const satisfies = semver.satisfies(installedVersion, desiredVersion);
in package.json, we might see this:
"csvtojson": "^1.12.0"
or
"csvtojson":"github:Keyang/node-csvtojson#16ba2237e0bd96d6e3773e4c4d6e36c70efa620e"
what I want to do is determine if an installed dependency meets the version range of the desired dependency.
If the desired version is not semverish, I am willing to skip it, but I don't have a good test for that, anyone have a good idea how to skip desired versions that don't appear to be semverish?
Maybe use a regex like this:
/.*[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}/
?
This RegExp here is validating all scenarios:
^(\d|[1-9]\d*)\.(\d|[1-9]\d*)\.(\d|[1-9]\d*)(-(0|[1-9A-Za-z-][0-9A-Za-z-]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9A-Za-z-][0-9A-Za-z-]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$
Source: https://brunorb.com/untangling-semver/

How to relate a version of #types to the versions of the associated package in NodeJS Typescript?

I am working on a nodejs project with typescript 2.2 that is using node 6.3.1 and I want to migrate from using typings to using #types. By doing so I ran into a set of questions related to whether there is a relationship between the version of the #types file and the corresponding npm package.
If I use jasmine as an example, the existing versions of the types definitions are
npm show #types/jasmine#* version
#types/jasmine#1.3.0 '1.3.0'
#types/jasmine#1.3.1 '1.3.1'
#types/jasmine#1.3.2 '1.3.2'
#types/jasmine#2.2.29 '2.2.29'
#types/jasmine#2.2.30 '2.2.30'
#types/jasmine#2.2.31 '2.2.31'
#types/jasmine#2.2.32 '2.2.32'
#types/jasmine#2.2.33 '2.2.33'
#types/jasmine#2.2.34 '2.2.34'
#types/jasmine#2.5.35 '2.5.35'
#types/jasmine#2.5.36 '2.5.36'
#types/jasmine#2.5.37 '2.5.37'
#types/jasmine#2.5.38 '2.5.38'
#types/jasmine#2.5.39 '2.5.39'
#types/jasmine#2.5.40 '2.5.40'
#types/jasmine#2.5.41 '2.5.41'
#types/jasmine#2.5.42 '2.5.42'
#types/jasmine#2.5.43 '2.5.43'
#types/jasmine#2.5.44 '2.5.44'
#types/jasmine#2.5.45 '2.5.45'
#types/jasmine#2.5.46 '2.5.46'
But if I examine the versions of the jasmine packages I have;
npm show jasmine#* version
jasmine#2.0.1 '2.0.1'
jasmine#2.1.0 '2.1.0'
jasmine#2.1.1 '2.1.1'
jasmine#2.2.0 '2.2.0'
jasmine#2.2.1 '2.2.1'
jasmine#2.3.0 '2.3.0'
jasmine#2.3.1 '2.3.1'
jasmine#2.3.2 '2.3.2'
jasmine#2.4.0 '2.4.0'
jasmine#2.4.1 '2.4.1'
jasmine#2.5.0 '2.5.0'
jasmine#2.5.1 '2.5.1'
jasmine#2.5.2 '2.5.2'
jasmine#2.5.3 '2.5.3'
Let’s say I am using version 2.4.0 of jasmine, which version of #types/jasmine should I pick? Because even if I use the latest of both, 2.5.46 does not match with 2.5.3.
Another example would be node itself, there are basically 6.0 or 7.0 versions in #types, and typings has only the ones shown below, being 6.0 reported as obsolete. So, what version of node are those typings actually tied to?
typings view dt~node --versions
TAG VERSION DESCRIPTION COMPILER LOCATION
UPDATED
7.0.0+20170322231424 7.0.0 github:DefinitelyTyped/DefinitelyTyped/node/index.d.ts#a4a912a0cd1849fa7df0e5d909c8625fba04e49d 2017-03-22T23:14:24.000Z
6.0.0+20161121110008 6.0.0 github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#fb7fbd28b477f5e239467e69397ed020d92817e7 2016-11-21T11:00:08.000Z
Thanks
The major and minor versions of the DefinitelyTyped packages are supposed to correspond to the major and minor versions of the package they are types for. The patch version increments whenever the .d.ts file changes for other reasons. Because the minor version shouldn't represent breaking changes, in theory, you can use the highest 2.x.y definition file available for a 2.a.b.c library.
But now the caveats begin.
The header in the definition file may not have changed at the right time
Library authors do not necessarily follow semver*
The definition file may not be 100% correct at any given point, in either direction (i.e. listing a 2.6 feature under a 2.5 version, or failing to list a 2.4 in function in the 2.5 file)
* In fact, no one does
A detailed explanation can be found in official docs FAQ: How do Definitely Typed package versions relate to versions of the corresponding library?

npm install using pre-release versions

i want to use pre-release versions in my package.json to get some dependencies in the latest version (containing als pre-releases) but for some reasons it doesn't work in my case. The pre-releases are fully ignored. As an example lets use angular. If I ask "angular": ">=1.4.0-rc.0 <1.4.1" as an dependency, i would expect that i would get the version 1.4.0-rc.2 installed, but i get just the version 1.4.0.
The npm info angular shows, that there are some rc versions available like
...
'1.4.0-beta.4',
'1.4.0-beta.5',
'1.4.0-beta.6',
'1.4.0-rc.0',
'1.4.0-rc.1',
'1.4.0-rc.2',
My package.json looks as follows right now
"dependencies": {
"angular": ">=1.4.0-rc.0 <1.4.1"
}
Any ideas why i dont get any rc versions? What do i have to do to get it working?
This seems logical, the order of versions is normally the following (for angular releases 1.4.x):
1.4.0-beta.0
1.4.0-beta.2
1.4.0-beta.3
1.4.0-beta.4
1.4.0-beta.5
1.4.0-beta.6
1.4.0-rc.0
1.4.0-rc.1
1.4.0-rc.2
1.4.0
1.4.1
If you request "angular": ">=1.4.0-rc.0 <1.4.1", The latest version that is less strictly 1.4.1 is 1.4.0
Anyway, if you demand "angular": ">=1.4.0-rc.0 <1.4.0", the latest version will be 1.4.0-rc.2

Where do I get 'httr' for R version 2.15.2

Hi, all.
The 'httr' file that CRAN website provides only works on those Rs with versions higher than 3.0. I have a R version 2.15.2. Where can I get 'httr' for my version of R?
Thanks!
May I know what is the correct way to achieve my objective?
Sincerely, Alicia.
You can get the old archives of a package from cran. For httr the archive is at cran.r-project.org/src/contrib/Archive/httr . For projects on github some developers will have tagged releases. httr has the following releases https://github.com/hadley/httr/releases . You can install a package from github using the install_github function from the devtools package.
devtools::install_github("hadley/httr", ref = "httr-0.2")
would install the release tagged 'httr-0.2'

Resources