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

TypeScript versions of the homepage starters #95

Merged

Conversation

aghreed
Copy link
Contributor

@aghreed aghreed commented Mar 8, 2022

Purpose

This PR sets up the ability to handle publishing TS and JS "source" versions of the starters. It also converts all the components over to .tsx as the first step to add type safety to the front-end of the starter.

Testing

These are currently deployed to Gatsby Cloud:
Contentful: https://gatsbycontentfulhomepagets.gatsbyjs.io/
DatoCMS: https://gatsbydatocmshomepagets.gatsbyjs.io/
Drupal: https://gatsbydrupalhomepagets.gatsbyjs.io/
WP: https://gatsbywordpresshomepagets.gatsbyjs.io/

What's included?

  • Updates to the publish.js script to support transpiling the TS source to "source" JS as well as publishing the four new TS flavors of the starters
  • Conversion of all front end components and pages to TS
  • Updates to documentation to account for differences in the READMEs for TS flavors of the starters

@gatsby-cloud
Copy link

gatsby-cloud bot commented Mar 8, 2022

Gatsby Cloud Build Report

homepage-starters-dev

🎉 Your build was successful! See the Deploy preview here.

Build Details

View the build logs here.

🕐 Build time: 29s

Performance

Lighthouse report

Metric Score
Performance 💚 99
Accessibility 💚 97
Best Practices 💚 100
SEO 💚 92

🔗 View full report

@aghreed aghreed changed the base branch from main to chore/typescript-all-the-things March 11, 2022 19:15
@aghreed aghreed changed the title Support TS variations of the starters Update publish script to support TS publishing and convert all src/components to TS Mar 11, 2022
scripts/data.js Outdated Show resolved Hide resolved
@aghreed aghreed marked this pull request as ready for review March 11, 2022 22:02
@aghreed aghreed requested a review from jxnblk March 11, 2022 22:02
Copy link

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

I'm not sure why you're not doing it all in one PR but, i've added some comments

__dirname,
"plugins",
plugin,
"src",
"colors.css.ts"
"colors.css"
Copy link

@wardpeet wardpeet Mar 13, 2022

Choose a reason for hiding this comment

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

Any reason why you don't add ts extension here? Or you remove them anywhere or you add them everywhere but I think the goal here is to remove them everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, we don't want them around anywhere. For VSCode users (myself included), you need to omit the .ts extension in the import statement in order for VSCode's in-IDE type checking and auto-complete functionality to work properly. And when I did that across the board in this PR, the webpack alias also needed updating.

If I were to add the .ts back to this line, I consistently get this build error:
Screen Shot 2022-03-14 at 4 11 10 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like Vanilla Extract still handles these correctly without the extension, right? It's unclear from the documentation whether that's a requirement versus just a convention, but 👍 if this all works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lennart's example repo omits .ts from import statements as well

scripts/data.js Outdated Show resolved Hide resolved
jobTitle?: string
}

function AboutProfile(props: AboutProfileProps) {

Choose a reason for hiding this comment

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

Don't you get type warnings? In React land with typescript, you should do

Suggested change
function AboutProfile(props: AboutProfileProps) {
const AboutProfile: React.FC<AboutProfileProps> = function AboutProfile(props: AboutProfileProps) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, no type warnings!

I can certainly update to type all the components with React.FC, however I was trying to minimize the changes to the source code in my effort to convert over to TypeScript, and additionally, I tend to agree with the opinions articulated in this article: https://fettblog.eu/typescript-react-why-i-dont-use-react-fc/

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the correct answer to this would be, but I'd say we should follow any "blessed" practices that might exist from React and ensure that our Gatsby style is consistent across the board. @wardpeet do we have much of a precedent set with other starters or TS docs, etc.?

@aghreed aghreed mentioned this pull request Mar 15, 2022
Copy link
Contributor

@jxnblk jxnblk left a comment

Choose a reason for hiding this comment

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

Looking great so far! I'll take another pass at this in the morning, but wanted to comment mostly around the UI components and leave some notes about some of the things we chatted about earlier for consideration/discussion

scripts/data.js Outdated Show resolved Hide resolved
scripts/data.js Outdated Show resolved Hide resolved
src/components/about-hero.tsx Outdated Show resolved Hide resolved
src/components/about-hero.tsx Show resolved Hide resolved
jobTitle?: string
}

function AboutProfile(props: AboutProfileProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the correct answer to this would be, but I'd say we should follow any "blessed" practices that might exist from React and ensure that our Gatsby style is consistent across the board. @wardpeet do we have much of a precedent set with other starters or TS docs, etc.?


export default function CaretDown({
direction = "down",
size = 9,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we use the size prop at all; I'd be keen to remove it to simplify the API a little

src/components/ui.css.ts Outdated Show resolved Hide resolved
@aghreed aghreed changed the title Update publish script to support TS publishing and convert all src/components to TS Update publish script to support TS publishing and convert all src to TS Mar 16, 2022
scripts/data.js Outdated Show resolved Hide resolved
scripts/create-readmes.mjs Outdated Show resolved Hide resolved
@aghreed aghreed changed the title Update publish script to support TS publishing and convert all src to TS TypeScript versions of the homepage starters Mar 23, 2022
@aghreed aghreed requested review from jxnblk and wardpeet March 23, 2022 21:46
@aghreed aghreed changed the base branch from chore/typescript-all-the-things to main March 23, 2022 21:46
Copy link
Contributor

@jxnblk jxnblk left a comment

Choose a reason for hiding this comment

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

Think this is looking very close. Left a few comments and questions but nothing major from what I can see

scripts/publish.js Outdated Show resolved Hide resolved
scripts/publish.js Outdated Show resolved Hide resolved
scripts/publish.js Outdated Show resolved Hide resolved
const dest = path.join(
dir.dist,
name,
srcFilename.replace(extension, ".js")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will likely work, but I think the better way to replace the extension is by using path.basename (i.e. in the odd case that you had a file named foo.ts.bar.ts)

@@ -125,8 +128,8 @@ For this example, we'll create a new "Banner" component.

1. Next, create the Banner component:

```jsx
// src/components/banner.js
```jsx fileExt
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't checked yet, but I'm guessing the jsx syntax highlighting on GitHub works for tsx syntax, but if it doesn't 100%, I would guess it'd work the other way around. Then again, maybe it doesn't matter because there are significant changes to the code examples' contents

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought about that, but didn't think it was worth the trouble because the syntax highlighting won't be different. If we did add in an interface for the props, that wouldn't be highlighted the same way with jsx and tsx but I figure people will be able to figure out adding:

interface BannerProps {
    heading: string;
    text: string;
}

without us holding their hands on this one.

scripts/create-readmes.mjs Outdated Show resolved Hide resolved
export const radii = styleVariants(theme.radii, (borderRadius) => ({
overflow: "hidden",
borderRadius,
}))
export const order = styleVariants([0, 1, 2, 3], (order) => ({
export const order = styleVariants({ 0: 0, 1: 1, 2: 2, 3: 3 }, (order) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not typed to accept array objects in vanilla extract?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, styleVariants is typed to accept a Record as it's first argument

{
...theme.space,
auto: "auto",
},
(marginTop) => ({ marginTop })
)
margin.bottom = styleVariants(

export const marginBottom = styleVariants(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a problem, but this just feels less elegant than grouping into an object, but keeps things more consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I changed this one because of the TS intellisense warning:

Screen Shot 2022-03-24 at 7 37 57 PM

styles.margin.right[-right],
styles.margin.top[-top],
styles.margin.bottom[-bottom],
left && styles.marginLeft[-left],
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought these props could be 0, but I might be wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They could, but there would be no point in passing 0 as the value since you wouldn't be "nudging" at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

In which case, this would pass a 0 to the className, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, no I'm wrong, this goes through .filter(Boolean)

src/pages/404.tsx Outdated Show resolved Hide resolved
@aghreed aghreed requested a review from jxnblk March 28, 2022 19:30
Copy link
Contributor

@jxnblk jxnblk left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for getting this all together and getting the readme generation in there as well!

)
}
node.value = node.value.replace("$fileExt", opts.fileExt)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good! A lot simpler and doesn't mix up the directive syntax

@aghreed aghreed merged commit dd3ab9a into main Mar 28, 2022
@aghreed aghreed deleted the aghreed/sc-47188/spike-add-a-ts-variation-to-the-homepage branch March 28, 2022 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants