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

Use export * in component indexes and subcomponent reexports #2625

Merged
merged 6 commits into from
Jan 17, 2020

Conversation

BPScott
Copy link
Member

@BPScott BPScott commented Jan 16, 2020

WHY are these changes introduced?

Updating component indexes to use export *. Fixes #2619

277 changed files. Really Ben?

Yeah, sorry. It probably best to review this PR by commit by commit.

WHAT is this pull request doing?

This PR does a few things.

First, a trio of commits that updates all the component (and subcomponent) files (e.g. src/components/ActionMenu/ActionMenu.tsx and src/components/Frame/components/CSSAnimation.tsx) to ensure that the component file exports only the same as what the current index exports.

Second, now that all component files and their indexes (e.g. src/components/ActionMenu/ActionMenu.tsx and src/components/ActionMenu/index.ts) export the same things, update all component indexes to use export *.

Thirdly, update all subcomponent folder indexes (e.g. src/components/Frame/components/index.ts) to reexport to use export *

How to 🎩

Ensure type-check and tests pass.
Note that the contents of the utilities folder and src/components/index.ts have not been touched so the public exports accessed by importing @shopify/polaris are untouched, with the exception of adding the SheetProps, which seem useful publicly.

Once https://github.com/Shopify/web/pull/22624 has been merged into web to stop them reaching into our internal types, then ensure that web passes a type-check with these changes:

  • [in polaris] yarn run build-consumer web
  • [in web] yarn run type-check

@BPScott BPScott requested a review from amrocha January 16, 2020 23:28
@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2020

💦 Potential splash zone of changes introduced to src/**/*.tsx in this pull request:

Files modified30
Files potentially affected63

Details

All files potentially affected (total: 63)
📄 UNRELEASED.md (total: 0)

Files potentially affected (total: 0)

🧩 src/components/AccountConnection/index.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/components/ActionList/components/Item/index.ts (total: 19)

Files potentially affected (total: 19)

🧩 src/components/ActionList/components/Section/index.ts (total: 18)

Files potentially affected (total: 18)

🧩 src/components/ActionList/components/index.ts (total: 18)

Files potentially affected (total: 18)

🧩 src/components/ActionList/index.ts (total: 17)

Files potentially affected (total: 17)

🧩 src/components/ActionMenu/ActionMenu.tsx (total: 2)

Files potentially affected (total: 2)

🧩 src/components/ActionMenu/components/MenuAction/index.ts (total: 4)

Files potentially affected (total: 4)

🧩 src/components/ActionMenu/components/MenuGroup/index.ts (total: 3)

Files potentially affected (total: 3)

🧩 src/components/ActionMenu/components/RollupActions/index.ts (total: 3)

Files potentially affected (total: 3)

🧩 src/components/ActionMenu/components/index.ts (total: 3)

Files potentially affected (total: 3)

🧩 src/components/ActionMenu/index.ts (total: 2)

Files potentially affected (total: 2)

🧩 src/components/ActionMenu/tests/ActionMenu.test.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/components/AfterInitialMount/index.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/components/AppProvider/index.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Autocomplete/components/ComboBox/ComboBox.tsx (total: 1)

Files potentially affected (total: 1)

🧩 src/components/Autocomplete/components/ComboBox/index.ts (total: 1)

Files potentially affected (total: 1)

🧩 src/components/Autocomplete/components/TextField/index.ts (total: 1)

Files potentially affected (total: 1)

🧩 src/components/Autocomplete/components/index.ts (total: 1)

Files potentially affected (total: 1)

🧩 src/components/Autocomplete/index.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Avatar/Avatar.tsx (total: 12)

Files potentially affected (total: 12)

🧩 src/components/Avatar/index.ts (total: 12)

Files potentially affected (total: 12)

🧩 src/components/Avatar/tests/Avatar.test.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Backdrop/index.ts (total: 7)

Files potentially affected (total: 7)

🧩 src/components/Badge/Badge.tsx (total: 26)

Files potentially affected (total: 26)

🧩 src/components/Badge/index.ts (total: 26)

Files potentially affected (total: 26)

