Skip to content

chore: commit package-lock.json, install with npm ci and run prebuild once per build - #2216

Draft
Douglasymlai wants to merge 1 commit into
mainfrom
chore/lockfile-npm-ci
Draft

Douglasymlai wants to merge 1 commit into
mainfrom
chore/lockfile-npm-ci

Conversation

@Douglasymlai

Copy link
Copy Markdown
Contributor

Pull Request

Related Issue

N/A — maintainer-directed repair; no linked issue required for this PR.

Description

Problem

Two builds of the same commit can ship different dependency versions. package-lock.json is not committed, so every release job runs npm install and takes whatever versions package.json allows that day. This already broke a release once, and it means a build can't be reproduced later. Example from v1.0.8: two installer builds of the same commit, made 85 minutes apart, got different react-router versions (7.18.5 and 7.18.6). Resolving the same package.json one day later gives 10 different package versions.

Separately, the macOS and Windows release jobs compile the app twice per build, which adds about a minute per job.

Cause

  • .gitignore excludes package-lock.json, and the CI check rejects any pull request that touches it.
  • npm run build already runs prebuild automatically (npm runs the pre<name> script before <name>), and the build script also called npm run prebuild itself. build:win did the same with prebuild:win. In the v1.0.8 release logs the second pass takes 59 s on macOS arm64 and 51 s on Windows. build:linux has no matching pre script, so Linux compiled once.

Fix

  • Commit package-lock.json. It pins the dependency set the v1.0.8 installers were built with: it was resolved with npm 10.8.2 (the npm version CI runs) as of the time the v1.0.8 installers installed their dependencies. It includes the native packages for macOS (x64 and arm64), Windows x64 and Linux x64.
  • Every workflow that installs project dependencies now uses npm ci, which installs exactly what the lockfile says and fails if package.json and the lockfile disagree. actions/setup-node now caches npm downloads keyed on package-lock.json.
  • The CI check stops rejecting package-lock.json changes (it still rejects yarn.lock and pnpm-lock.yaml). CONTRIBUTING now says to commit the updated lockfile with any dependency change.
  • build and build:win no longer call the prebuild step themselves; npm's automatic prebuild hook runs it once. npm run dev, npm run prebuild, build:mac, build:linux and the other build scripts are unchanged.

Note: the "Check Not Allowed File Changes" job runs from main's copy of the workflow, so it will still flag this PR for adding package-lock.json. Pull requests opened after this one merges won't be flagged.

Testing Evidence (REQUIRED)

I can't run a real installer build on my machine. The first CI build after this merges is the real check: it should finish with one compile pass per job.

Release build job, before → after (per macOS / Windows job):

Step Before After
Install dependencies npm install (newest versions allowed by package.json) npm ci (exact versions from package-lock.json)
Node setup (GitHub-hosted runners) no npm cache npm cache keyed on package-lock.json
npm run build -- --<arch> prebuild → prebuild again → electron-builder prebuild → electron-builder
Time spent compiling ~93 s + ~59 s (macOS arm64), ~60 s + ~51 s (Windows), from the v1.0.8 logs one pass only
Linux npm run build:linux prebuild → electron-builder unchanged

What I checked locally:

  • npm ci --ignore-scripts (npm 10.8.2) installs 1,607 packages from the committed lockfile and leaves it unchanged.

  • npm ci with a package.json that has one extra dependency fails with "package.json and package-lock.json … are in sync", as intended.

  • With every script replaced by an echo stub, npm run build -- --x64 and npm run build:win now run the prebuild steps once and still pass --x64 to electron-builder. build:mac, build:linux and prebuild run the same steps as before.

  • The release runners use Node 20 with npm 10.8.2 (both self-hosted macOS runners report it in the v1.0.8 logs), the same npm that generated the lockfile.

  • npm run type-check passes.

  • npm test with the lockfile installed: 5,857 passed, 49 failed in 14 files. Those same 14 files fail with the same 49 tests on an untouched main checkout installed the old way (npm install), so they are existing failures on main (chat store integration, installer and environment tests that depend on the local machine), not caused by this change.

  • I have included human-verified testing evidence in this PR. (Not yet: automated checks only; the first CI build is the real check.)

  • This PR includes frontend/UI changes, and I attached screenshot(s) or screen recording(s).

  • No frontend/UI changes in this PR.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other (build and CI reliability)

Contribution Guidelines Acknowledgement

@github-actions

Copy link
Copy Markdown

👋 Hey there spelunker. It looks like you've modified some files that we can't accept as contributions. The complete list of files we can't accept are:

  • package-lock.json
  • yarn.lock
  • pnpm-lock.yaml

You'll need to revert all of the files you changed in that list using GitHub Desktop or git checkout origin/main <file name>. Once you get those files reverted, we can continue with the review process. :octocat:

More discussion:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant