generated from JoshuaKGoldberg/create-typescript-app
-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Feature: Change result type to indicate when the user has no packages on npm #17
Closed
3 tasks done
Labels
good first issue
Good for newcomers, please hop on!
status: accepting prs
Please, send a pull request to resolve this!
type: feature
New enhancement or request
Comments
3 tasks
3 tasks
3 tasks
JoshuaKGoldberg
pushed a commit
that referenced
this issue
Feb 24, 2025
…es (#591) <!-- 👋 Hi, thanks for sending a PR to tidelift-me-up! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #17 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/tidelift-me-up/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/tidelift-me-up/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> ### Change 1: updated tideliftMeUp() In the `tidelift-me-up` package, the `npm-username-to-packages` package is used to fetch a user's npm packages. However, `npm-username-to-packages` doesn't distinguish between an invalid user and a valid user with zero packages — both scenarios return an empty array (`[]`). To address this limitation, I added logic to throw an error if an invalid username is entered or if a valid user user has zero packages: ```jsx if (!allUserPackages || allUserPackages.length === 0) { throw new Error(`No packages found for npm username: ${username}.`); } ``` ### Change 2: updated CLI I then updated the CLI so it logs a message in red that says`Could not find packages for ${username}` if an invalid username or a valid user who has zero packages are entered. Previously, it returned nothing (as detailed in #17). ### Bonus: Bug Fix Additionally, these changes unintentionally fixed a bug where usernames containing `#` in the beginning or just double quotes where entered into the CLI, it returned one of the two errors: - `Error: Either log in to npm or provide a username with --username.` - `SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON` ex: ```jsx npx tidelift-me-up --username "#JI*#@%OJSL" npx tidelift-me-up --username "" ``` Now, the CLI catches these errors and logs a message saying `Could not find packages for ${username}`. Not sure if this was the best way to handle these errors so open to suggestions! ### Testing First, I locally ran the unit tests: ```jsx pnpm build pnpm run test ``` Then, I manually tested the CLI with the following scenarios: - **No npm username passed**: `npx tidelift-me-up` - **Valid npm username with packages**: `npx tidelift-me-up --username joshuakgoldberg` - **Valid npm username with no packages**: `npx tidelift-me-up --username maggi3` - **Invalid npm username (no special characters)**: `npx tidelift-me-up --username 098jljlbvvfgg` - **Invalid npm username (with special characters)**: `npx tidelift-me-up --username "#JI*#@%OJSL"` 🧸
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
good first issue
Good for newcomers, please hop on!
status: accepting prs
Please, send a pull request to resolve this!
type: feature
New enhancement or request
Bug Report Checklist
main
branch of the repository.Overview
Right now, if you run
npx tidelift-me-up --username "#JI*#@%OJSL"
(some username that definitely doesn't exist), it does ... nothing.That could be confusing for folks who mistype their username. Let's have the package
throw new Error
when the user has no packages published to npm.Additional Info
Right now, we fetch user npm packages with the
npm-user-packages
package here:tidelift-me-up/src/tideliftMeUp.ts
Lines 24 to 26 in 148ddcb
The text was updated successfully, but these errors were encountered: