-
Notifications
You must be signed in to change notification settings - Fork 43
docs: add ADR about using caret ranges for npm deps #687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sarina
merged 4 commits into
openedx:master
from
adamstankiewicz:ags/npm-deps-pinning-strategy-2
Mar 23, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f02ad58
docs: add ADR about using caret ranges for npm deps
adamstankiewicz 9e20ecb
chore: apply suggestions from code review
adamstankiewicz ce93416
chore: add link to Renovate and brief blurb
adamstankiewicz 441a2b8
chore: update the renovate link, with a ref to the adr
adamstankiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
oeps/best-practices/oep-0067/decisions/frontend/0009-renovate.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
oeps/best-practices/oep-0067/decisions/frontend/0011-caret-ranges-dependencies.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.. _Use Caret Ranges for npm Dependency Versions: | ||
|
||
Use Caret Ranges for npm Dependency Versions | ||
############################################ | ||
|
||
Status | ||
****** | ||
|
||
Proposed (February 2025) | ||
|
||
Context | ||
******* | ||
|
||
Managing dependencies in JavaScript projects requires balancing stability, maintainability, and performance. Historically, most projects | ||
have opted to pin exact dependency versions to ensure consistency. However, this approach has notable downsides, particularly when | ||
considering transitive dependencies, package duplication, and update workflows. | ||
|
||
Decision | ||
******** | ||
|
||
JavaScript projects in the Open edX community should define dependencies using caret ranges (e.g., ``^1.2.3``) instead of pinning exact | ||
versions (e.g., ``1.2.3``). | ||
|
||
Why? | ||
|
||
#. **Pinned Dependencies Do Not Fully Lock Transitive Dependencies**: Even if a top-level dependency is pinned, its transitive dependencies | ||
are not necessarily locked. This means updates can still introduce changes, making pinning less effective than intended. | ||
|
||
#. **Reduces Webpack Bundle Size and Dependency Fragmentation**: When different packages pin slightly different versions of the same dependency, | ||
multiple versions of that dependency may be included in the final bundle. Using caret ranges allows different packages to share a single version, | ||
reducing duplication and improving performance. | ||
|
||
#. **More Clearly Communicates Engineering Intent**: Specifying caret ranges explicitly indicates that a project intends to accept non-breaking | ||
updates in accordance with semantic versioning. This improves clarity for maintainers and contributors. | ||
|
||
#. **Improves Renovate Workflow and Reduces Maintenance Overhead**: The Open edX platform to automate and manage dependency updates (see | ||
:ref:`Use Renovate to update dependencies` for more details). With caret ranges, Renovate still detects and opens PRs for minor and patch updates, | ||
but these updates typically require only a ``package-lock.json`` change rather than modifying ``package.json``. This allows Renovate to group updates | ||
more efficiently and reduces unnecessary PR churn. In contrast, pinned dependencies require Renovate to open a PR for every minor or patch update to | ||
explicitly modify ``package.json``, increasing maintenance overhead. | ||
|
||
Consequence | ||
*********** | ||
|
||
#. Projects will automatically receive non-breaking dependency updates within the specified range, reducing the need for manual intervention. | ||
#. Webpack bundle sizes may decrease due to fewer redundant versions of dependencies. | ||
#. Renovate will generate fewer update PRs, focusing primarily on major version changes that require attention. | ||
#. Developers should continue using lockfiles (``package-lock.json``) to ensure consistent installations across environments. | ||
|
||
Rejected Alternatives | ||
********************* | ||
|
||
#. **Continuing to pin dependencies in JavaScript projects** | ||
|
||
* Pinning dependencies does not effectively prevent updates to transitive dependencies. | ||
* Leads to unnecessary duplication of packages in Webpack bundles, increasing size and complexity. | ||
* Results in excessive Renovate PRs for minor and patch updates, increasing maintenance burden. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.