Skip to content
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
JoshuaKGoldberg opened this issue Jun 17, 2023 · 0 comments · Fixed by #591
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

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

Right now, if you run npx tidelift-me-up --username "#JI*#@%OJSL" (some username that definitely doesn't exist), it does ... nothing.

$ npx tidelift-me-up --username "#JI*#@%OJSL"
$ 

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:

const userPackages = (await npmUserPackages(username)).filter(
createUserPackagesFilter({ ownership, since: new Date(since), username })
);

@JoshuaKGoldberg JoshuaKGoldberg added good first issue Good for newcomers, please hop on! type: feature New enhancement or request status: accepting prs Please, send a pull request to resolve this! labels Jun 17, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title 🚀 Feature: Throw an error when the user has no packages on npm 🚀 Feature: Change result type to indicate when the user has no packages on npm Jan 9, 2025
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant