Skip to content

Commit

Permalink
Remove babel-plugin-add-module-exports (ant-design#8888)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck authored Jan 13, 2018
1 parent 3418cb8 commit 46b45ac
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
10 changes: 2 additions & 8 deletions components/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { PREFIX_CLS } from './Constants';
import Header from './Header';
import callMoment from '../_util/callMoment';

declare const require: Function;
import enUS from './locale/en_US';

export { HeaderProps } from './Header';

Expand Down Expand Up @@ -122,11 +121,6 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
);
}

getDefaultLocale() {
const locale = require('./locale/en_US');
return locale.default || locale;
}

setValue = (value: moment.Moment, way: 'select' | 'changePanel') => {
if (!('value' in this.props)) {
this.setState({ value });
Expand Down Expand Up @@ -215,7 +209,7 @@ export default class Calendar extends React.Component<CalendarProps, CalendarSta
return (
<LocaleReceiver
componentName="Calendar"
defaultLocale={this.getDefaultLocale}
defaultLocale={enUS}
>
{this.renderCalendar}
</LocaleReceiver>
Expand Down
4 changes: 3 additions & 1 deletion components/date-picker/__tests__/MonthPicker.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { MonthPicker } from '..';
import DatePicker from '..';
import focusTest from '../../../tests/shared/focusTest';

const { MonthPicker } = DatePicker;

describe('MonthPicker', () => {
focusTest(MonthPicker);
});
4 changes: 3 additions & 1 deletion components/date-picker/__tests__/RangePicker.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { mount, render } from 'enzyme';
import moment from 'moment';
import { RangePicker } from '../';
import DatePicker from '../';
import focusTest from '../../../tests/shared/focusTest';

const { RangePicker } = DatePicker;

describe('RangePicker', () => {
focusTest(RangePicker);

Expand Down
4 changes: 3 additions & 1 deletion components/date-picker/__tests__/WeekPicker.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { WeekPicker } from '..';
import DatePicker from '..';
import focusTest from '../../../tests/shared/focusTest';

const { WeekPicker } = DatePicker;

describe('WeekPicker', () => {
focusTest(WeekPicker);
});
4 changes: 3 additions & 1 deletion components/date-picker/__tests__/other.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { mount, render } from 'enzyme';
import moment from 'moment';
import { MonthPicker, WeekPicker } from '../';
import DatePicker from '../';

const { MonthPicker, WeekPicker } = DatePicker;

describe('MonthPicker and WeekPicker', () => {
it('render MonthPicker', () => {
Expand Down
4 changes: 3 additions & 1 deletion components/date-picker/__tests__/showTime.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { mount } from 'enzyme';
import DatePicker, { RangePicker } from '../';
import DatePicker from '../';

const { RangePicker } = DatePicker;

describe('DatePicker with showTime', () => {
it('should trigger onChange when select value', () => {
Expand Down
7 changes: 2 additions & 5 deletions components/date-picker/wrapPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import TimePickerPanel from 'rc-time-picker/lib/Panel';
import classNames from 'classnames';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { generateShowHourMinuteSecond } from '../time-picker';

declare const require: Function;
import enUS from './locale/en_US';

function getColumns({ showHour, showMinute, showSecond, use12Hours }: any) {
let column = 0;
Expand Down Expand Up @@ -81,10 +80,8 @@ export default function wrapPicker(Picker: React.ComponentClass<any>, defaultFor
}

getDefaultLocale = () => {
const locale = require('./locale/en_US');
const defaultlocale = (locale.default || locale);
const result = {
...defaultlocale,
...enUS,
...this.props.locale,
};
result.lang = {
Expand Down
2 changes: 1 addition & 1 deletion index-with-locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ antd.locales = {};

req.keys().forEach((mod) => {
const match = mod.match(/\/([^/]+).tsx$/);
antd.locales[match[1]] = req(mod);
antd.locales[match[1]] = req(mod).default;
});

module.exports = antd;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@types/react": "^16.0.0",
"@types/react-dom": "^16.0.0",
"ansi-styles": "^3.2.0",
"antd-tools": "^4.0.6",
"antd-tools": "^5.0.0",
"babel-cli": "^6.18.0",
"babel-eslint": "^8.1.1",
"babel-plugin-import": "^1.0.0",
Expand Down
7 changes: 6 additions & 1 deletion site/bisheng.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const usePreact = process.env.REACT_ENV === 'preact';
function alertBabelConfig(rules) {
rules.forEach((rule) => {
if (rule.loader && rule.loader === 'babel-loader') {
rule.options.plugins.push(replaceLib);
if (rule.options.plugins.indexOf(replaceLib) === -1) {
rule.options.plugins.push(replaceLib);
}
rule.options.plugins = rule.options.plugins.filter(plugin =>
!plugin.indexOf || plugin.indexOf('babel-plugin-add-module-exports') === -1
);
} else if (rule.use) {
alertBabelConfig(rule.use);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/shared/demoTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function demoTest(component, options = {}) {
}
testMethod(`renders ${file} correctly`, () => {
MockDate.set(new Date('2016-11-22').getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
const demo = require(`../.${file}`); // eslint-disable-line global-require, import/no-dynamic-require
const demo = require(`../.${file}`).default; // eslint-disable-line global-require, import/no-dynamic-require
const wrapper = render(demo);
expect(wrapper).toMatchSnapshot();
MockDate.reset();
Expand Down

0 comments on commit 46b45ac

Please sign in to comment.