Skip to content

fix(pm): postinstall OS detection for Windows kernel-version drift#2883

Merged
elrrrrrrr merged 3 commits intonextfrom
fix/postinstall-windows-os-detection
May 2, 2026
Merged

fix(pm): postinstall OS detection for Windows kernel-version drift#2883
elrrrrrrr merged 3 commits intonextfrom
fix/postinstall-windows-os-detection

Conversation

@elrrrrrrr
Copy link
Copy Markdown
Contributor

Summary

  • The postinstall.sh / postinstall.utoo.sh templates relied on $OSTYPE to detect Windows. When sh is invoked from PowerShell on GitHub Actions, $OSTYPE is not set, so the scripts fell back to uname -s | tr and produced package names like @utoo/utoo-mingw64_nt-10.0-26100-x64, which don't exist on npm.
  • GitHub recently rolled windows-latest from Server 2022 (kernel mingw64_nt-10.0-20348) to Server 2025 (mingw64_nt-10.0-26100), so the kernel-version slug changed and the install started failing on downstream projects (e.g. eggjs/egg CI).
  • Switch to uname -s prefix matching (MINGW* / MSYS* / CYGWIN*) and keep the existing $OSTYPE check as a secondary fallback, so the resolved OS is always win32 regardless of host kernel version.

Repro (before this PR)

On a fresh windows-latest runner:

$ sh -c 'echo "$OSTYPE"'
                       # empty when invoked from pwsh
$ uname -s
MINGW64_NT-10.0-26100

→ postinstall builds @utoo/utoo-mingw64_nt-10.0-26100-x64 → npm 404.

Test plan

  • Verify on a downstream project (e.g. eggjs/egg) that ut install --from pnpm succeeds on windows-latest after this template ships in a new utoo release.
  • Confirm Linux/macOS resolution still produces linux-x64 / darwin-arm64 etc. (no behavior change on those branches — uname -s prefix only matches the three Windows shell envs).

🤖 Generated with Claude Code

The postinstall scripts relied on $OSTYPE to detect Windows, which is
not set when sh is invoked from PowerShell on GitHub Actions. They then
fell back to `uname -s | tr` and emitted package names like
`@utoo/utoo-mingw64_nt-10.0-26100-x64`, which don't exist on npm.

Recently `windows-latest` was upgraded from Server 2022
(`mingw64_nt-10.0-20348`) to Server 2025 (`mingw64_nt-10.0-26100`),
making the failure visible (e.g. eggjs/egg CI), but the detection was
already fragile — any future kernel bump would break it again.

Switch to `uname -s` prefix matching (`MINGW*`/`MSYS*`/`CYGWIN*`) with
the `$OSTYPE` check kept as a fallback, so the resolved OS is always
`win32` regardless of the host kernel version.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the post-install script templates to improve Windows environment detection by utilizing uname -s and a case statement, which prevents kernel version bumps from affecting package names. The review feedback suggests adding a fallback value for the OS variable in cases where uname -s returns an empty string to ensure the generated package name is always well-formed.

Comment thread vendor/templates/postinstall.sh.template Outdated
Comment thread vendor/templates/postinstall.utoo.sh.template Outdated
Per review feedback: if `uname -s` fails or returns empty (and $OSTYPE is
not a Windows variant), the resulting OS would be empty and produce a
malformed package name like `@utoo/utoo--x64`. Substitute "unknown" so
the failure mode is at least debuggable.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@elrrrrrrr elrrrrrrr requested a review from killagu May 2, 2026 12:48
@elrrrrrrr elrrrrrrr added the A-Pkg Manager Area: Package Manager label May 2, 2026
Lock down `vendor/templates/postinstall*.sh.template`'s OS/ARCH
resolution so a future kernel-version bump on `windows-latest` (the
trigger for the original regression here) or a stray refactor of the
`uname -s` / $OSTYPE handling fails CI instead of producing a 404
package name in user installs.

The test stubs `uname` and the side-effecting commands (cp, mkdir,
chmod, npm, find_node_modules) and runs each template under a sandboxed
sh, then asserts the computed (OS, ARCH) for 11 cases per template:
Linux/macOS x64+arm64, Windows under MINGW (Server 2022 + 2025), MSYS,
CYGWIN, ARM64, the legacy $OSTYPE=msys fallback, and the
empty-uname "unknown" fallback.

Wired into pm-ci.yml as a pre-build step on every matrix host
(linux/mac/windows) — runs in well under a second.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

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

LGTM

@elrrrrrrr elrrrrrrr merged commit 6be8e29 into next May 2, 2026
32 checks passed
@elrrrrrrr elrrrrrrr deleted the fix/postinstall-windows-os-detection branch May 2, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Pkg Manager Area: Package Manager

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants