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

build(forma-36-react-components): build with tsdx #611

Merged
merged 1 commit into from
Nov 24, 2020
Merged

Conversation

denkristoffer
Copy link
Collaborator

@denkristoffer denkristoffer commented Oct 29, 2020

Purpose of PR

This PR moves @contentful/forma-36-react-components to a tsdx build setup. To allow this I had to do some subtasks:

  • Change to SVG components instead of importing through Babel (This can be supported by Rollup as well, but then we have a difference with Storybook, which uses Webpack. Let's discuss this later).
  • Lint fixes all over the place as tsdx bring its own eslint config, which we cannot really extend.
  • Changing some directory structures, like moving forma-36-react-components test config into src/ to have it included in the TS rootDir.
  • We cannot extend the tsdx babel config outside of tsdx, which means that we cannot get jest to use it. I decided the best solution was then to use tsdx's default config as is, because at least it will be used the same everywhere. This means that we cannot choose our own babel modules and have them work in tests!
  • This currently doesn't build a file per component like the old setup, so imports like import { CardActions } from '@contentful/forma-36-react-components/dist/components/Card/CardActions/CardActions'; don't work. Do we want to support this?

Some issues

eslint doesn't allow shared configs to bring their own modules, who knew! See eslint/eslint#3458 – this is crazy to me. Anyway, that means we'll have either to "reinstall" the modules used by tsdx's eslint config, like eslint-config-prettier, in each package or we can avoid using hoisting. I prefer the first option because it means less duplication.

PR Checklist

  • I have read the relevant readme.md file(s)
  • All commits follow our Git commit message convention
  • Tests are added/updated/not required
  • Tests are passing
  • Storybook stories are added/updated/not required
  • Usage notes are added/updated/not required
  • Has been tested based on Contentful's browser support
  • Doesn't contain any sensitive information

@denkristoffer

This comment has been minimized.

@denkristoffer

This comment has been minimized.

@netlify
Copy link

netlify bot commented Nov 4, 2020

Deploy preview for forma-36-react-components ready!

Built with commit 2892a94

https://deploy-preview-611--forma-36-react-components.netlify.app

Copy link
Contributor

@gui-santos gui-santos left a comment

Choose a reason for hiding this comment

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

LGTM! Should we merge this before #610 ?

// require.resolve('babel-loader'),
// require.resolve('react-docgen-typescript-loader'),
// ],
// });

This comment was marked as resolved.

@denkristoffer
Copy link
Collaborator Author

@gui-santos Sorry, it's not ready yet 😬 The tests aren't running, I think it's because of tsdx issues that I hope will work better after Yarn workspaces are in.

@gui-santos
Copy link
Contributor

@gui-santos Sorry, it's not ready yet 😬 The tests aren't running, I think it's because of tsdx issues that I hope will work better after Yarn workspaces are in.

Hmmmm I see!

Should we wait to merge the workspaces because of the frozen deployment? (I'm thinking on the case that someone needs to push a hotfix in the webapp and then it would try to get forma in the pipeline)

@denkristoffer
Copy link
Collaborator Author

denkristoffer commented Nov 9, 2020

I got the tests running, but they're currently failing because SVGs seem to not be loaded correctly. Same issue as seen here – will look into this more later, but help is welcome.

viewBox="0 0 9 18"
xmlns="http://www.w3.org/2000/svg"
width="1em"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these width/height changes expected? I see a lot of them in different svgs and snapshots

Copy link
Collaborator Author

@denkristoffer denkristoffer Nov 16, 2020

Choose a reason for hiding this comment

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

They're from the way @svgr/cli generates components based on SVG files. I don't know if it would be preferable to keep the sizes locked with px?

Copy link
Contributor

@gui-santos gui-santos 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!

@@ -8,9 +8,7 @@
"packages/components/*"
],
"nohoist": [
"@contentful/forma-36-fcss/node-sass-import",
"**/tsdx",
"**/tsdx/**"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Comment on lines +1 to +12
import * as React from 'react';

function SvgArrowDown(props: React.SVGProps<SVGSVGElement>) {
return (
<svg width="1em" height="1em" viewBox="0 0 24 24" {...props}>
<path d="M7 10l5 5 5-5z" />
<path d="M0 0h24v24H0z" fill="none" />
</svg>
);
}

export default SvgArrowDown;
Copy link
Contributor

Choose a reason for hiding this comment

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

@burakukula look!
This is basically what we need for an icon package

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah! exactly! 🙂

@gui-santos
Copy link
Contributor

  • Change to SVG components instead of importing through Babel (This can be supported by Rollup as well, but then we have a difference with Storybook, which uses Webpack. Let's discuss this later).

This is perfect! Since we are dating with the idea of making a separate package for icons. Moving them to components is 50% the work already hahahaha

  • Lint fixes all over the place as tsdx bring its own eslint config, which we cannot really extend.

If it's a good eslint config, I'm ok with that

  • This currently doesn't build a file per component like the old setup, so imports like import { CardActions } from '@contentful/forma-36-react-components/dist/components/Card/CardActions/CardActions'; don't work. Do we want to support this?

I don't this will be a problem 😄

eslint doesn't allow shared configs to bring their own modules, who knew! See eslint/eslint#3458 – this is crazy to me. Anyway, that means we'll have either to "reinstall" the modules used by tsdx's eslint config, like eslint-config-prettier, in each package or we can avoid using hoisting. I prefer the first option because it means less duplication.

I prefer the first option too 👍

Copy link
Contributor

@burakukula burakukula left a comment

Choose a reason for hiding this comment

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

Looks amazing! 🎉
Thanks for that contribution and yeah, most of the work for the icon package is done 🤯 I will try take it and move it to the package in the PR proposal in the next couple of days.

Copy link
Collaborator

@mshaaban0 mshaaban0 left a comment

Choose a reason for hiding this comment

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

Awesome work 🍪

I'm not sure about width="1em" height="1em" on svgs especially since the viewbox is still in pixels as well. If there's a way to keep them in pixels it would be awesome.

I'm going to hold of #641 until this is merged, and hope conflicts would be nice to me 😏

"package.json",
"dist"
"dist",
"src"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to have src files in the npm package?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tbh I had the same thought. It's the tsdx default, but I'm not 100% sure why they add it.

Copy link
Contributor

Choose a reason for hiding this comment

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

None of our experience components have it: https://github.com/contentful/experience-packages/blob/master/packages/experience-components/package.json, so I'd not include it here too.

@denkristoffer
Copy link
Collaborator Author

@mshaaban0 (and /cc @suevalov): SVGR automatically adds missing width and height attributes when the output mode is icon, which I used in this case. The svgr PR here doesn't have a lot of reasoning for this, but I trust them to know what they're doing. What do you think, can we keep them or should I remove the attributes?

@suevalov
Copy link
Contributor

@denkristoffer are width and height attributes present in the output dist of the main branch? If they're the same then I have no objections

Copy link
Contributor

@suevalov suevalov left a comment

Choose a reason for hiding this comment

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

Let's remove src folder from the built package, but otherwise is 🎖️

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.

None yet

6 participants