Skip to content

Skip already-installed npm globals so bootstrap reruns are idempotent - #38

Merged
tommyjcarpenter merged 2 commits into
mainfrom
fix/npm-idempotent-install
Sep 29, 2026
Merged

tommyjcarpenter merged 2 commits into
mainfrom
fix/npm-idempotent-install

Conversation

@tommyjcarpenter

@tommyjcarpenter tommyjcarpenter commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

The npm package type now lists the installed globals with npm ls -g --depth=0 --json and runs npm install -g only for the missing ones. Each installed package gets a skip log line, the same as the winget precheck. Released as 1.3.2.

npm install -g retires and re-extracts every named package, even one that is already current. On Windows that rename fails with EBUSY while another process holds a file in the package dir open, such as an editor's running pyright language server, so a plain rerun of the bootstrap aborted at the npm step:

npm error code EBUSY
npm error syscall rename
npm error EBUSY: resource busy or locked, rename '...\npm\node_modules\pyright\dist' -> '...\npm\node_modules\.pyright-dTxHruk4\dist'

The npm ls exit code is ignored because it exits 1 on extraneous or invalid deps but still prints the full tree. Empty or non-JSON output (npm not installed yet) counts as nothing installed, so the install runs and fails loudly as before. A spec with a version suffix (pkg@1.2) never matches an installed name, so it always installs.

Reruns leave installed globals at their current version; upgrading them is out of scope for bootstrap.

Tested with make ci (new tests/test_npm.py), plus a dry run against real npm on Windows with the install call stubbed out: all five configured globals were detected and no install ran.

The `npm` package type now lists the installed globals with `npm ls -g --depth=0 --json` and runs `npm install -g` only for the missing ones.

`npm install -g` retires and re-extracts every named package, even one that is already current. On Windows that rename fails with EBUSY while another process holds a file in the package dir open, such as an editor's running `pyright` language server, so a plain rerun of the bootstrap aborted at the npm step. The winget step already skips installed packages the same way.

Reruns no longer upgrade npm globals; `npm update -g` does that.
Copilot AI balanced review requested due to automatic review settings September 29, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused implementation matches the stated behavior and includes adequate tests for its key paths.

Review effort: Balanced
Findings: None

What changed in this PR

Adds idempotent npm global installation to prevent Windows EBUSY failures during bootstrap reruns.

Changes:

  • Detects installed npm globals and skips them.
  • Installs only missing packages, with POSIX/Windows handling.
  • Adds unit tests and changelog documentation.
File Description
bootstrap/​utils.py Adds npm precheck and selective installation.
tests/​test_npm.py Tests detection, skipping, and installation behavior.
Changelog.md Documents the new idempotent behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Gives the changelog entry a version instead of Unreleased and bumps `pyproject.toml` and `uv.lock` to match. Drops the note telling users to run `npm update -g` by hand; upgrading installed globals is the machine's update routine, not bootstrap's.
Copilot AI review requested due to automatic review settings September 29, 2026 11:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The npm precheck must refresh Windows PATH to support reruns from a stale parent shell.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Refresh PATH before npm checks to support same-shell reruns

bootstrap/​utils.py:189

Refresh PATH before invoking npm. On Windows, an unchanged parent shell can still have the pre-install PATH; if winget detects Node is already installed, it skips run_cmd, so the refresh at utils.py:89 never runs and this check (and the subsequent install) reports npm missing. This makes the common rerun from the same shell fail instead of becoming idempotent.

@tommyjcarpenter
tommyjcarpenter merged commit 2719eca into main Sep 29, 2026
6 checks passed
@tommyjcarpenter
tommyjcarpenter deleted the fix/npm-idempotent-install branch September 29, 2026 12:35
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.

2 participants