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

Support shorthand scoped templates #8298

Merged
merged 3 commits into from Jan 12, 2020
Merged

Conversation

kevin940726
Copy link
Contributor

Continue from #7991. Allow @scope shorthand for template package name.

The motivation comes from storybookjs/storybook#9327 (comment), where when library authors want to provide cra template under their scoped name, typing --template @storybook/cra-template every time seems tedious. Instead, it'd be better if the users can just type --template @storybook to use the template @storybook/cra-template. Since @ is not a valid character for npm package name, it should be backward-compatible.

Tests

To list all the possible combinations.

provided template downloaded package
--template cra-template cra-template
--template cra-template-typescript cra-template-typescript
--template typescript cra-template-typescript
--template @scope/cra-template-typescript @scope/cra-template-typescript
--template @scope/typescript @scope/cra-template-typescript
--template @scope (Added) @scope/cra-template

This PR also fixes a bug (?) when users provided --template cra-templates would still download cra-templates while it should be cra-template-cra-templates, as templates should be prefixed by cra-template-, judging from the doc. We can instead allow the other way around though if that makes more sense.

Pinging @mrmckeb as we mentioned it in the issue before :)

Copy link
Contributor

@mrmckeb mrmckeb 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 great @kevin940726! Are you able to add any tests for this?

@kevin940726
Copy link
Contributor Author

kevin940726 commented Jan 9, 2020

@mrmckeb Sure! I was trying to do so too, but couldn’t find an appropriate place to put those tests. Should I create e2e tests? Any recommended example?

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 9, 2020

You could create an E2E test... but those are quite flimsy right now.

Perhaps for now we'll leave it, and we'll cover this as we rewrite tests towards v4.

Copy link
Contributor

@mrmckeb mrmckeb left a comment

Choose a reason for hiding this comment

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

This is great overall, just a few minor thoughts on the comments - let me know what you think.

packages/create-react-app/createReactApp.js Outdated Show resolved Hide resolved
packages/create-react-app/createReactApp.js Outdated Show resolved Hide resolved
packages/create-react-app/createReactApp.js Outdated Show resolved Hide resolved
Comment on lines 648 to 650
// @SCOPE/cra-template
// cra-template-NAME
// @SCOPE/cra-template-NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

As above... :)

Co-Authored-By: Brody McKee <mrmckeb@users.noreply.github.com>
@kevin940726
Copy link
Contributor Author

@mrmckeb That definitely makes them clearer 👍! Just updated :)

@mrmckeb mrmckeb added this to the 3.3.1 milestone Jan 9, 2020
@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 9, 2020

I've tagged this for 3.3.1, as I don't think it's worth delaying this for v3.4 - and we could argue that it is a bug that it doesn't work this way already.

Copy link
Contributor

@heyimalex heyimalex left a comment

Choose a reason for hiding this comment

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

LGTM, tested each case using that code and it works.

@mrmckeb
Copy link
Contributor

mrmckeb commented Jan 12, 2020

Thanks @heyimalex! Merging now @kevin940726 - great work.

@mrmckeb mrmckeb merged commit fa85f03 into facebook:master Jan 12, 2020
@kevin940726 kevin940726 deleted the scope-template branch January 12, 2020 14:04
@lock lock bot locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants