diff --git a/package.json b/package.json index 80698069..aac403f2 100644 --- a/package.json +++ b/package.json @@ -2,18 +2,27 @@ "name": "@wojtekmaj/react-daterange-picker", "version": "5.3.0", "description": "A date range picker for your React app.", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "source": "src/index.ts", - "types": "dist/cjs/index.d.ts", + "type": "module", "sideEffects": [ "*.css" ], + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "source": "./src/index.ts", + "types": "./dist/cjs/index.d.ts", + "exports": { + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./dist/DateRangePicker.css": "./dist/DateRangePicker.css" + }, "scripts": { "build": "yarn build-js && yarn copy-styles", - "build-js": "yarn build-js-esm && yarn build-js-cjs", + "build-js": "yarn build-js-esm && yarn build-js-cjs && yarn build-js-cjs-package", "build-js-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext", "build-js-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs", + "build-js-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json", "clean": "rimraf dist", "copy-styles": "cpy 'src/**/*.css' dist", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", @@ -23,7 +32,7 @@ "test": "yarn lint && yarn tsc && yarn prettier && yarn unit", "tsc": "tsc --noEmit", "unit": "vitest", - "watch": "yarn build-js-esm --watch & yarn build-js-cjs --watch & nodemon --watch src --ext css --exec \"yarn copy-styles\"" + "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\"" }, "keywords": [ "calendar", diff --git a/sample/index.tsx b/sample/index.tsx index 79a5a7ce..5a6a8183 100644 --- a/sample/index.tsx +++ b/sample/index.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; -import Sample from './Sample'; + +import Sample from './Sample.js'; createRoot(document.getElementById('react-root') as HTMLDivElement).render(); diff --git a/src/DateRangePicker.spec.tsx b/src/DateRangePicker.spec.tsx index a631c7b2..2e6c072f 100644 --- a/src/DateRangePicker.spec.tsx +++ b/src/DateRangePicker.spec.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { act, fireEvent, render, waitFor, waitForElementToBeRemoved } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import DateRangePicker from './DateRangePicker'; +import DateRangePicker from './DateRangePicker.js'; async function waitForElementToBeRemovedOrHidden(callback: () => HTMLElement | null) { const element = callback(); diff --git a/src/DateRangePicker.tsx b/src/DateRangePicker.tsx index 523edabb..ad560514 100644 --- a/src/DateRangePicker.tsx +++ b/src/DateRangePicker.tsx @@ -10,10 +10,17 @@ import Fit from 'react-fit'; import DateInput from 'react-date-picker/dist/cjs/DateInput'; -import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes'; +import { isMaxDate, isMinDate, rangeOf } from './shared/propTypes.js'; import type { ReactNodeArray } from 'prop-types'; -import type { ClassName, CloseReason, Detail, LooseValue, OpenReason, Value } from './shared/types'; +import type { + ClassName, + CloseReason, + Detail, + LooseValue, + OpenReason, + Value, +} from './shared/types.js'; const baseClassName = 'react-daterange-picker'; const outsideActionEvents = ['mousedown', 'focusin', 'touchstart'] as const; diff --git a/src/index.ts b/src/index.ts index 4a89c5c0..783c3427 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import DateRangePicker from './DateRangePicker'; +import DateRangePicker from './DateRangePicker.js'; -export type { DateRangePickerProps } from './DateRangePicker'; +export type { DateRangePickerProps } from './DateRangePicker.js'; export { DateRangePicker }; diff --git a/src/shared/propTypes.ts b/src/shared/propTypes.ts index c03d81ce..68037b1d 100644 --- a/src/shared/propTypes.ts +++ b/src/shared/propTypes.ts @@ -1,7 +1,7 @@ import PropTypes from 'prop-types'; import type { Requireable, Validator } from 'prop-types'; -import type { Range } from './types'; +import type { Range } from './types.js'; export const isMinDate: Validator = function isMinDate( props, diff --git a/test/MaxDetailOptions.tsx b/test/MaxDetailOptions.tsx index 3bd21d56..f28e9729 100644 --- a/test/MaxDetailOptions.tsx +++ b/test/MaxDetailOptions.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import type { Detail } from './shared/types'; +import type { Detail } from './shared/types.js'; const allViews = ['century', 'decade', 'year', 'month'] as const; diff --git a/test/MinDetailOptions.tsx b/test/MinDetailOptions.tsx index 007a640a..9a528f6f 100644 --- a/test/MinDetailOptions.tsx +++ b/test/MinDetailOptions.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import type { Detail } from './shared/types'; +import type { Detail } from './shared/types.js'; const allViews = ['century', 'decade', 'year', 'month'] as const; diff --git a/test/Test.tsx b/test/Test.tsx index bae51aa9..b8ddb5e2 100644 --- a/test/Test.tsx +++ b/test/Test.tsx @@ -1,18 +1,18 @@ import React, { useRef, useState } from 'react'; -import DateRangePicker from '@wojtekmaj/react-daterange-picker/src'; -import '@wojtekmaj/react-daterange-picker/src/DateRangePicker.css'; +import DateRangePicker from '@wojtekmaj/react-daterange-picker'; +import '@wojtekmaj/react-daterange-picker/dist/DateRangePicker.css'; import 'react-calendar/dist/Calendar.css'; -import ValidityOptions from './ValidityOptions'; -import MaxDetailOptions from './MaxDetailOptions'; -import MinDetailOptions from './MinDetailOptions'; -import LocaleOptions from './LocaleOptions'; -import ValueOptions from './ValueOptions'; -import ViewOptions from './ViewOptions'; +import ValidityOptions from './ValidityOptions.js'; +import MaxDetailOptions from './MaxDetailOptions.js'; +import MinDetailOptions from './MinDetailOptions.js'; +import LocaleOptions from './LocaleOptions.js'; +import ValueOptions from './ValueOptions.js'; +import ViewOptions from './ViewOptions.js'; import './Test.css'; -import type { Detail, LooseValue } from './shared/types'; +import type { Detail, LooseValue } from './shared/types.js'; const now = new Date(); diff --git a/test/ValueOptions.tsx b/test/ValueOptions.tsx index 9b9c2abd..8bb837d2 100644 --- a/test/ValueOptions.tsx +++ b/test/ValueOptions.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { getDayStart, getDayEnd, getISOLocalDate } from '@wojtekmaj/date-utils'; -import type { LooseValue } from './shared/types'; +import type { LooseValue } from './shared/types.js'; type ValueOptionsProps = { setValue: (value: LooseValue) => void; diff --git a/test/index.tsx b/test/index.tsx index 4a67864f..c355c527 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -1,7 +1,7 @@ import React, { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; -import Test from './Test'; +import Test from './Test.js'; createRoot(document.getElementById('react-root') as HTMLDivElement).render(