-
Notifications
You must be signed in to change notification settings - Fork 26
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: split codebase into packages and set up monorepository #1177
Conversation
I like this approach of exporting a I think generally exporting multiple bundles and modules is nice and the approach to gradually migrate there is very nice. Have you checked for our MC apps what porportion of the bundle size is uikit so we can evaluate the gains for us? |
@@ -0,0 +1,28 @@ | |||
{ | |||
"name": "@ui-kit/multiline-text-input", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit but I bet this namespace will be taken. Also nested namespaces don't work. So @ct-fe/uikit/text-input
won't do. I guess @ct-fe/uikit-textinput
could be something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good point.
@commercetools-frontend/ui-kit-text-input
should work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so. Or a completley new scope #commercetools-uikit/text-input
.
@tdeekens I'll do some research on the FE side, good call. |
@tdeekens with |
Oh wow. Immutable.js? Gotta do |
@tdeekens it's from the rich-text-input... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach looks promising. I think we need to plan a bit how we want to:
- move to a monorepo setup as the first step
- split up the source code into their respective packages in the long term
I would expect eventually to have the source code in each package, then the original package @ct-fe/ui-kit
is just a mere proxy from all other packages (no source code there).
package.json
Outdated
@@ -86,7 +89,8 @@ | |||
"slate-react": "0.22.10", | |||
"tiny-invariant": "1.0.6", | |||
"use-popper": "1.1.6", | |||
"warning": "4.0.3" | |||
"warning": "4.0.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a monorepo, the root package.json
should not have any runtime dependencies, as it simply does not make sense to. Instead runtime deps should be defined by each package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I hadn't got to that party yet 😄
packages/avatar/package.json
Outdated
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@emotion/core": "10.0.22", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering "how easy" it would be here to miss some runtime dep.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far it seems like you get warnings in the build but not failures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean within the monorepo it shouldn't matter, as packages get hoisted. I'm talking about consumers of the package. If some runtime dep is not defined, you will probably get an error then.
I guess this would make more sense to do once the source code is moved into its own package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the plan with this PR? Should we move everything at once? Is it just for testing things out and then we start migrating things one by one in separate PRs?
If we start moving components into their own package, I would prefer then to do it "properly" by moving the source code and have the dependency + export in the main ui-kit
package.
package.json
Outdated
"packages/*", | ||
"packages/buttons/*", | ||
"packages/typography/*", | ||
"packages/inputs/*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep the packages flat?
packages/avatar/package.json
Outdated
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@emotion/core": "10.0.22", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean within the monorepo it shouldn't matter, as packages get hoisted. I'm talking about consumers of the package. If some runtime dep is not defined, you will probably get an error then.
I guess this would make more sense to do once the source code is moved into its own package.
rollup.config.js
Outdated
@@ -26,7 +32,7 @@ const configureRollupPlugins = (options = {}) => | |||
// See also https://medium.com/@kelin2025/so-you-wanna-use-es6-modules-714f48b3a953 | |||
// Transpile sources using our custom babel preset. | |||
babel({ | |||
exclude: ['node_modules/**'], | |||
exclude: path.join(__dirname, '/node_modules/**'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better now 😉
rollup.config.js
Outdated
file: pkg.module, | ||
format: 'esm', | ||
const createConfig = cliArgs => { | ||
return [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: unnecessary return
block
src/components/avatar/avatar.js
Outdated
@@ -1,8 +1,8 @@ | |||
import React from 'react'; | |||
/** @jsx jsx */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the only JSX rendered by this component using the css prop, the built version drops all usages of react.createELement and replaces it with JSX
so we get warnings about unused 'react' import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of what Text
looks like
import 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import requiredIf from 'react-required-if';
import { isNil } from 'lodash-es';
import { oneLine } from 'common-tags';
import { css, jsx } from '@emotion/core';
import vars from '@commercetools-uikit/custom-properties';
... more stuff
var Text = function Text(_ref) {
var intlMessage = _ref.intlMessage,
children = _ref.children;
return intlMessage ? jsx(FormattedMessage, intlMessage) : children;
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove this
@@ -2,9 +2,9 @@ import React from 'react'; | |||
import PropTypes from 'prop-types'; | |||
import { css } from '@emotion/core'; | |||
import { omit } from 'lodash'; | |||
import vars from '../../../../materials/custom-properties'; | |||
import Text from '@commercetools-uikit/text'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if it would make sense to have the package named @commercetools-uikit/typography
, which exports individual components like import { Header, Body, ... }
@@ -1,7 +1,7 @@ | |||
import PropTypes from 'prop-types'; | |||
import invariant from 'tiny-invariant'; | |||
import styled from '@emotion/styled'; | |||
import vars from '../../../materials/custom-properties'; | |||
import vars from '@commercetools-uikit/custom-properties'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name this package something like @commercetools-uikit/design-system
or @commercetools-uikit/design-tokens
? 🤔
@@ -3,9 +3,9 @@ import PropTypes from 'prop-types'; | |||
import requiredIf from 'react-required-if'; | |||
import { useIntl } from 'react-intl'; | |||
import { css } from '@emotion/core'; | |||
import { AngleUpIcon, AngleDownIcon } from '@commercetools-uikit/icons'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember, one of the issues with tree shaking was related to the svgs...should we maybe publish each icon individually? If we bundle them all together we might end up with the same problem 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's what I wanted to mess around with now. 👍 Going to investigate in the VRT app how treeshaking works with the icons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, so right now if you use MultilineTextInput
, you end up with all of the icons. I'll look into alternatives now.
@@ -2,7 +2,7 @@ import React from 'react'; | |||
import PropTypes from 'prop-types'; | |||
import { CellMeasurer, CellMeasurerCache, MultiGrid } from 'react-virtualized'; | |||
import sortBy from 'lodash/sortBy'; | |||
import getScrollbarSize from 'dom-helpers/scrollbarSize'; | |||
import getScrollbarSize from 'dom-helpers/util/scrollbarSize'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a bug fix? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this. There must be some weird resolution happening, because when I open node_modules
on master, the file is at scrollbarSide
, yet when I open node modules here, it's at utils/scrollbarSize
and you get a lint warning 🤔
visual-testing-app/webpack.config.js
Outdated
// For svg icons, we want to get them transformed into React components | ||
// when we import them. | ||
{ | ||
test: /\.react\.svg$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why we need this now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't, can remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah, should not noeed that sorry
c31f6e7
to
2ec5b6b
Compare
76a28ab
to
a320e76
Compare
@@ -2,7 +2,7 @@ | |||
"files": [ | |||
{ | |||
"path": "visual-testing-app/dist/ui-kit.js", | |||
"maxSize": "130 kB" | |||
"maxSize": "150 kB" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the point of this to... just kidding 😄.
…rds compatibility
This is ready to go now from my side. We can start moving code into their packages as follow ups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems OK. Great work!
Great, I’ll merge this later today then. |
No description provided.