PowerShell UserVoice: Add Support for NPM Type Version Specification in Module Manifest and #Requires
If you have ever used Node.js, the packages.json file is used to specify the module dependencies. Here is an example:
In the above snippet, line 12 specifies express module with a version string ^4.16.2. The version string here is prefixed with a caret (^) symbol. NPM supports different specification strings. We can prefix the version string with a tilde (~) as well or simply use an asterisk (*) to mean the most recent version or latest version of the module. Through the use of version range comparators, version can be specified in multiple ways. The node-semver repository provides in-depth view into this.
From the node-semver page,
comparator is composed of an
operator and a
version. The set of primitive
<=Less than or equal to
>=Greater than or equal to
=Equal. If no operator is specified, then equality is assumed, so this operator is optional, but MAY be included.
For example, the comparator
>=1.2.7 would match the versions
1.3.9, but not the versions
The tilde (~) and caret (^) ranges can be used as well.
* may be used to “stand in” for one of the numeric values in the
[major, minor, patch] tuple.
>=0.0.0(Any version satisfies)
>=1.0.0 <2.0.0(Matching major version)
>=1.2.0 <1.3.0(Matching major and minor versions)
Allows patch-level changes if a minor version is specified on the comparator. Allows minor-level changes if not.
Allows changes that do not modify the left-most non-zero digit 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
Coming to the subject of this article, having similar support in PowerShell module manifests and with #Requires statement, we can specify the module dependencies in a more flexible way. To this extent, I have created a UserVoice item: https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/32845762-support-for-npm-type-version-strings-in-powershell
If you think this is useful feature in PowerShell, go ahead and vote it up!Share on: