The `resolveDepsAndWritePackageJson` method should respect the `save-prefix` npm config
The method (resolveDepsAndWritePackageJson) for resolving the npm package versions after the initial * install hardcodes the semver range to use caret (^).
This is not always desirable, ~~and for most projects using a pinned version is probably a more correct behaviour.~~
I think Projen could add support for this in two ways:
- Allow this to be configurable at the project level, ideally by type of dep too.
- Read npm config option to get the user preference (
${packageManager} config get save-prefix)
Here's what Renovate documentation, for example, has to say about the versions:
- Any apps (web or Node.js) that aren't
require()'d by other packages should pin all types of dependencies for greatest reliability/predictability. - Browser or dual browser/node.js libraries that are consumed/required()'d by others should keep using SemVer ranges for dependencies but can use pinned dependencies for devDependencies
- Node.js-only libraries can consider pinning all dependencies, because application size/duplicate dependencies are not as much a concern in Node.js compared to the browser. Of course, don't do that if your library is a micro one likely to be consumed in disk-sensitive environments
This behaviour is defined here:
https://github.com/projen/projen/blob/f80982e56df987507e3f80d1f20e54e20ebd0387/src/javascript/node-package.ts#L1270
Yeah that should be configurable.
Although I disagree with (emphasis is mine):
for most projects using a pinned version is probably a more correct behaviour.
IMO, that's what lockfiles are for. And choosing the correct tool to manage upgrades safely is in the purview of the user.