Skip to content

feat(shims): add a corepack shim that runs corepack in the container - #17

Merged
gpmayorga merged 1 commit into
mainfrom
feat/corepack-shim
Nov 28, 2026
Merged

gpmayorga merged 1 commit into
mainfrom
feat/corepack-shim

Conversation

@gpmayorga

Copy link
Copy Markdown
Owner

Problem

node, npm, npx, yarn and pnpm are shimmed, but corepack was not. Typing corepack resolved to whatever comes later on PATH, e.g. a host Node kept at the end of PATH for local mode, so it ran on the host, outside the container.

Changes

  • bin/corepack: new shim, identical to bin/node / bin/pnpm (docker_exec "$(basename "$0")").
  • bin/common.sh
    • needs_corepack(): always true for corepack (same as yarn / pnpm). The existing corepack_setup_script then makes corepack available before the call: on Node 25+ images (default node:26-alpine), which no longer bundle corepack, it puts the pinned copy from ~/.cache/node-shims/corepack (NODE_SHIMS_COREPACK_VERSION, default 0.36.0) on PATH, installing it once if missing. Older images use their bundled corepack. corepack enable / corepack install also run first, as they do for yarn/pnpm.
    • is_install_command(): corepack use|up and corepack <pm>[@ver] <install subcommand> (e.g. corepack pnpm install, corepack yarn) count as installs, so the node_modules platform marker is recorded. --help / --version still never count.
    • Local mode needs no change: NODE_SHIMS_MODE=local corepack goes through exec_local, which skips the shims dir and finds the host corepack. Dev-server port mapping already matches on the full argv (corepack pnpm dev).
  • Docs and lists of shimmed tools: README, scripts/install-shims.sh ("Available commands"), scripts/install-agent-skill.sh (CLAUDE.md pointer text), skills/node-docker-shims/SKILL.md, a comment in bin/node-shell.
  • Tests
    • Unit: corepack added to the per-tool loop; new tests for corepack setup (pinned copy on PATH, cache dir mount, NODE_SHIMS_COREPACK_VERSION), local override plus the shim winning over a host corepack at the end of PATH, port mapping, and the platform marker for corepack install vs non-install calls.
    • Smoke: corepack --version and corepack pnpm --version (with packageManager) on the default image, and corepack pnpm --version on .nvmrc 22 (bundled corepack).

Testing

  • bats test/unit in an ubuntu:24.04 container (bats from apt, matching CI): 43/43 pass.
  • bats test/unit on macOS: 39/43. The 4 failures (project is mounted at its real path, absolute path arguments outside the project, op run parent forwards host env, node-shell mounts the corepack dir) also fail on unmodified main. They are macOS-specific (/var vs /private/var, Linux pnpm store path), and CI runs on Linux.
  • shellcheck -S warning bin/corepack bin/common.sh bin/node-shell scripts/install-shims.sh scripts/install-agent-skill.sh: clean.
  • bats test/smoke on macOS with Docker Desktop: the new corepack smoke test passes, along with node, npm, yarn, pnpm and Docker-from-npm-scripts. 4 tests fail (yarn install ... NODE_SHIMS_LOCAL, pnpm shares one store ..., npx wrangler builds a worker with npm ECOMPROMISED, op run), and the same 4 also fail on unmodified origin/main on this machine, so they come from the environment.
  • Manual, through the shim in a temp project with "packageManager": "pnpm@11.28.10":
    • default image (Node 26): corepack --version gives 0.36.0 (pinned copy), corepack pnpm --version gives 11.28.10
    • NODE_IMAGE=node:22-alpine: corepack --version gives 0.34.6 (bundled), corepack pnpm --version gives 11.28.10
    • with a Node 24 host bin at the end of PATH: corepack --version gives 0.36.0 (the shim wins), and NODE_SHIMS_MODE=local corepack --version gives 0.34.2 (host corepack)
  • Not tested: the CI smoke job on Linux (it runs on this PR).

Notes

  • Host Node 25+ installs (e.g. nvm Node 26) don't ship corepack either. With only such a Node at the end of PATH, NODE_SHIMS_MODE=local corepack fails with the existing "not found outside the Docker shims" message. That is the intended behaviour, but local mode then needs a host corepack (npm i -g corepack) to be useful.
  • Wrangler credential detection does not look through corepack: corepack pnpm exec wrangler deploy gets no Cloudflare credentials. This fails closed. pnpm exec wrangler ... or NODE_SHIMS_WRANGLER_AUTH=1 still work.

🤖 Generated with Claude Code

Without a shim, `corepack` resolved to whatever host Node sits at the end
of PATH (kept there for local mode), so it ran on the host. bin/corepack
now goes through docker_exec like node/npm/npx/yarn/pnpm.

needs_corepack() always sets corepack up for the corepack shim, so Node 25+
images (no bundled corepack, default node:26) get the same pinned copy the
yarn/pnpm shims install into ~/.cache/node-shims/corepack; older images use
their bundled one. Local mode still finds the host corepack via exec_local.

is_install_command() treats `corepack use|up` and `corepack <pm> <install>`
as installs, so the node_modules platform marker stays correct.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gpmayorga
gpmayorga merged commit dc04c91 into main Nov 28, 2026
3 checks passed
@gpmayorga
gpmayorga deleted the feat/corepack-shim branch November 28, 2026 13:32
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