fix(package-manager): restore missing git package deps + pnpm-friendly install flags#6467
Closed
cad0p wants to merge 1 commit into
Closed
Conversation
…y install flags The package load path (resolvePackageSources) only checked for a git checkout's directory, not its node_modules. A checkout that lost its node_modules (manual git clean -fdx, fresh clone by another tool, or partial state) was loaded with broken imports, failing with "Cannot find module '<dep>'" for extensions importing third-party packages (e.g. croner in @tintinweb/pi-subagents). Add ensureGitPackageDependencies(): on resolve, when a git checkout exists but has a package.json with runtime dependencies and no node_modules, reinstall them. No-deps packages are skipped because npm install does not create node_modules for them, so checking for it would cause spurious reinstalls on every startup for npm users. Also fix getGitDependencyInstallArgs() for pnpm: it returned a bare ["install"], so pnpm 11 exited non-zero on unapproved build scripts ([ERR_PNPM_IGNORED_BUILDS]), aborting install/update/restore even though dependencies were installed. Mirror the npm-package install flags (--config.strict-dep-builds=false etc.) so git package installs stay pnpm-friendly. Verified end-to-end: removed node_modules from a git package with npmCommand: ["pnpm"]; pi restored deps (+ croner 10.0.1) and exited 0 with no "Cannot find module" error.
Contributor
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
Author
|
Sorry for the spam, did not mean to push this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A git package whose checkout exists but whose
node_modulesis missing fails to load withCannot find module '<dep>'. This hits pnpm users in particular.Repro (the case I hit):
@tintinweb/pi-subagentsis installed asgit:github.com/cad0p/tintinweb-pi-subagents@masterwith"npmCommand": ["pnpm"]. After the checkout lost itsnode_modules(agit clean -fdxduring reconcile, a fresh clone by another tool, or a partial state),pifailed at startup:Root cause
The package load path (
resolvePackageSources) only checks for the git checkout directory, not fornode_modules:So a checkout that exists but has no
node_modulesis loaded as-is, and extensions importing third-party packages fail to resolve. The install/reconcile paths (installGit/ensureGitRef) do reinstall after a ref change, but the load path on a plainpistartup does not.A second, related pnpm issue:
getGitDependencyInstallArgs()returns a bare["install"]whennpmCommandis configured. pnpm 11 exits non-zero on unapproved build scripts ([ERR_PNPM_IGNORED_BUILDS]), which would abort install/update/restore even though the dependencies are installed successfully. The npm-package install path (getNpmInstallArgs) already passes--config.strict-dep-builds=falsefor pnpm; the git path did not.Fix
Two changes in
packages/coding-agent/src/core/package-manager.ts:ensureGitPackageDependencies()— onresolve, when a git checkout exists but has apackage.jsonwith runtimedependenciesand nonode_modules, reinstall them. No-deps packages are skipped:npm installdoes not createnode_modulesfor a package with no dependencies, so checking for it would cause spurious reinstalls on every startup for npm users. Respects offline mode.getGitDependencyInstallArgs()— when the configured package manager is pnpm, return the same pnpm-friendly flags the npm-package path uses (--config.auto-install-peers=false,--config.strict-peer-dependencies=false,--config.strict-dep-builds=false), so[ERR_PNPM_IGNORED_BUILDS]no longer aborts git package installs/updates/restores.Verification
End-to-end with
npmCommand: ["pnpm"]and@tintinweb/pi-subagents(which depends oncroner):Before the fix:
Cannot find module 'croner'and startup abort. After: deps restored, extension loads, exit 0.npm run check✅npx vitest run test/package-manager.test.ts— 119 passed (4 new regression tests added)test/suite/regressions/4167-...are pre-existing onmain(verified by stashing this change) and unrelated to package-manager.Notes
CHANGELOG.mdper CONTRIBUTING.node_modules-exists and no-deps cases short-circuit before any install).