Conversation
pnpm logout
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support for pnpm logout, wiring it into the CLI and implementing the underlying auth token revocation + local credential cleanup logic in @pnpm/auth.commands.
Changes:
- Register a new
logoutcommand in the pnpm CLI (and remove it from the “not implemented” list). - Implement
logoutcommand logic in@pnpm/auth.commands, including registry token revocation andauth.inicleanup. - Add unit tests and a changeset for the new command.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm/src/cmd/notImplemented.ts | Removes logout from the not-implemented command set. |
| pnpm/src/cmd/index.ts | Adds logout to the CLI command registry. |
| auth/commands/src/logout.ts | Implements pnpm logout command behavior (revoke + local config updates). |
| auth/commands/src/login.ts | Tightens LoginFetchOptions.method type. |
| auth/commands/src/index.ts | Exports the new logout command module. |
| auth/commands/test/logout.test.ts | Adds unit test coverage for logout scenarios. |
| .changeset/implement-pnpm-logout.md | Declares minor releases for pnpm and @pnpm/auth.commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a new `pnpm logout` command that logs users out of npm registries.
The command revokes the authentication token on the registry via
DELETE /-/user/token/{token}, then removes it from the local auth.ini
config file. Token revocation is best-effort: local cleanup always
proceeds even if the registry is unreachable or doesn't support
revocation.
Uses the same dependency injection pattern as `pnpm login` for
comprehensive testability.
https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
- Rename revokeToken to tryRevokeToken for self-documenting code - Extract token removal into removeTokenFromAuthIni function - Remove redundant comments that restate function names - Fix toHaveProperty to use array syntax for keys containing dots (avoids Jest property path parsing pitfall) - Add globalWarn when token is found in authConfig but not in auth.ini, informing the user it must be removed manually from .npmrc - Add tests for the .npmrc-only warning case https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
Use path.join in test expectations for the warning message path, since path.join produces backslashes on Windows. https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
Replace manual fetchedUrls arrays with jest.fn() mocks and use toHaveBeenCalledWith for cleaner, more idiomatic assertions. https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
- Rename mockFetch to fetch for shorthand property syntax - Use platform-aware configDir in warning tests instead of path.join on Unix-style paths https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
Single-statement return-with-braces arrow function converted to expression-body form. https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
- Send Authorization: Bearer header in the DELETE token revocation request, otherwise the registry returns 401 and the token is not actually revoked - Make tryRevokeToken return a boolean indicating whether the token was actually revoked, and use it to choose the right warning when the token is not in auth.ini - Drop the misleading "(token removed locally)" suffix from the registry-failure log messages, since the local removal may not happen - Extract getRegistryConfigKey and safeReadIniFile from login.ts and logout.ts into a shared module to prevent the two commands from drifting apart over time - Add tests asserting the Authorization header is sent and that the warning correctly distinguishes between revoked and not-revoked cases https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
When the registry rejects the token revocation AND the token is not in auth.ini, neither side effect of logout actually happened — the user is still authenticated locally and on the registry. Throwing an ERR_PNPM_LOGOUT_FAILED error in this case avoids the misleading "Logged out of ..." success message and gives a non-zero exit code. https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa
5b89d28 to
2fd86ee
Compare
This PR implements the
pnpm logoutcommand, allowing users to log out of npm registries by revoking their authentication tokens both on the registry and locally.https://claude.ai/code/session_016fw5sdGFtBiB9QapMKEuXa