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: split codebase into packages and set up monorepository #1177

Merged
merged 78 commits into from
Dec 4, 2019
Merged

Conversation

montezume
Copy link
Contributor

@montezume montezume commented Nov 13, 2019

No description provided.

@tdeekens
Copy link
Contributor

I like this approach of exporting a combined package. Maybe something the MC will always use or teams decide to only pick what they want.

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",
Copy link
Contributor

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.

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 good point.

@commercetools-frontend/ui-kit-text-input should work?

Copy link
Contributor

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.

@montezume
Copy link
Contributor Author

@tdeekens I'll do some research on the FE side, good call.

@montezume
Copy link
Contributor Author

montezume commented Nov 13, 2019

@tdeekens with application-orders, ui-kit or ui-kit related dependencies (react-select, immutable js, slate, etc etc) make up (all gzipped numbers) seem to make up about 1/2 of the bundle size.

@tdeekens
Copy link
Contributor

Oh wow. Immutable.js? Gotta do yarn why on that one I guess.

@montezume
Copy link
Contributor Author

@tdeekens it's from the rich-text-input...

Copy link
Member

@emmenko emmenko left a 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",
Copy link
Member

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.

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 hadn't got to that party yet 😄

"author": "",
"license": "MIT",
"dependencies": {
"@emotion/core": "10.0.22",
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@emmenko emmenko left a 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/*"
Copy link
Member

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?

"author": "",
"license": "MIT",
"dependencies": {
"@emotion/core": "10.0.22",
Copy link
Member

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/**'),
Copy link
Member

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 [
Copy link
Member

Choose a reason for hiding this comment

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

Nit: unnecessary return block

@@ -1,8 +1,8 @@
import React from 'react';
/** @jsx jsx */
Copy link
Member

Choose a reason for hiding this comment

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

What's this for? 🤔

Copy link
Contributor Author

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

Copy link
Contributor Author

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;
};

Copy link
Contributor Author

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';
Copy link
Member

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';
Copy link
Member

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';
Copy link
Member

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 🤔

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, that's what I wanted to mess around with now. 👍 Going to investigate in the VRT app how treeshaking works with the icons.

Copy link
Contributor Author

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';
Copy link
Member

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? 🤔

Copy link
Contributor Author

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 🤔

// For svg icons, we want to get them transformed into React components
// when we import them.
{
test: /\.react\.svg$/,
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Is this still valid?

Copy link
Contributor Author

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

@montezume montezume force-pushed the ml-mono branch 2 times, most recently from c31f6e7 to 2ec5b6b Compare November 19, 2019 14:38
@montezume montezume force-pushed the ml-mono branch 2 times, most recently from 76a28ab to a320e76 Compare November 26, 2019 09:52
@emmenko emmenko changed the title WIP - migration to monorepo feat: split codebase into packages and set up monorepository Dec 3, 2019
@@ -2,7 +2,7 @@
"files": [
{
"path": "visual-testing-app/dist/ui-kit.js",
"maxSize": "130 kB"
"maxSize": "150 kB"
Copy link
Contributor

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 😄.

@emmenko
Copy link
Member

emmenko commented Dec 4, 2019

This is ready to go now from my side. We can start moving code into their packages as follow ups.

Copy link
Contributor

@jonnybel jonnybel left a 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!

@emmenko
Copy link
Member

emmenko commented Dec 4, 2019

Great, I’ll merge this later today then.

@emmenko emmenko merged commit 4ed4f60 into master Dec 4, 2019
@emmenko emmenko deleted the ml-mono branch December 4, 2019 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants