Skip to content

Commit 25112a6

Browse files
committed
Add native ESM support (#310)
1 parent 5d809aa commit 25112a6

File tree

11 files changed

+43
-26
lines changed

11 files changed

+43
-26
lines changed

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22
"name": "@wojtekmaj/react-daterange-picker",
33
"version": "5.3.0",
44
"description": "A date range picker 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/DateRangePicker.css": "./dist/DateRangePicker.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",

sample/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import Sample from './Sample';
3+
4+
import Sample from './Sample.js';
45

56
createRoot(document.getElementById('react-root') as HTMLDivElement).render(<Sample />);

src/DateRangePicker.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 { act, fireEvent, render, waitFor, waitForElementToBeRemoved } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55

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

88
async function waitForElementToBeRemovedOrHidden(callback: () => HTMLElement | null) {
99
const element = callback();

src/DateRangePicker.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@ import Fit from 'react-fit';
1010

1111
import DateInput from 'react-date-picker/dist/cjs/DateInput';
1212

13-
import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes';
13+
import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes.js';
1414

1515
import type { ReactNodeArray } from 'prop-types';
16-
import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types';
16+
import type {
17+
ClassName,
18+
CloseReason,
19+
Detail,
20+
LooseValue,
21+
OpenReason,
22+
Value,
23+
} from './shared/types.js';
1724

1825
const baseClassName = 'react-daterange-picker';
1926
const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'] as const;

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import DateRangePicker from './DateRangePicker';
1+
import DateRangePicker from './DateRangePicker.js';
22

3-
export type { DateRangePickerProps } from './DateRangePicker';
3+
export type { DateRangePickerProps } from './DateRangePicker.js';
44

55
export { DateRangePicker };
66

src/shared/propTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types';
22

33
import type { Requireable, Validator } from 'prop-types';
4-
import type { Range } from './types';
4+
import type { Range } from './types.js';
55

66
export const isMinDate: Validator<Date | null | undefined> = function isMinDate(
77
props,

test/MaxDetailOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import type { Detail } from './shared/types';
3+
import type { Detail } from './shared/types.js';
44

55
const allViews = ['century', 'decade', 'year', 'month'] as const;
66

test/MinDetailOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import type { Detail } from './shared/types';
3+
import type { Detail } from './shared/types.js';
44

55
const allViews = ['century', 'decade', 'year', 'month'] as const;
66

test/Test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React, { useRef, useState } from 'react';
2-
import DateRangePicker from '@wojtekmaj/react-daterange-picker/src';
3-
import '@wojtekmaj/react-daterange-picker/src/DateRangePicker.css';
2+
import DateRangePicker from '@wojtekmaj/react-daterange-picker';
3+
import '@wojtekmaj/react-daterange-picker/dist/DateRangePicker.css';
44
import 'react-calendar/dist/Calendar.css';
55

6-
import ValidityOptions from './ValidityOptions';
7-
import MaxDetailOptions from './MaxDetailOptions';
8-
import MinDetailOptions from './MinDetailOptions';
9-
import LocaleOptions from './LocaleOptions';
10-
import ValueOptions from './ValueOptions';
11-
import ViewOptions from './ViewOptions';
6+
import ValidityOptions from './ValidityOptions.js';
7+
import MaxDetailOptions from './MaxDetailOptions.js';
8+
import MinDetailOptions from './MinDetailOptions.js';
9+
import LocaleOptions from './LocaleOptions.js';
10+
import ValueOptions from './ValueOptions.js';
11+
import ViewOptions from './ViewOptions.js';
1212

1313
import './Test.css';
1414

15-
import type { Detail, LooseValue } from './shared/types';
15+
import type { Detail, LooseValue } from './shared/types.js';
1616

1717
const now = new Date();
1818

test/ValueOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { getDayStart, getDayEnd, getISOLocalDate } from '@wojtekmaj/date-utils';
33

4-
import type { LooseValue } from './shared/types';
4+
import type { LooseValue } from './shared/types.js';
55

66
type ValueOptionsProps = {
77
setValue: (value: LooseValue) => void;

0 commit comments

Comments
 (0)