fix(cli): update the workspace member that declares the CLI - #251
Open
detail-app[bot] wants to merge 1 commit into
Open
fix(cli): update the workspace member that declares the CLI#251detail-app[bot] wants to merge 1 commit into
detail-app[bot] wants to merge 1 commit into
Conversation
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.
Detail bug report: View on Detail
Closes #247
Bug
javachat updateexited 1 in an npm workspaces monorepo when@wcallahan/javachat-cliwas declared by a workspace member package. npm hoistsnode_modules/.bin/javachatand the CLI package to the workspace root, butresolveNpmInstallTarget(cli/bin/javachat.js) treated the.binowner (the workspace root) as the project to update, read only the root'spackage.json, and threwThe project at <root> does not declare @wcallahan/javachat-clibefore ever invoking npm. The guard conflated "the directory that owns.bin/javachat" with "the project that declares the dependency" — identical in a single-package project, divergent under hoisting. Introduced bye6844cfb(the self-update feature).Fix
In the
.binbranch ofresolveNpmInstallTarget, when the root manifest does not declare@wcallahan/javachat-cli, the guard now consults the root'sworkspacesfield, expands the patterns (literal paths plus*/**globs) the way npm does, and — if a member declares the package underdependencies,devDependencies, oroptionalDependencies— runs the unchanged commandnpm install @wcallahan/javachat-cli@latestwithworkingDirectoryset to that member directory.npmArgumentsis identical for the single-package and workspaces-member paths; onlyworkingDirectorychanges (the README's literal command, run "in that project").manifestDeclaresJavaChat,findDeclaringWorkspaceMember,extractWorkspacePatterns,expandWorkspaceGlob,matchWorkspaceSegments,workspaceSegmentToRegex.Testing
cli/test/javachat.test.js,npm test): 50/50 pass (43 pre-existing + 7 new). New tests are observable-boundary tests using the existing fake-npm harness (runCli+ recordednpminvocations +mkdtempfixtures), covering:dependencieswith apackages/*glob → install runs in the memberdevDependencies, and viaoptionalDependencieswith a literal workspace path**glob finds a nested declaring membernpm run pack:check(==npm pack --dry-run): unchanged 4-file manifest (bin/javachat.js,README.md,LICENSE.md,package.json); no new shipped files,test/excluded..binhoisted to root):javachat updaterefused with the exact error and exit 1 — confirming the defect on the unmodified release.javachat updatevia PATH: member spec advanced0.0.1→^0.0.3, hoisted install updated to0.0.3, root manifest unchanged (no pollution), exit 0.^0.0.3, install0.0.3, exit 0 (install runs at the project root, not a member).javachat update→ exit 0 running the--globalinstall. Global package uninstalled afterward; environment verified clean..npmrc install-strategy=nested(nohoist) topology:.bin/javachatlives in the member's ownnode_modules/.bin, so the.binbranch resolvesprojectRoot= the member (which declares the CLI) → member spec advanced to^0.0.3, root clean, exit 0. Confirms the nohoist topology is unaffected by the fix.node bin/javachat.js updatestill refuses with the entrypoint guard and exit 1 (expected guard, not a regression).No tests/procedures were skipped; every item in the plan ran successfully.
Automatic Fixes PRs can be configured here.