Skip to content

Commit 08a60a2

Browse files
committed
Add native ESM support (#210)
1 parent 6d9c15e commit 08a60a2

16 files changed

+43
-33
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-clock",
33
"version": "4.4.0",
44
"description": "An analog clock 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/Clock.css": "./dist/Clock.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
"clock",

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/Clock.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 Clock from './Clock';
5+
import Clock from './Clock.js';
66

77
describe('Clock', () => {
88
describe('<time> element', () => {

src/Clock.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import PropTypes from 'prop-types';
33
import clsx from 'clsx';
44
import { getHours, getMilliseconds, getMinutes, getSeconds } from '@wojtekmaj/date-utils';
55

6-
import Hand from './Hand';
7-
import MinuteMark from './MinuteMark';
8-
import HourMark from './HourMark';
6+
import Hand from './Hand.js';
7+
import MinuteMark from './MinuteMark.js';
8+
import HourMark from './HourMark.js';
99

10-
import type { formatHour as defaultFormatHour } from './shared/hourFormatter';
10+
import type { formatHour as defaultFormatHour } from './shared/hourFormatter.js';
1111

1212
import {
1313
isHandLength,
1414
isOppositeHandLength,
1515
isHandWidth,
1616
isMarkLength,
1717
isMarkWidth,
18-
} from './shared/propTypes';
18+
} from './shared/propTypes.js';
1919

2020
import type {
2121
ClassName,
@@ -24,7 +24,7 @@ import type {
2424
MarkLength,
2525
MarkWidth,
2626
OppositeHandLength,
27-
} from './shared/types';
27+
} from './shared/types.js';
2828

2929
export type ClockProps = {
3030
className?: ClassName;

src/Hand.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 Hand from './Hand';
5+
import Hand from './Hand.js';
66

77
describe('Hand', () => {
88
it('renders a hand with given name', () => {

src/Hand.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 { HandLength, HandWidth, OppositeHandLength } from './shared/types';
3+
import type { HandLength, HandWidth, OppositeHandLength } from './shared/types.js';
44

55
type HandProps = {
66
angle?: number;

src/HourMark.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 { render } from '@testing-library/react';
44

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

77
describe('HourMark', () => {
88
it('renders Mark', () => {

src/HourMark.tsx

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

3-
import Mark from './Mark';
3+
import Mark from './Mark.js';
44

5-
import { formatHour as defaultFormatHour } from './shared/hourFormatter';
5+
import { formatHour as defaultFormatHour } from './shared/hourFormatter.js';
66

77
type HourMarkProps = React.ComponentProps<typeof Mark> & {
88
formatHour?: typeof defaultFormatHour;

src/Mark.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 Mark from './Mark';
5+
import Mark from './Mark.js';
66

77
describe('Mark', () => {
88
it('renders a hand with given name', () => {

src/Mark.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 { MarkLength, MarkWidth } from './shared/types';
3+
import type { MarkLength, MarkWidth } from './shared/types.js';
44

55
type MarkProps = {
66
angle?: number;

0 commit comments

Comments
 (0)