Skip to content

Commit 66a41bb

Browse files
authored
build: use package exports for esm/cjs files (#114)
* lint updates * build and bump
1 parent b1894d0 commit 66a41bb

37 files changed

+2066
-627
lines changed

.babelrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = (api) => ({
22
presets: [
3-
['env-modules', { modules: api.env() === 'esm' ? false : 'commonjs' }],
3+
['env-modules', { modules: api.env() === 'cjs' ? 'commonjs' : false }],
44
['@babel/react', { runtime: 'automatic' }],
55
'@babel/preset-typescript',
66
],

.eslintrc

-18
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lib/
2+
cjs/
23
.cache/
34
www/public
45

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

eslint.config.mjs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import eslint from '@eslint/js';
2+
import globals from 'globals';
3+
import prettierPlugin from 'eslint-plugin-prettier/recommended';
4+
import tseslint from 'typescript-eslint';
5+
import react from 'eslint-plugin-react';
6+
import reactHooks from 'eslint-plugin-react-hooks';
7+
8+
export default tseslint.config(
9+
eslint.configs.recommended,
10+
tseslint.configs.recommended,
11+
12+
prettierPlugin,
13+
react.configs.flat.recommended,
14+
react.configs.flat['jsx-runtime'],
15+
16+
{
17+
plugins: {
18+
'react-hooks': reactHooks,
19+
},
20+
settings: {
21+
react: {
22+
version: 'detect',
23+
},
24+
},
25+
rules: {
26+
'react-hooks/rules-of-hooks': 'error',
27+
},
28+
},
29+
{
30+
files: ['**/*.ts', '**/*.tsx', '**/*.mts'],
31+
plugins: {
32+
'@typescript-eslint': tseslint.plugin,
33+
},
34+
languageOptions: {
35+
parser: tseslint.parser,
36+
parserOptions: {
37+
ecmaVersion: 'latest',
38+
ecmaFeatures: {
39+
jsx: true,
40+
},
41+
warnOnUnsupportedTypeScriptVersion: false,
42+
},
43+
},
44+
rules: {
45+
'@typescript-eslint/no-explicit-any': 'off',
46+
'@typescript-eslint/no-unused-vars': [
47+
'error',
48+
{
49+
args: 'after-used',
50+
argsIgnorePattern: '^_',
51+
vars: 'all',
52+
varsIgnorePattern: '^_',
53+
caughtErrors: 'none',
54+
caughtErrorsIgnorePattern: '^_',
55+
ignoreRestSiblings: false,
56+
},
57+
],
58+
},
59+
},
60+
{
61+
ignores: ['**/node_modules/**', '**/lib/**', '**/www/**'],
62+
},
63+
{
64+
languageOptions: {
65+
ecmaVersion: 2022,
66+
sourceType: 'module',
67+
globals: {
68+
...globals.browser,
69+
...globals.commonjs,
70+
...globals.node,
71+
},
72+
},
73+
linterOptions: {
74+
reportUnusedDisableDirectives: true,
75+
},
76+
},
77+
{
78+
files: ['**/test/**/*'],
79+
rules: {
80+
'no-script-url': 'off',
81+
'no-unused-expressions': 'off',
82+
'@typescript-eslint/no-unused-expressions': 'off',
83+
'padded-blocks': 'off',
84+
'react/no-multi-comp': 'off',
85+
'react/prop-types': 'off',
86+
},
87+
},
88+
);

package.json

+60-34
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,44 @@
1111
"url": "git+https://github.com/react-restart/ui.git"
1212
},
1313
"license": "MIT",
14-
"main": "lib/cjs/index.js",
15-
"module": "lib/esm/index.js",
16-
"types": "lib/esm/index.d.ts",
14+
"main": "cjs/index.js",
15+
"module": "lib/index.js",
16+
"types": "lib/index.d.ts",
1717
"exports": {
18+
"./package.json": "./package.json",
1819
".": {
19-
"types": "./esm/index.d.ts",
20-
"node": "./cjs/index.js",
21-
"import": "./esm/index.js",
22-
"require": "./cjs/index.js"
20+
"node": {
21+
"types": "./cjs/index.d.ts",
22+
"default": "./cjs/index.js"
23+
},
24+
"require": {
25+
"types": "./cjs/index.d.ts",
26+
"default": "./cjs/index.js"
27+
},
28+
"import": {
29+
"types": "./lib/index.d.ts",
30+
"default": "./lib/index.js"
31+
}
2332
},
2433
"./*": {
25-
"types": "./esm/*.d.ts",
26-
"node": "./cjs/*.js",
27-
"import": "./esm/*.js",
28-
"require": "./cjs/*.js"
34+
"node": {
35+
"types": "./cjs/*.d.ts",
36+
"default": "./cjs/*.js"
37+
},
38+
"require": {
39+
"types": "./cjs/*.d.ts",
40+
"default": "./cjs/*.js"
41+
},
42+
"import": {
43+
"types": "./lib/*.d.ts",
44+
"default": "./lib/*.js"
45+
}
2946
}
3047
},
3148
"sideEffects": false,
3249
"files": [
33-
"lib"
50+
"lib",
51+
"cjs"
3452
],
3553
"gitHooks": {
3654
"pre-commit": "lint-staged"
@@ -48,11 +66,15 @@
4866
],
4967
"scripts": {
5068
"bootstrap": "yarn --network-timeout 100000 && yarn --cwd www --network-timeout 100000",
51-
"build": "rimraf lib && 4c build src && yarn build:popper && yarn build:pick",
69+
"build": "rimraf lib && yarn build:esm && yarn build:cjs && yarn build:popper",
70+
"build:esm": "babel src --out-dir lib --delete-dir-on-start --extensions '.ts,.tsx' --ignore='**/*.d.ts' && yarn build:esm:types",
71+
"build:cjs": "babel src --out-dir cjs --env-name cjs --delete-dir-on-start --extensions '.ts,.tsx' --ignore='**/*.d.ts' && yarn build:cjs:types && echo '{\"type\": \"commonjs\"}' > cjs/package.json",
72+
"build:esm:types": "tsc -p . --emitDeclarationOnly --declaration --outDir lib",
73+
"build:cjs:types": "tsc -p . --emitDeclarationOnly --declaration --outDir cjs",
5274
"build:pick": "cherry-pick --cwd=lib --input-dir=../src --cjs-dir=cjs --esm-dir=esm",
53-
"build:popper": "rollup src/popper.ts --file lib/cjs/popper.js --format cjs --name popper --plugin @rollup/plugin-node-resolve",
75+
"build:popper": "rollup src/popper.ts --file cjs/popper.js --format cjs --name popper --plugin @rollup/plugin-node-resolve && rollup src/popper.ts --file lib/popper.js --format esm --name popper --plugin @rollup/plugin-node-resolve",
5476
"deploy-docs": "yarn --cwd www deploy",
55-
"lint": "eslint www/*.js www/src src test *.ts --ext .js,.ts,.tsx",
77+
"lint": "eslint src test",
5678
"prepublishOnly": "yarn build",
5779
"release": "rollout",
5880
"start": "yarn --cwd www start",
@@ -61,7 +83,7 @@
6183
"testonly": "vitest --run"
6284
},
6385
"lint-staged": {
64-
"*.js,*.tsx": "eslint --fix --ext .js,.ts,.tsx"
86+
"*.js,*.tsx": "eslint --fix"
6587
},
6688
"prettier": {
6789
"singleQuote": true,
@@ -75,14 +97,15 @@
7597
"conventionalCommits": true
7698
},
7799
"dependencies": {
100+
"@babel/eslint-parser": "^7.25.9",
78101
"@babel/runtime": "^7.26.0",
79102
"@popperjs/core": "^2.11.8",
80103
"@react-aria/ssr": "^3.5.0",
81-
"@restart/hooks": "^0.5.0",
104+
"@restart/hooks": "^0.6.2",
82105
"@types/warning": "^3.0.3",
83106
"dequal": "^2.0.3",
84107
"dom-helpers": "^5.2.0",
85-
"uncontrollable": "^8.0.4",
108+
"uncontrollable": "^9.0.0",
86109
"warning": "^4.0.3"
87110
},
88111
"peerDependencies": {
@@ -93,10 +116,11 @@
93116
"@4c/cli": "^4.0.4",
94117
"@4c/rollout": "^4.0.2",
95118
"@4c/tsconfig": "^0.4.1",
96-
"@babel/cli": "^7.20.7",
97-
"@babel/core": "^7.20.12",
98-
"@babel/preset-react": "^7.18.6",
99-
"@babel/preset-typescript": "^7.18.6",
119+
"@babel/cli": "^7.26.4",
120+
"@babel/core": "^7.26.0",
121+
"@babel/preset-react": "^7.26.3",
122+
"@babel/preset-typescript": "^7.26.0",
123+
"@eslint/js": "^9.17.0",
100124
"@react-bootstrap/eslint-config": "^2.0.0",
101125
"@rollup/plugin-node-resolve": "^15.2.3",
102126
"@testing-library/dom": "^10.3.1",
@@ -106,8 +130,8 @@
106130
"@types/react": "^18.3.3",
107131
"@types/react-dom": "^18.3.0",
108132
"@types/react-transition-group": "^4.4.4",
109-
"@typescript-eslint/eslint-plugin": "^4.33.0",
110-
"@typescript-eslint/parser": "^4.33.0",
133+
"@typescript-eslint/eslint-plugin": "^8.19.1",
134+
"@typescript-eslint/parser": "^8.19.1",
111135
"@vitejs/plugin-react": "^4.3.2",
112136
"@vitest/browser": "^2.1.3",
113137
"@vitest/coverage-istanbul": "2.1.3",
@@ -116,25 +140,27 @@
116140
"babel-preset-env-modules": "^1.0.1",
117141
"cherry-pick": "^0.5.0",
118142
"cross-env": "^7.0.3",
119-
"eslint": "^7.24.0",
120-
"eslint-config-4catalyzer-typescript": "^3.2.1",
121-
"eslint-config-prettier": "^8.5.0",
122-
"eslint-plugin-import": "^2.26.0",
123-
"eslint-plugin-jsx-a11y": "^6.5.1",
124-
"eslint-plugin-prettier": "^3.4.1",
125-
"eslint-plugin-react": "^7.30.0",
126-
"eslint-plugin-react-hooks": "^4.6.0",
143+
"eslint": "^9.17.0",
144+
"eslint-config-4catalyzer-typescript": "^3.3.0",
145+
"eslint-config-prettier": "^9.1.0",
146+
"eslint-plugin-import": "^2.31.0",
147+
"eslint-plugin-jsx-a11y": "^6.10.2",
148+
"eslint-plugin-prettier": "^5.2.1",
149+
"eslint-plugin-react": "^7.37.3",
150+
"eslint-plugin-react-hooks": "^5.1.0",
127151
"gh-pages": "^3.1.0",
152+
"globals": "^15.14.0",
128153
"hookem": "^1.0.9",
129154
"lint-staged": "^10.5.4",
130155
"playwright": "^1.48.0",
131-
"prettier": "^2.7.1",
156+
"prettier": "^3.4.2",
132157
"react": "^18.3.1",
133158
"react-dom": "^18.3.1",
134159
"react-transition-group": "^4.4.1",
135160
"rimraf": "^3.0.2",
136161
"rollup": "^4.18.1",
137-
"typescript": "^4.7.4",
162+
"typescript": "^5.7.3",
163+
"typescript-eslint": "^8.19.1",
138164
"vitest": "^2.1.3"
139165
},
140166
"bugs": {

src/Anchor.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
/* eslint-disable jsx-a11y/no-static-element-interactions */
2-
/* eslint-disable jsx-a11y/anchor-has-content */
3-
41
import * as React from 'react';
52

6-
import { useEventCallback } from '@restart/hooks';
3+
import useEventCallback from '@restart/hooks/useEventCallback';
74
import { useButtonProps } from './Button';
85

96
export function isTrivialHref(href?: string) {

src/DropdownContext.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import * as React from 'react';
22
import type { Placement } from './usePopper';
33

44
export type DropdownContextValue = {
5-
toggle: (nextShow: boolean, event?: React.SyntheticEvent | Event) => void;
5+
toggle: (
6+
nextShow: boolean,
7+
event?: React.SyntheticEvent | KeyboardEvent | MouseEvent,
8+
) => void;
69
menuElement: HTMLElement | null;
710
toggleElement: HTMLElement | null;
811
setMenu: (ref: HTMLElement | null) => void;

src/DropdownMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function useDropdownMenu(options: UseDropdownMenuOptions = {}) {
126126
}
127127

128128
const handleClose = (e: React.SyntheticEvent | Event) => {
129-
context?.toggle(false, e);
129+
context?.toggle(false, e as any);
130130
};
131131

132132
const { placement, setMenu, menuElement, toggleElement } = context || {};

src/DropdownToggle.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function useDropdownToggle(): [
4040
} = useContext(DropdownContext) || {};
4141
const handleClick = useCallback(
4242
(e: Event | React.SyntheticEvent<Element, Event>) => {
43-
toggle(!show, e);
43+
toggle(!show, e as any);
4444
},
4545
[show, toggle],
4646
);

src/ImperativeTransition.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import useMergedRefs from '@restart/hooks/useMergedRefs';
22
import useEventCallback from '@restart/hooks/useEventCallback';
33
import useIsomorphicEffect from '@restart/hooks/useIsomorphicEffect';
4-
import React, { useRef, cloneElement, useState } from 'react';
4+
import { useRef, cloneElement, useState } from 'react';
55
import { TransitionComponent, TransitionProps } from './types';
66
import NoopTransition from './NoopTransition';
77
import RTGTransition from './RTGTransition';
@@ -62,11 +62,8 @@ export function useTransition({
6262

6363
export interface ImperativeTransitionProps extends TransitionProps {
6464
transition: TransitionHandler;
65-
// eslint-disable-next-line react/no-unused-prop-types
6665
appear: true;
67-
// eslint-disable-next-line react/no-unused-prop-types
6866
mountOnEnter: true;
69-
// eslint-disable-next-line react/no-unused-prop-types
7067
unmountOnExit: true;
7168
}
7269

0 commit comments

Comments
 (0)