Skip to content

Commit 410c60e

Browse files
authored
Add native ESM support (#886)
1 parent 598c568 commit 410c60e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+136
-123
lines changed

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
"name": "react-calendar",
33
"version": "4.5.0",
44
"description": "Ultimate calendar for your React app.",
5-
"main": "dist/cjs/index.js",
6-
"module": "dist/esm/index.js",
7-
"source": "src/index.ts",
8-
"types": "dist/cjs/index.d.ts",
5+
"type": "module",
96
"sideEffects": [
107
"*.css"
118
],
9+
"main": "./dist/cjs/index.js",
10+
"module": "./dist/esm/index.js",
11+
"source": "./src/index.ts",
12+
"types": "./dist/cjs/index.d.ts",
13+
"exports": {
14+
".": {
15+
"import": "./dist/esm/index.js",
16+
"require": "./dist/cjs/index.js"
17+
},
18+
"./dist/Calendar.css": "./dist/Calendar.css"
19+
},
1220
"scripts": {
1321
"build": "yarn build-js && yarn copy-styles",
14-
"build-js": "yarn build-js-esm && yarn build-js-cjs",
22+
"build-js": "yarn build-js-esm && yarn build-js-cjs && yarn build-js-cjs-package",
1523
"build-js-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
1624
"build-js-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
25+
"build-js-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
1726
"clean": "rimraf dist",
1827
"copy-styles": "cpy 'src/**/*.css' dist",
1928
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
@@ -23,7 +32,7 @@
2332
"test": "yarn lint && yarn tsc && yarn prettier && yarn unit",
2433
"tsc": "tsc --noEmit",
2534
"unit": "vitest",
26-
"watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & nodemon --watch src --ext css --exec \"yarn copy-styles\""
35+
"watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & yarn build-js-cjs-package & nodemon --watch src --ext css --exec \"yarn copy-styles\""
2736
},
2837
"keywords": [
2938
"calendar",

src/Calendar.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import React, { createRef } from 'react';
33
import { act, render } from '@testing-library/react';
44
import { getMonthStart } from '@wojtekmaj/date-utils';
55

6-
import Calendar from './Calendar';
6+
import Calendar from './Calendar.js';
77

8-
import type { Action, Value, View } from './shared/types';
8+
import type { Action, Value, View } from './shared/types.js';
99

1010
type CalendarImperativeHandle = {
1111
activeStartDate: Date;

src/Calendar.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import React, { forwardRef, useCallback, useImperativeHandle, useState } from 'r
44
import PropTypes from 'prop-types';
55
import clsx from 'clsx';
66

7-
import Navigation from './Calendar/Navigation';
8-
import CenturyView from './CenturyView';
9-
import DecadeView from './DecadeView';
10-
import YearView from './YearView';
11-
import MonthView from './MonthView';
7+
import Navigation from './Calendar/Navigation.js';
8+
import CenturyView from './CenturyView.js';
9+
import DecadeView from './DecadeView.js';
10+
import YearView from './YearView.js';
11+
import MonthView from './MonthView.js';
1212

13-
import { getBegin, getBeginNext, getEnd, getValueRange } from './shared/dates';
13+
import { getBegin, getBeginNext, getEnd, getValueRange } from './shared/dates.js';
1414
import {
1515
isCalendarType,
1616
isClassName,
@@ -19,8 +19,8 @@ import {
1919
isRef,
2020
isView,
2121
rangeOf,
22-
} from './shared/propTypes';
23-
import { between } from './shared/utils';
22+
} from './shared/propTypes.js';
23+
import { between } from './shared/utils.js';
2424

2525
import type {
2626
Action,
@@ -39,7 +39,7 @@ import type {
3939
TileDisabledFunc,
4040
Value,
4141
View,
42-
} from './shared/types';
42+
} from './shared/types.js';
4343

4444
import type {
4545
formatDay as defaultFormatDay,
@@ -49,7 +49,7 @@ import type {
4949
formatShortWeekday as defaultFormatShortWeekday,
5050
formatWeekday as defaultFormatWeekday,
5151
formatYear as defaultFormatYear,
52-
} from './shared/dateFormatter';
52+
} from './shared/dateFormatter.js';
5353

5454
const baseClassName = 'react-calendar';
5555
const allViews = ['century', 'decade', 'year', 'month'] as const;

src/Calendar/Navigation.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
22
import React from 'react';
33
import { fireEvent, render } from '@testing-library/react';
44

5-
import Navigation from './Navigation';
5+
import Navigation from './Navigation.js';
66

77
const allViews = ['century', 'decade', 'year', 'month'];
88

src/Calendar/Navigation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
getBeginPrevious2,
1313
getEndPrevious,
1414
getEndPrevious2,
15-
} from '../shared/dates';
15+
} from '../shared/dates.js';
1616
import {
1717
formatMonthYear as defaultFormatMonthYear,
1818
formatYear as defaultFormatYear,
19-
} from '../shared/dateFormatter';
19+
} from '../shared/dateFormatter.js';
2020

21-
import type { Action, NavigationLabelFunc, RangeType } from '../shared/types';
21+
import type { Action, NavigationLabelFunc, RangeType } from '../shared/types.js';
2222

2323
const className = 'react-calendar__navigation';
2424

src/CenturyView.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { render } from '@testing-library/react';
44
import { getDecadeStart, getDecadeEnd } from '@wojtekmaj/date-utils';
55

6-
import CenturyView from './CenturyView';
6+
import CenturyView from './CenturyView.js';
77

88
describe('CenturyView', () => {
99
const defaultProps = {

src/CenturyView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22

3-
import Decades from './CenturyView/Decades';
3+
import Decades from './CenturyView/Decades.js';
44

5-
import { tileGroupProps } from './shared/propTypes';
5+
import { tileGroupProps } from './shared/propTypes.js';
66

77
type CenturyViewProps = React.ComponentProps<typeof Decades>;
88

src/CenturyView/Decade.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
22
import React from 'react';
33
import { fireEvent, render } from '@testing-library/react';
44

5-
import Decade from './Decade';
5+
import Decade from './Decade.js';
66

77
const tileProps = {
88
activeStartDate: new Date(2018, 0, 1),

src/CenturyView/Decade.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import { getDecadeStart, getDecadeEnd } from '@wojtekmaj/date-utils';
33

4-
import Tile from '../Tile';
4+
import Tile from '../Tile.js';
55

6-
import { getDecadeLabel } from '../shared/dates';
7-
import { formatYear as defaultFormatYear } from '../shared/dateFormatter';
6+
import { getDecadeLabel } from '../shared/dates.js';
7+
import { formatYear as defaultFormatYear } from '../shared/dateFormatter.js';
88

99
const className = 'react-calendar__century-view__decades__decade';
1010

src/CenturyView/Decades.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import { getDecadeStart } from '@wojtekmaj/date-utils';
33

4-
import TileGroup from '../TileGroup';
5-
import Decade from './Decade';
4+
import TileGroup from '../TileGroup.js';
5+
import Decade from './Decade.js';
66

7-
import { getBeginOfCenturyYear } from '../shared/dates';
7+
import { getBeginOfCenturyYear } from '../shared/dates.js';
88

99
type DecadesProps = {
1010
activeStartDate: Date;

0 commit comments

Comments
 (0)