Skip to content

Commit

Permalink
fix(App): babel transformation for the react-core modules (#279)
Browse files Browse the repository at this point in the history
* fix(App): babel transformation for the react-core modules

* Updated react-core layout imports and removed the mapper

* Updated the babel config

* Removed the trailing slashes
  • Loading branch information
Fewwy authored May 27, 2022
1 parent 38ecc40 commit f04ac70
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 77 deletions.
31 changes: 31 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const path = require('path');
const glob = require('glob');

module.exports = {
presets: [
// Polyfills
Expand All @@ -13,6 +16,34 @@ module.exports = {
// Devs tend to write `import { someIcon } from '@patternfly/react-icons';`
// This transforms the import to be specific which prevents having to parse 2k+ icons
// Also prevents potential bundle size blowups with CJS
[
'transform-imports',
{
'@patternfly/react-core': {
transform: (importName) => {
let res;
const files = glob.sync(
path.resolve(
__dirname,
`./node_modules/@patternfly/react-core/dist/js/**/${importName}.js`
)
);
if (files.length > 0) {
res = files[0];
} else {
throw `File with importName ${importName} does not exist`;
}

res = res.replace(path.resolve(__dirname, './node_modules/'), '');
res = res.replace(/^\//, '');
return res;
},
preventFullImport: false,
skipDefaultConversion: true,
},
},
'react-core',
],
[
'transform-imports',
{
Expand Down
3 changes: 3 additions & 0 deletions config/dev.webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { resolve } = require('path');
const config = require('@redhat-cloud-services/frontend-components-config');
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

const { config: webpackConfig, plugins } = config({
rootFolder: resolve(__dirname, '../'),
Expand Down Expand Up @@ -33,6 +35,7 @@ plugins.push(
}
)
);
plugins.push(new BundleAnalyzerPlugin());

module.exports = {
...webpackConfig,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"stylelint": "14.8.2",
"stylelint-config-recommended-scss": "^6.0.0",
"stylelint-scss": "4.2.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "4.9.2"
},
"release": {
Expand Down
3 changes: 1 addition & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import PropTypes from 'prop-types';
import NotificationsPortal from '@redhat-cloud-services/frontend-components-notifications/NotificationPortal';
import { getRegistry } from '@redhat-cloud-services/frontend-components-utilities/Registry/Registry';
import { notificationsReducer } from '@redhat-cloud-services/frontend-components-notifications/redux';
import { Bullseye } from '@patternfly/react-core/dist/js/layouts/Bullseye/Bullseye';
import { Bullseye, Spinner } from '@patternfly/react-core';
import LockIcon from '@patternfly/react-icons/dist/js/icons/lock-icon';
import { Spinner } from '@patternfly/react-core/dist/js/components/Spinner';

import { Routes } from './Routes';
import ErrorBoundary from './Utilities/ErrorBoundary';
Expand Down
15 changes: 8 additions & 7 deletions src/Components/AffectedClustersTable/AffectedClustersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import PrimaryToolbar from '@redhat-cloud-services/frontend-components/PrimaryTo
import { EmptyTable } from '@redhat-cloud-services/frontend-components/EmptyTable';
import { TableToolbar } from '@redhat-cloud-services/frontend-components/TableToolbar';
import { DateFormat } from '@redhat-cloud-services/frontend-components/DateFormat';
import { Card, CardBody } from '@patternfly/react-core/dist/js/components/Card';
import {
Card,
CardBody,
Tooltip,
Bullseye,
Pagination,
} from '@patternfly/react-core';
import { PaginationVariant } from '@patternfly/react-core/dist/js/components/Pagination/Pagination';
import { Table } from '@patternfly/react-table/dist/js/components/Table/Table';
import { TableBody } from '@patternfly/react-table/dist/js/components/Table/Body';
import { TableHeader } from '@patternfly/react-table/dist/js/components/Table/Header';
import { Bullseye } from '@patternfly/react-core/dist/js/layouts/Bullseye';
import { Tooltip } from '@patternfly/react-core/dist/js/components/Tooltip';
import {
Pagination,
PaginationVariant,
} from '@patternfly/react-core/dist/js/components/Pagination/Pagination';

import {
ErrorState,
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Breadcrumbs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Link, useLocation } from 'react-router-dom';

import { Breadcrumb } from '@patternfly/react-core/dist/js/components/Breadcrumb/Breadcrumb';
import { BreadcrumbItem } from '@patternfly/react-core/dist/js/components/Breadcrumb/BreadcrumbItem';
import { Breadcrumb, BreadcrumbItem } from '@patternfly/react-core';

import messages from '../../Messages';

Expand Down
10 changes: 7 additions & 3 deletions src/Components/ClusterHeader/ClusterHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';

import { Grid, GridItem } from '@patternfly/react-core/dist/js/layouts/Grid';
import { Stack, StackItem } from '@patternfly/react-core/dist/js/layouts/Stack';
import { Title } from '@patternfly/react-core/dist/js/components/Title';
import {
Grid,
GridItem,
Stack,
StackItem,
Title,
} from '@patternfly/react-core';
import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core';
import Skeleton from '@redhat-cloud-services/frontend-components/Skeleton';
import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat/DateFormat';
Expand Down
7 changes: 2 additions & 5 deletions src/Components/ClusterRules/ClusterRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ import {
TableHeader,
TableVariant,
} from '@patternfly/react-table';
import { Card, CardBody } from '@patternfly/react-core/dist/js/components/Card';
import {
Tooltip,
TooltipPosition,
} from '@patternfly/react-core/dist/js/components/Tooltip';
import { Card, CardBody, Tooltip } from '@patternfly/react-core';
import { TooltipPosition } from '@patternfly/react-core/dist/js/components/Tooltip';
import InfoCircleIcon from '@patternfly/react-icons/dist/js/icons/info-circle-icon';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/js/icons/exclamation-circle-icon';
import { global_danger_color_100 as globalDangerColor100 } from '@patternfly/react-tokens/dist/js/global_danger_color_100';
Expand Down
13 changes: 7 additions & 6 deletions src/Components/ClustersListTable/ClustersListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
TableHeader,
TableVariant,
} from '@patternfly/react-table';
import { Card, CardBody } from '@patternfly/react-core/dist/js/components/Card';
import { Bullseye } from '@patternfly/react-core/dist/js/layouts/Bullseye';
import { Spinner } from '@patternfly/react-core/dist/js/components/Spinner';
import {
Card,
CardBody,
Bullseye,
Spinner,
Pagination,
PaginationVariant,
} from '@patternfly/react-core/dist/js/components/Pagination';
import { Tooltip } from '@patternfly/react-core';
Tooltip,
} from '@patternfly/react-core';
import { PaginationVariant } from '@patternfly/react-core/dist/js/components/Pagination/Pagination';
import PrimaryToolbar from '@redhat-cloud-services/frontend-components/PrimaryToolbar/PrimaryToolbar';
import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat';
import { conditionalFilterType } from '@redhat-cloud-services/frontend-components/ConditionalFilter/conditionalFilterConstants';
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Labels/CategoryLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import camelCase from 'lodash/camelCase';

import { Label } from '@patternfly/react-core/dist/js/components/Label/index';
import { LabelGroup } from '@patternfly/react-core/dist/js/components/LabelGroup/LabelGroup';
import { Label, LabelGroup } from '@patternfly/react-core';
import LockIcon from '@patternfly/react-icons/dist/esm/icons/lock-icon';
import PortIcon from '@patternfly/react-icons/dist/esm/icons/port-icon';
import AutomationIcon from '@patternfly/react-icons/dist/esm/icons/automation-icon';
Expand Down
8 changes: 2 additions & 6 deletions src/Components/Labels/RuleLabels.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
Tooltip,
TooltipPosition,
} from '@patternfly/react-core/dist/js/components/Tooltip/Tooltip';

import { Label } from '@patternfly/react-core/dist/js/components/Label/Label';
import { TooltipPosition } from '@patternfly/react-core/dist/js/components/Tooltip/Tooltip';
import { Tooltip, Label } from '@patternfly/react-core';
import PropTypes from 'prop-types';
import React from 'react';
import { useIntl } from 'react-intl';
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Loading/Loading.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Card } from '@patternfly/react-core/dist/js/components/Card/Card';
import { CardBody } from '@patternfly/react-core/dist/js/components/Card/CardBody';
import { Card, CardBody } from '@patternfly/react-core';
import { List } from 'react-content-loader';

const Loading = ({ id }) => (
Expand Down
4 changes: 1 addition & 3 deletions src/Components/MessageState/EmptyStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import * as React from 'react';
import { useIntl } from 'react-intl';
import { Link } from 'react-router-dom';

import { Stack, StackItem } from '@patternfly/react-core/dist/js/layouts/Stack';
import { Title } from '@patternfly/react-core/dist/js/components/Title';
import { Title, Button, Stack, StackItem } from '@patternfly/react-core';
import {
EmptyState,
EmptyStateBody,
EmptyStateIcon,
EmptyStateSecondaryActions,
} from '@patternfly/react-core/dist/js/components/EmptyState';
import { Button } from '@patternfly/react-core/dist/js/components/Button';
import ExclamationCircleIcon from '@patternfly/react-icons/dist/js/icons/exclamation-circle-icon';
import CheckCircleIcon from '@patternfly/react-icons/dist/js/icons/check-circle-icon';
import PlusCircleIcon from '@patternfly/react-icons/dist/js/icons/plus-circle-icon';
Expand Down
14 changes: 7 additions & 7 deletions src/Components/MessageState/MessageState.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
EmptyState,
EmptyStateVariant,
} from '@patternfly/react-core/dist/js/components/EmptyState/EmptyState';
import { EmptyStateVariant } from '@patternfly/react-core/dist/js/components/EmptyState/EmptyState';

import CubesIcon from '@patternfly/react-icons/dist/js/icons/cubes-icon';
import { EmptyStateBody } from '@patternfly/react-core/dist/js/components/EmptyState/EmptyStateBody';
import { EmptyStateIcon } from '@patternfly/react-core/dist/js/components/EmptyState/EmptyStateIcon';
import {
EmptyStateIcon,
EmptyStateBody,
EmptyState,
Title,
} from '@patternfly/react-core';
import PropTypes from 'prop-types';
import React from 'react';
import { Title } from '@patternfly/react-core/dist/js/components/Title/Title';

const MessageState = ({
className,
Expand Down
14 changes: 8 additions & 6 deletions src/Components/Modals/DisableRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';

import { Button } from '@patternfly/react-core/dist/js/components/Button/Button';
import { Checkbox } from '@patternfly/react-core/dist/js/components/Checkbox/Checkbox';
import { Form } from '@patternfly/react-core/dist/js/components/Form/Form';
import { FormGroup } from '@patternfly/react-core/dist/js/components/Form/FormGroup';
import { Modal } from '@patternfly/react-core/dist/js/components/Modal/Modal';
import { TextInput } from '@patternfly/react-core/dist/js/components/TextInput/TextInput';
import {
Button,
Checkbox,
Form,
FormGroup,
Modal,
TextInput,
} from '@patternfly/react-core';
import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/';

import messages from '../../Messages';
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Modals/ViewHostAcks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
TableHeader,
cellWidth,
} from '@patternfly/react-table';
import { Button } from '@patternfly/react-core/dist/js/components/Button/Button';
import { Button, Modal } from '@patternfly/react-core';
import { DateFormat } from '@redhat-cloud-services/frontend-components/DateFormat';
import { Modal } from '@patternfly/react-core/dist/js/components/Modal/Modal';
import OutlinedBellIcon from '@patternfly/react-icons/dist/js/icons/outlined-bell-icon';
import { addNotification as notification } from '@redhat-cloud-services/frontend-components-notifications/';

Expand Down
20 changes: 11 additions & 9 deletions src/Components/Recommendation/Recommendation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ import {
} from '@redhat-cloud-services/frontend-components/PageHeader';
import { Main } from '@redhat-cloud-services/frontend-components/Main';
import { DateFormat } from '@redhat-cloud-services/frontend-components/DateFormat';
import { Label } from '@patternfly/react-core/dist/js/components/Label/Label';
import { Title } from '@patternfly/react-core/dist/js/components/Title/Title';
import { LabelGroup } from '@patternfly/react-core/dist/js/components/LabelGroup';
import {
Label,
Title,
LabelGroup,
Button,
Dropdown,
DropdownItem,
DropdownToggle,
Flex,
FlexItem,
} from '@patternfly/react-core';
import BellSlashIcon from '@patternfly/react-icons/dist/js/icons/bell-slash-icon';
import CaretDownIcon from '@patternfly/react-icons/dist/js/icons/caret-down-icon';
import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/';
import { Button } from '@patternfly/react-core/dist/js/components/Button/Button';
import { Dropdown } from '@patternfly/react-core/dist/js/components/Dropdown/Dropdown';
import { DropdownItem } from '@patternfly/react-core/dist/js/components/Dropdown/DropdownItem';
import { DropdownToggle } from '@patternfly/react-core/dist/js/components/Dropdown/DropdownToggle';
import { Flex } from '@patternfly/react-core/dist/js/layouts/Flex/Flex';
import { FlexItem } from '@patternfly/react-core/dist/js/layouts/Flex/FlexItem';
import { ErrorState } from '@redhat-cloud-services/frontend-components/ErrorState';
import {
AdvisorProduct,
Expand Down
15 changes: 7 additions & 8 deletions src/Components/RecsListTable/RecsListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import {
TableHeader,
TableVariant,
} from '@patternfly/react-table';
import { Card, CardBody } from '@patternfly/react-core/dist/js/components/Card';
import {
Pagination,
PaginationVariant,
} from '@patternfly/react-core/dist/js/components/Pagination';
import { Stack } from '@patternfly/react-core/dist/js/layouts/Stack';
import isEqual from 'lodash/isEqual';
import {
Stack,
Card,
CardBody,
Tooltip,
TooltipPosition,
} from '@patternfly/react-core/dist/js/components/Tooltip';
} from '@patternfly/react-core';
import { TooltipPosition } from '@patternfly/react-core/dist/js/components/Tooltip';
import { PaginationVariant } from '@patternfly/react-core/dist/js/components/Pagination/Pagination';
import isEqual from 'lodash/isEqual';

import { DateFormat } from '@redhat-cloud-services/frontend-components/DateFormat';
import { InsightsLabel } from '@redhat-cloud-services/frontend-components/InsightsLabel';
Expand Down
10 changes: 6 additions & 4 deletions src/Routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Route, Switch, Redirect } from 'react-router-dom';
import React, { Suspense, lazy } from 'react';

import { Bullseye } from '@patternfly/react-core/dist/js/layouts/Bullseye';
import { Spinner } from '@patternfly/react-core/dist/js/components/Spinner';
import { EmptyState } from '@patternfly/react-core/dist/js/components/EmptyState';
import { EmptyStateBody } from '@patternfly/react-core/dist/js/components/EmptyState';
import {
Bullseye,
EmptyStateBody,
Spinner,
EmptyState,
} from '@patternfly/react-core';
import InvalidObject from '@redhat-cloud-services/frontend-components/InvalidObject/InvalidObject';

const Cluster = lazy(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { injectIntl } from 'react-intl';
import PropTypes from 'prop-types';

import { ErrorState } from '../Components/MessageState/EmptyStates';
import { Bullseye } from '@patternfly/react-core/dist/js/layouts/Bullseye/Bullseye';
import { Bullseye } from '@patternfly/react-core';

class ErrorBoundary extends React.Component {
constructor(props) {
Expand Down

0 comments on commit f04ac70

Please sign in to comment.