Skip to content

Commit 47f0f1c

Browse files
Build with tsup (#26)
1 parent 6ffd1bb commit 47f0f1c

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
node_modules
2-
index.cjs.js
3-
index.es.js
42
package-lock.json
53
dist
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import React from 'react'
2-
import mitt from 'mitt'
2+
import mitt, { type Emitter, type EventType, type Handler } from 'mitt'
33

4-
export const BusContext = React.createContext(/** @type {null|import('mitt').Emitter} */ (null))
4+
export const BusContext = React.createContext<Emitter | null>(null)
55
const P = BusContext.Provider
66

7-
/**
8-
* Return the event emitter.
9-
*
10-
* @return {import('mitt').Emitter}
11-
*/
7+
/** Return the event emitter. */
128
export function useBus () {
139
const bus = React.useContext(BusContext)
1410
if (!bus) throw new Error('useBus: missing context')
1511
return bus
1612
}
1713

1814
/**
19-
* Attach an event listener to the bus while this component is mounted. Adds the listener after mount, and removes it before unmount.
20-
21-
* @param {import('mitt').EventType} name
22-
* @param {import('mitt').Handler} listener
15+
* Attach an event listener to the bus while this component is mounted.
16+
*
17+
* Adds the listener after mount, and removes it before unmount.
2318
*/
24-
export function useListener (name, listener) {
19+
export function useListener (name: EventType, listener: Handler) {
2520
const bus = useBus()
2621
React.useEffect(() => {
2722
bus.on(name, listener)
@@ -33,10 +28,8 @@ export function useListener (name, listener) {
3328

3429
/**
3530
* Create an event emitter that will be available to all deeply nested child elements using the useBus() hook.
36-
*
37-
* @param {{ children?: import('react').ReactNode }} props
3831
*/
39-
export function Provider ({ children }) {
32+
export function Provider ({ children }: { children: React.ReactNode }) {
4033
const [bus] = React.useState(() => mitt())
4134
return <P value={bus}>{children}</P>
4235
}

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
"name": "react-bus",
33
"description": "A global event emitter for react.",
44
"version": "3.0.0",
5-
"typings": "types/index.d.ts",
5+
"main": "dist/index.js",
6+
"typings": "dist/index.d.ts",
7+
"exports": {
8+
"./package.json": "./package.json",
9+
".": {
10+
"types": "dist/index.d.mts",
11+
"require": "dist/index.js",
12+
"default": "dist/index.mjs"
13+
}
14+
},
615
"author": "Renée Kooi <[email protected]>",
716
"bugs": {
817
"url": "https://github.com/goto-bus-stop/react-bus/issues"
@@ -15,10 +24,9 @@
1524
"react": ">=17.0.0"
1625
},
1726
"devDependencies": {
18-
"@rollup/plugin-buble": "^0.21.3",
1927
"react": "^17.0.0",
2028
"react-test-renderer": "^17.0.0",
21-
"rollup": "^2.38.0",
29+
"tsup": "^8.1.0",
2230
"typescript": "^5.0.2"
2331
},
2432
"homepage": "https://github.com/goto-bus-stop/react-bus#readme",
@@ -30,14 +38,12 @@
3038
"react"
3139
],
3240
"license": "MIT",
33-
"main": "./dist/react-bus.cjs.js",
34-
"module": "./dist/react-bus.es.js",
3541
"repository": {
3642
"type": "git",
3743
"url": "git+https://github.com/goto-bus-stop/react-bus.git"
3844
},
3945
"scripts": {
40-
"build": "rollup -c",
46+
"build": "tsup --format=esm --format=cjs --dts index.tsx index.tsx",
4147
"prepare": "npm run build",
4248
"test": "node --test"
4349
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"lib": ["es2015"],
4+
"moduleResolution": "node",
45
"allowJs": true,
56
"checkJs": true,
67
"declaration": true,
@@ -10,5 +11,5 @@
1011
"esModuleInterop": true,
1112
"outDir": "types"
1213
},
13-
"files": ["index.js"]
14+
"files": ["index.tsx"]
1415
}

0 commit comments

Comments
 (0)