-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@@ -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'; |
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.
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', () => { |
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.
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); |
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.
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 { |
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.
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']; |
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.
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'; |
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.
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', |
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.
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; |
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.
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> { |
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.
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', () => { |
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.
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
4e4b355
to
cb56bfa
Compare
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 went over this together, looks good once the problems in web have been fixed
cb56bfa
to
f2ec124
Compare
WHY are these changes introduced?
Updating component indexes to use
export *
. Fixes #2619277 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
andsrc/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
andsrc/components/ActionMenu/index.ts
) export the same things, update all component indexes to useexport *
.Thirdly, update all subcomponent folder indexes (e.g.
src/components/Frame/components/index.ts
) to reexport to useexport *
How to 🎩
Ensure type-check and tests pass.
Note that the contents of the
utilities
folder andsrc/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:
yarn run build-consumer web
yarn run type-check