Skip to content

Commit 0b9ca37

Browse files
committed
Add native ESM support
1 parent f9446e1 commit 0b9ca37

27 files changed

+91
-62
lines changed

package.json

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,39 @@
22
"name": "react-time-picker",
33
"version": "6.3.0",
44
"description": "A time 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/cjs/TimeInput.js": "./dist/cjs/TimeInput.js",
19+
"./dist/cjs/TimeInput/Hour12Input.js": "./dist/cjs/TimeInput/Hour12Input.js",
20+
"./dist/cjs/TimeInput/Hour24Input.js": "./dist/cjs/TimeInput/Hour24Input.js",
21+
"./dist/cjs/TimeInput/MinuteInput.js": "./dist/cjs/TimeInput/MinuteInput.js",
22+
"./dist/cjs/TimeInput/SecondInput.js": "./dist/cjs/TimeInput/SecondInput.js",
23+
"./dist/cjs/TimeInput/AmPm.js": "./dist/cjs/TimeInput/AmPm.js",
24+
"./dist/esm/TimeInput.js": "./dist/esm/TimeInput.js",
25+
"./dist/esm/TimeInput/Hour12Input.js": "./dist/esm/TimeInput/Hour12Input.js",
26+
"./dist/esm/TimeInput/Hour24Input.js": "./dist/esm/TimeInput/Hour24Input.js",
27+
"./dist/esm/TimeInput/MinuteInput.js": "./dist/esm/TimeInput/MinuteInput.js",
28+
"./dist/esm/TimeInput/SecondInput.js": "./dist/esm/TimeInput/SecondInput.js",
29+
"./dist/esm/TimeInput/AmPm.js": "./dist/esm/TimeInput/AmPm.js",
30+
"./dist/TimePicker.css": "./dist/TimePicker.css"
31+
},
1232
"scripts": {
1333
"build": "yarn build-js && yarn copy-styles",
14-
"build-js": "yarn build-js-esm && yarn build-js-cjs",
34+
"build-js": "yarn build-js-esm && yarn build-js-cjs && yarn build-js-cjs-package",
1535
"build-js-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
1636
"build-js-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
37+
"build-js-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
1738
"clean": "rimraf dist",
1839
"copy-styles": "cpy 'src/**/*.css' dist",
1940
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
@@ -23,7 +44,7 @@
2344
"test": "yarn lint && yarn tsc && yarn prettier && yarn unit",
2445
"tsc": "tsc --noEmit",
2546
"unit": "vitest",
26-
"watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & nodemon --watch src --ext css --exec \"yarn copy-styles\""
47+
"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\""
2748
},
2849
"keywords": [
2950
"react",

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/TimeInput.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import React from 'react';
33
import { fireEvent, render } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
55

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

8-
import { muteConsole, restoreConsole } from '../test-utils';
8+
import { muteConsole, restoreConsole } from '../test-utils.js';
99

1010
vi.useFakeTimers();
1111

src/TimeInput.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import {
99
getHoursMinutesSeconds,
1010
} from '@wojtekmaj/date-utils';
1111

12-
import Divider from './Divider';
13-
import Hour12Input from './TimeInput/Hour12Input';
14-
import Hour24Input from './TimeInput/Hour24Input';
15-
import MinuteInput from './TimeInput/MinuteInput';
16-
import SecondInput from './TimeInput/SecondInput';
17-
import NativeInput from './TimeInput/NativeInput';
18-
import AmPm from './TimeInput/AmPm';
19-
20-
import { getFormatter, getNumberFormatter } from './shared/dateFormatter';
21-
import { convert12to24, convert24to12 } from './shared/dates';
22-
import { getAmPmLabels } from './shared/utils';
23-
24-
import type { AmPmType, Detail, LooseValuePiece, Value } from './shared/types';
12+
import Divider from './Divider.js';
13+
import Hour12Input from './TimeInput/Hour12Input.js';
14+
import Hour24Input from './TimeInput/Hour24Input.js';
15+
import MinuteInput from './TimeInput/MinuteInput.js';
16+
import SecondInput from './TimeInput/SecondInput.js';
17+
import NativeInput from './TimeInput/NativeInput.js';
18+
import AmPm from './TimeInput/AmPm.js';
19+
20+
import { getFormatter, getNumberFormatter } from './shared/dateFormatter.js';
21+
import { convert12to24, convert24to12 } from './shared/dates.js';
22+
import { getAmPmLabels } from './shared/utils.js';
23+
24+
import type { AmPmType, Detail, LooseValuePiece, Value } from './shared/types.js';
2525

2626
const getFormatterOptionsCache: Record<string, Intl.DateTimeFormatOptions> = {};
2727

src/TimeInput/AmPm.spec.tsx

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

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

77
describe('AmPm', () => {
88
const defaultProps = {

src/TimeInput/AmPm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React from 'react';
22
import clsx from 'clsx';
33
import { getHours } from '@wojtekmaj/date-utils';
44

5-
import { convert24to12 } from '../shared/dates';
6-
import { getAmPmLabels } from '../shared/utils';
5+
import { convert24to12 } from '../shared/dates.js';
6+
import { getAmPmLabels } from '../shared/utils.js';
77

88
/* eslint-disable jsx-a11y/no-autofocus */
99

src/TimeInput/Hour12Input.spec.tsx

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

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

77
describe('Hour12Input', () => {
88
const defaultProps = {

src/TimeInput/Hour12Input.tsx

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

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

6-
import { convert24to12 } from '../shared/dates';
7-
import { safeMin, safeMax } from '../shared/utils';
6+
import { convert24to12 } from '../shared/dates.js';
7+
import { safeMin, safeMax } from '../shared/utils.js';
88

9-
import type { AmPmType } from '../shared/types';
9+
import type { AmPmType } from '../shared/types.js';
1010

1111
type Hour12InputProps = {
1212
amPm: AmPmType | null;

src/TimeInput/Hour24Input.spec.tsx

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

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

77
describe('Hour24Input', () => {
88
const defaultProps = {

src/TimeInput/Hour24Input.tsx

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

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

6-
import { safeMin, safeMax } from '../shared/utils';
6+
import { safeMin, safeMax } from '../shared/utils.js';
77

88
type Hour24InputProps = {
99
maxTime?: string;

0 commit comments

Comments
 (0)