projen icon indicating copy to clipboard operation
projen copied to clipboard

The `resolveDepsAndWritePackageJson` method should respect the `save-prefix` npm config

Open moltar opened this issue 2 years ago • 1 comments

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:

  1. Allow this to be configurable at the project level, ideally by type of dep too.
  2. 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:

  1. Any apps (web or Node.js) that aren't require()'d by other packages should pin all types of dependencies for greatest reliability/predictability.
  2. 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
  3. 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

moltar avatar Aug 25 '23 15:08 moltar

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.

mrgrain avatar Aug 25 '23 15:08 mrgrain