🧩 src/components/Badge/tests/Badge.test.tsx (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Banner/index.ts (total: 0)

Files potentially affected (total: 0)

🧩 src/components/Breadcrumbs/index.ts (total: 2)

Files potentially affected (total: 2)

🧩 src/components/Button/Button.tsx (total: 52)

Files potentially affected (total: 52)


This comment automatically updates as changes are made to this pull request.
Feedback, troubleshooting: open an issue or reach out on Slack in #polaris-tooling.

@@ -9,15 +9,15 @@ import {Image} from '../Image';
import styles from './Avatar.scss';
import * as avatars from './images';

export type Size = 'small' | 'medium' | 'large';
type Size = 'small' | 'medium' | 'large';
Copy link
Member Author

Choose a reason for hiding this comment

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

This sort of thing crops up a lot. Using this particular case as an example, Size was exported here but was never reexported by src/Avatar/index.ts and was never used in any other file, so there is no value in exporting it at all.

@@ -116,10 +115,6 @@ describe('<Avatar />', () => {
});

describe('styleClass', () => {
it('defaults to five styles', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is testing an internal implementation detail, I didn't want to expose STYLE_CLASSES so it was easiest to remove this test instead of moving files around to avoid exposing STYLE_CLASSES

@@ -168,7 +168,7 @@ describe('<Button />', () => {

it('does not render the markup for the icon if none is provided', () => {
const button = mountWithAppProvider(<Button />);
expect(button.find(IconWrapper).exists()).toBe(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

IconWrapper shouldn't be exposed outside of Button.

@@ -11,7 +11,7 @@ import {Error, Key, CheckboxHandles} from '../../types';

import styles from './Checkbox.scss';

export interface BaseProps {
export interface CheckboxProps {
Copy link
Member Author

Choose a reason for hiding this comment

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

This crops up in a few files - a BaseProps interface and the component's props that extend from that without adding anything news - so remove BaseProps.


describe('<ChoiceList />', () => {
let choices: ChoiceDescriptor[];
let choices: ChoiceListProps['choices'];
Copy link
Member Author

Choose a reason for hiding this comment

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

Where possible we should look at the values that live on the Props interface instead of exposing the interfaces the Props use

@@ -12,10 +12,10 @@ import {PreferredPosition, PreferredAlignment} from '../PositionedOverlay';
import {Portal} from '../Portal';
import {portal} from '../shared';
import {useUniqueId} from '../../utilities/unique-id';
import {CloseSource, Pane, PopoverOverlay, Section} from './components';
import {PopoverCloseSource, Pane, PopoverOverlay, Section} from './components';
Copy link
Member Author

Choose a reason for hiding this comment

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

Name this import/export correctly where it is initially defined, avoids having to rename it in the Popover/index.ts file

BOTTOM_CLASS_NAMES,
);
expect(sheet.find(CSSTransition).props().classNames).toStrictEqual({
enter: 'Bottom enterBottom',
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit meh, but I think it's a bit better than exposing the BOTTOM_CLASS_NAMES RIGHT_CLASS_NAMES or extracting them out into a file that used by both Sheet and Sheet.test.tsx

@@ -75,12 +75,10 @@ describe('<Spinner />', () => {
it('a large spinner with an unavailable color warns in development', () => {
process.env.NODE_ENV = 'development';

const color = 'black' as Color;
Copy link
Member Author

Choose a reason for hiding this comment

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

That's not even a valid Color shrug

@@ -34,7 +34,7 @@ interface State {

const ParentCollapsibleExpandingContext = createContext(false);

class Collapsible extends React.Component<CollapsibleProps, State> {
class CollapsibleInner extends React.Component<CollapsibleProps, State> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Kill off cases where we export a default value - now things that use AppProvider are exported with a named component, which means that the component index file doesn't need to rename the default export to a named export

@@ -124,99 +120,6 @@ describe('<PositionedOverlay />', () => {
});
});

describe('intersectionWithViewport', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is testing internal details, presumably because it's hard to to test this using just the component.

Move this function to math.ts and do the tests in math.test.ts to avoid exporting intersectionWithViewport from PositionedOverlay.tsx

@BPScott BPScott force-pushed the export-star-components branch 2 times, most recently from 4e4b355 to cb56bfa Compare January 17, 2020 19:47
Copy link
Contributor

@amrocha amrocha left a comment

Choose a reason for hiding this comment

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

We went over this together, looks good once the problems in web have been fixed

@BPScott BPScott force-pushed the export-star-components branch from cb56bfa to f2ec124 Compare January 17, 2020 22:08
@BPScott BPScott merged commit a487f75 into master Jan 17, 2020
@BPScott BPScott deleted the export-star-components branch January 17, 2020 22:18
This was referenced Jan 18, 2020
@danrosenthal danrosenthal restored the export-star-components branch January 23, 2020 15:17
@dleroux dleroux temporarily deployed to production January 27, 2020 13:38 Inactive
@danrosenthal danrosenthal deleted the export-star-components branch February 27, 2020 19:57
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.

Proposal: Use export * in component indexes
3 participants