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

feat: remove possible trailing slash from appName prompt #1466

Merged
merged 6 commits into from
Jun 17, 2023

Conversation

brunoeduardodev
Copy link
Contributor

Closes #1460

✅ Checklist

  • I have followed every step in the contributing guide (updated 2022-10-06).
  • The PR title follows the convention we established conventional-commit
  • I performed a functional test on my final commit

Changelog

Ignore trailing slashes when prompting the app name


Screenshots

When prompting ./

image

When prompting any path with a trailing slash

image

💯

@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2023

🦋 Changeset detected

Latest commit: f2a49bc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-t3-app Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 8, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
create-t3-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2023 1:33am

@vercel
Copy link

vercel bot commented Jun 8, 2023

@brunoeduardodev is attempting to deploy a commit to the t3-oss Team on Vercel.

A member of the Team first needs to authorize it.

@brunoeduardodev brunoeduardodev changed the title feat: emove possible trailing slash from appName prompt feat: remove possible trailing slash from appName prompt Jun 8, 2023
@github-actions github-actions bot added the 📌 area: cli Relates to the CLI label Jun 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 83
🟢 Accessibility 100
🟢 Best practices 100
🟢 SEO 100
🔴 PWA 30

Lighthouse ran on https://create-t3-app-git-fork-brunoeduardodev-next-t3-oss.vercel.app/

@brunoeduardodev
Copy link
Contributor Author

I don't fully love this solution since there's a duplicated checking, both on the validate function and after getting the prompt result, do y'all have any suggestions on this?

@brunoeduardodev
Copy link
Contributor Author

Currently the PR doesn't affect appNames provided by the CLI, the project creation works, but the project name, when passing a trailing slash direct to the CLI results in a empty appName, in this case might make sense doing this validation on parseNameAndPath but I'm not sure if this would be too much, thoughts?

@c-ehrlich
Copy link
Member

c-ehrlich commented Jun 8, 2023

Currently the PR doesn't affect appNames provided by the CLI, the project creation works, but the project name, when passing a trailing slash direct to the CLI results in a empty appName, in this case might make sense doing this validation on parseNameAndPath but I'm not sure if this would be too much, thoughts?

not sure about implementation details. but in terms of how it works for the user, it should be consistent for:

  • typing the app name in response to the prompt
  • adding it as an arg to the CLI
  • CI (same as above I think?)

@brunoeduardodev
Copy link
Contributor Author

I've just changed the implementation to remove the trailing space after the initial appName is get, so potential trailing slashes are removed from the prompt, args or ci,

usecase:

./ by args (appName becomes cwd after parsing)

image

./ by prompt (appName becomes cwd after parsing)

image

./some/path/ by args (appName becomes "path" after parsing)

image

./some/path/ by prompt (appName becomes "path" after parsing)

image

Copy link
Member

@c-ehrlich c-ehrlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks really clean :)

one remaining issue is that it doesn't catch a name that is just / and thus turned into an empty string, causing the command line to crash (if the user submits an empty string the normal way, their app gets named my_t3_app instead).

this behaviour should definitely be taken care of, but not sure what's better:

  • doing the same thing as when an empty string is provided at the start
  • turning an app name of / into . as it feels like this might be the user intent (they almost certainly didnt intend to init at the root of their file system)
  • an error of some sort

@brunoeduardodev
Copy link
Contributor Author

I see, currently the create-t3-app gives a validation error when a user prompts /, and when passing / through args it goes to the root dir,

So my suggestion would be keeping this behavior, since there might be some kind of weird scenario where it's wanted to create the app through the root,

this would mean we are going to remove trailing slashes only if there's at least 2 characters, do you have thoughts?

@c-ehrlich
Copy link
Member

I see, currently the create-t3-app gives a validation error when a user prompts /, and when passing / through args it goes to the root dir,

So my suggestion would be keeping this behavior, since there might be some kind of weird scenario where it's wanted to create the app through the root,

this would mean we are going to remove trailing slashes only if there's at least 2 characters, do you have thoughts?

Sounds good!

@brunoeduardodev
Copy link
Contributor Author

Just added a commit adding this behavior, I wonder if we should give a hint to the user telling then to use . if they want to install the project on the current dir.

I've also moved the verification to an util function, not sure if utils folder was the best place for that.

From prompt

image

From args

image

Copy link
Member

@c-ehrlich c-ehrlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good :) Thanks for the PR!

@c-ehrlich c-ehrlich added this pull request to the merge queue Jun 17, 2023
Merged via the queue into t3-oss:next with commit e8b68d9 Jun 17, 2023
23 checks passed
devvianto605 pushed a commit to devvianto605/create-devviantex-nextjs-app-deprecated that referenced this pull request Jun 9, 2024
* feat: remove possible trailing slash from appName prompt

* chore: add changeset

* feat: aslo remove trailing slash from args and ci

* fix: only remove trailing slash when there's at least 2 characters

* feat: removeTralingSlash file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📌 area: cli Relates to the CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: CLI add a ./ option for the project name
2 participants