Skip to content

ci: detect if package-lock.json is up to date and generated with correct npm version - #11827

Merged
pkuczynski merged 5 commits into
nextfrom
npm-version
Dec 8, 2025
Merged

pkuczynski merged 5 commits into
nextfrom
npm-version

Conversation

@pkuczynski

@pkuczynski pkuczynski commented Dec 6, 2025 •

Copy link
Copy Markdown
Member

Description of change

New CI step detecting if package-lock.json:

  • is up to date
  • was generated using npm shipped with node defined in .nvmrc

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated tests validating the change (tests/**.test.ts)
  • Documentation has been updated to reflect this change (docs/docs/**.md)

@pkuczynski pkuczynski self-assigned this Dec 6, 2025
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Version Constraint

The npm version constraint changed from '>=10.1.0' to '10', which may be too restrictive. This will only allow npm 10.x versions and block npm 11.x entirely. Consider using '~10' or '^10.0.0' to allow patch/minor updates within npm 10, or '>=10.0.0 <11.0.0' for more explicit range specification while still preventing npm 11.

"version": "10",
"onFail": "error"

@pkg-pr-new

pkg-pr-new Bot commented Dec 6, 2025 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@11827
    

commit: cfc5ae1

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 6, 2025 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to cfc5ae1

CategorySuggestion                                                                                                                                    Impact
General
Display diff for debugging failures

Add git diff package-lock.json to the error-handling block to display the
changes in the lock file when the check fails, which aids in debugging.

.github/workflows/tests.yml [71-74]

 if [ -n "$(git status --porcelain)" ]; then
   echo "package-lock.json is not up to date or was generated with a different npm version than the one shipped with Node.js $(cat .nvmrc)"
+  git diff package-lock.json
   exit 1
 fi
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This is a valuable improvement for debugging, as it provides immediate feedback on why the package-lock.json check failed by showing the exact differences, saving developers time.

Medium
  • More

Previous suggestions

Suggestions up to commit 6537568
CategorySuggestion                                                                                                                                    Impact
Possible issue
Restore removed devEngines configuration

Restore the devEngines configuration in package.json. Its removal contradicts
the PR's goal and eliminates development environment consistency checks.

package.json [244-247]

 "collective": {
   "type": "opencollective",
   "url": "https://opencollective.com/typeorm",
   "logo": "https://opencollective.com/opencollective/logo.txt"
 },
+"devEngines": {
+  "runtime": {
+    "name": "node",
+    "version": ">=20.9.0"
+  },
+  "packageManager": {
+    "name": "npm",
+    "version": ">=10.0.0",
+    "onFail": "error"
+  }
+},
 "tags": [
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that removing the devEngines block contradicts the likely intent of the PR and removes a useful constraint for ensuring development environment consistency. Restoring it improves project maintainability.

Medium
Suggestions up to commit a9ebbd7
CategorySuggestion                                                                                                                                    Impact
Possible issue
Use a more specific version range

Refine the packageManager version constraint to ^10.1.0 to enforce the minimum
required version while allowing minor and patch updates within major version 10.

package.json [254]

-"version": "10",
+"version": "^10.1.0",
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that changing the packageManager version to 10 lowers the minimum required version from 10.1.0 to 10.0.0, which could introduce environment-specific compatibility issues.

Medium

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: tests-linux (24) / sqljs

Failed stage: Run npm ci [❌]

Failure summary:

The action failed during the npm ci command due to a package manager version mismatch:
- The
repository's devEngines configuration requires npm version "10"
- The GitHub Actions runner has npm
version "11.6.2" installed
- The devEngines.packageManager setting has onFail: 'error', which causes
the installation to fail when the version doesn't match
- Error code: EBADDEVENGINES - Invalid
semver version "10" does not match "11.6.2"

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

153:  Downloading single artifact
154:  Preparing to download the following artifacts:
155:  - build (ID: 4787337696, Size: 6502590, Expected Digest: sha256:2cae37f077e2255e46bb2e6182712daddf30e2a26d411064caf9eb36ae4f74b3)
156:  Redirecting to blob download url: https://productionresultssa10.blob.core.windows.net/actions-results/0c4cfcb4-ab2e-4e07-8b98-b4c15a6fedce/workflow-job-run-12085cfa-27c0-5396-b0ff-c9956a3e1a5b/artifacts/44575cf5b28512d75644bf54a517dcef304ff809fd511747621b4d64f19aac66.zip
157:  Starting download of artifact to: /home/runner/work/typeorm/typeorm/build
158:  (node:2144) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
159:  (Use `node --trace-deprecation ...` to show where the warning was created)
160:  SHA256 digest of downloaded artifact is 2cae37f077e2255e46bb2e6182712daddf30e2a26d411064caf9eb36ae4f74b3
161:  Artifact download completed successfully.
162:  Total of 1 artifact(s) downloaded
163:  Download artifact has finished successfully
164:  ##[group]Run npm ci
165:  �[36;1mnpm ci�[0m
166:  shell: /usr/bin/bash -e {0}
167:  ##[endgroup]
168:  npm error code EBADDEVENGINES
169:  npm error EBADDEVENGINES The developer of this package has specified the following through devEngines
170:  npm error EBADDEVENGINES Invalid devEngines.packageManager
171:  npm error EBADDEVENGINES Invalid semver version "10" does not match "11.6.2" for "packageManager"
172:  npm error EBADDEVENGINES {
173:  npm error EBADDEVENGINES   current: { name: 'npm', version: '11.6.2' },
174:  npm error EBADDEVENGINES   required: { name: 'npm', version: '10', onFail: 'error' }
175:  npm error EBADDEVENGINES }
176:  npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2025-12-06T22_42_43_420Z-debug-0.log
177:  ##[error]Process completed with exit code 1.
178:  Post job cleanup.

@alumni

alumni commented Dec 8, 2025 •

Copy link
Copy Markdown
Collaborator

Hey, maybe it's not urgent to do this now - one quick thing would be --ignore-engines in CI or we could also leave it as it is for now.

I normally use the built-in corepack to pick the package manager version, but it requires some extra setup for npm AFAIR.

Maybe onFail could be changed to something else, like "ignore" or "download" - I think newer versions of npm will automatically download and switch to the older ones when they see "onFail": "download".

In the long term we need a fixed version (down to the patch) of a package manager - that is quite easy with e.g. pnpm, but it would mean to change things we don't want to change right now - at least not with the current branching model.

Comment thread package.json Outdated
"name": "npm",
"version": ">=10.1.0",
"version": "10",
"onFail": "error"

@alumni alumni Dec 8, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"onFail": "error"
"onFail": "warn"

"download" is not yet supported by npm

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not prevent messing up with lockfile. If we do warn we might as well remove the whole devEngines section...

What we could to alternativelly, is have a dedicated step validating if lockfile has been created using npm@10...

The difference between npm 10 and 11 are rather cosmetic. They both use the same lockfileVersion: 3, so they should be compatible. But I understand you want to avoid unnecessary diffs on packakge-lock, which make sense...

@OSA413

OSA413 commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

The tests uncover an interesting case: the default node 24's npm is 11, so what should be done then? I think we can manually regenerate package-lock.json for npm@10 before merging.

Btw how does npm@10 handle package-lock.json created by npm@11?

@pkuczynski

Copy link
Copy Markdown
Member Author

Btw how does npm@10 handle package-lock.json created by npm@11?

As this is the same lockfileVersion: 3, it does not care: see example run https://github.com/typeorm/typeorm/actions/runs/20035394227/job/57455392520?pr=11835#step:6:22

But if we allow different lockfile versions, we might end-up with some unnecessary diffs... Not a major issue I would say...

@pkuczynski pkuczynski changed the title chore: use npm 10 for devEngines in package.json ci: detect if package-lock.json is up to date and generated with correct npm version Dec 8, 2025
@pkuczynski

pkuczynski commented Dec 8, 2025 •

Copy link
Copy Markdown
Member Author

This whole discussion led me to discover our current package-lock.json is not up to date with package.json which most likely happened during one of the merges master > next.

So I added new CI step, which would detect if package-lock:

  • is up to date
  • was generated using npm shipped with node defined in .nvmrc

Here are some tests:

  1. package-lock outdated: https://github.com/typeorm/typeorm/actions/runs/20035851700?pr=11827 - FAIL
  2. package-lock up to date: https://github.com/typeorm/typeorm/actions/runs/20036015952?pr=11827 - PASS
  3. package-lock generated using npm 11.6.0 - https://github.com/typeorm/typeorm/actions/runs/20036071615?pr=11827 - PASS
    • this is interesting! npm@11 removed one more deps but npm@10 does not seem to care. Must be some npm glitch as when I move back to npm@10 it does not restore this dependency.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@pkuczynski
pkuczynski requested a review from alumni December 8, 2025 17:09
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 80.77% (+0.001%) from 80.769%
when pulling 96a4634 on npm-version
into ef9e4b6 on next.

Comment thread package.json Resolved
@pkuczynski
pkuczynski requested a review from gioboa December 8, 2025 19:42

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification 👍
LGTM

@pkuczynski
pkuczynski merged commit ffd735d into next Dec 8, 2025
@pkuczynski
pkuczynski deleted the npm-version branch December 8, 2025 19:49
@alumni

alumni commented Dec 8, 2025

Copy link
Copy Markdown
Collaborator

This only makes things more complicated 🤷🏻

anyway, we'll fix it sometime

@alumni

alumni commented Dec 8, 2025 •

Copy link
Copy Markdown
Collaborator

This only makes things more complicated 🤷🏻

Hmm, I was expecting npm ci in the build step to fail, but seems it does not?

If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.

Source: https://docs.npmjs.com/cli/v11/commands/npm-ci

Maybe because they say "dependencies" - both pnpm and yarn are more explicit about install --frozen-lockfile:

pnpm doesn't generate a lockfile and fails to install if the lockfile is out of sync with the manifest / an update is needed or no lockfile is present.

Source: https://pnpm.io/cli/install#--frozen-lockfile

If the --immutable option is set (defaults to true on CI), Yarn will abort with an error exit code if the lockfile was to be modified. For backward compatibility we offer an alias under the name of --frozen-lockfile, but it will be removed in a later release.

Source: https://yarnpkg.com/cli/install#details

So they aren't identical as I thought.

alumni added a commit to alumni/typeorm that referenced this pull request Dec 12, 2025
alumni added a commit to alumni/typeorm that referenced this pull request Dec 12, 2025
alumni added a commit to alumni/typeorm that referenced this pull request Dec 12, 2025
alumni added a commit to alumni/typeorm that referenced this pull request Dec 12, 2025
alumni added a commit to alumni/typeorm that referenced this pull request Dec 12, 2025
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants