Skip to content

Commit 89eb9cc

Browse files
committed
fix: export useCountdown types fixes #193
This is fix for the issue where types for the hook are referenced by the shared package, which is not exported. The solve the problem now we copy the types from the shared package and add them to each package when bundling the code. This is not the best solution but it is the simplest. Once we have a good way to bundle types from monorepo this can be changed.
1 parent 889acc3 commit 89eb9cc

File tree

11 files changed

+59
-151
lines changed

11 files changed

+59
-151
lines changed

packages/mobile/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
22
"name": "react-native-countdown-circle-timer",
3-
"version": "3.0.8",
3+
"version": "3.0.9",
44
"description": "Lightweight React Native countdown timer component with color and progress animation based on SVG",
55
"main": "./lib/index.js",
66
"source": "./src/index.ts",
77
"files": [
88
"lib"
99
],
1010
"scripts": {
11-
"ts-declaration": "tsc --declaration --emitDeclarationOnly --outDir lib",
12-
"build": "pnpm ts-declaration && node scripts/build.js",
11+
"build": "node scripts/build.js",
1312
"dev:push": "pnpm run build && yalc push",
1413
"test": "jest --collectCoverage",
1514
"test:watch": "jest --watch",

packages/mobile/scripts/build.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const esbuild = require('esbuild')
23
const pkg = require('../package.json')
34

@@ -8,8 +9,16 @@ const commonProps = {
89
external: ['react', 'react-native', 'react-native-svg'],
910
}
1011

11-
esbuild.build({
12-
...commonProps,
13-
outfile: pkg.main,
14-
format: 'cjs',
15-
})
12+
esbuild
13+
.build({
14+
...commonProps,
15+
outfile: pkg.main,
16+
format: 'cjs',
17+
})
18+
.then(() => {
19+
fs.copyFile('../shared/src/types.ts', './lib/index.d.ts', (err) => {
20+
if (err) {
21+
throw err
22+
}
23+
})
24+
})

packages/mobile/src/CountdownCircleTimer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { View } from 'react-native'
33
import type { StyleProp, ViewStyle } from 'react-native'
44
import Svg, { Path } from 'react-native-svg'
55
import { useCountdown, getWrapperStyle, timeStyle } from '@countdown/shared'
6-
import type { Props } from './types'
6+
import type { Props } from '@countdown/shared'
77

88
const CountdownCircleTimer = (props: Props) => {
99
const { children, duration, strokeLinecap, trailColor, trailStrokeWidth } =

packages/mobile/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { CountdownCircleTimer, useCountdown } from './CountdownCircleTimer'
2-
export type { Props } from './types'
2+
export type { Props } from '@countdown/shared'

packages/mobile/src/types.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/shared/src/types.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
/// <reference types="react" />
2+
13
type ColorHex = `#${string}`
24
type ColorRGBA = `rgba(${string})`
35
type ColorURL = `url(#${string})`
4-
export type ColorRGB = `rgb(${string})`
5-
export type ColorFormat = ColorHex | ColorRGB | ColorRGBA | ColorURL
6+
export declare type ColorRGB = `rgb(${string})`
7+
export declare type ColorFormat = ColorHex | ColorRGB | ColorRGBA | ColorURL
8+
69
type TimeProps = {
710
remainingTime: number
811
elapsedTime: number
@@ -32,7 +35,7 @@ type OnComplete = {
3235
newInitialRemainingTime?: number
3336
}
3437

35-
export type Props = {
38+
export declare type Props = {
3639
/** Countdown duration in seconds */
3740
duration: number
3841
/** Set the initial remaining time if it is different than the duration */
@@ -62,3 +65,20 @@ export type Props = {
6265
/** On remaining time update event handler */
6366
onUpdate?: (remainingTime: number) => void
6467
} & (SingleColor | MultipleColors)
68+
69+
export declare const useCountdown: (props: Props) => {
70+
elapsedTime: number
71+
path: string
72+
pathLength: number
73+
remainingTime: number
74+
rotation: 'clockwise' | 'counterclockwise'
75+
size: number
76+
stroke: ColorFormat
77+
strokeDashoffset: number
78+
strokeWidth: number
79+
}
80+
81+
export declare const CountdownCircleTimer: {
82+
(props: Props): JSX.Element
83+
displayName: 'CountdownCircleTimer'
84+
}

packages/web/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-countdown-circle-timer",
3-
"version": "3.0.8",
3+
"version": "3.0.9",
44
"description": "Lightweight React countdown timer component with color and progress animation based on SVG",
55
"main": "./lib/index.js",
66
"module": "./lib/index.module.js",
@@ -10,8 +10,7 @@
1010
],
1111
"scripts": {
1212
"start": "node scripts/serve.js",
13-
"ts-declaration": "tsc --declaration --emitDeclarationOnly --outDir lib",
14-
"build": "pnpm ts-declaration && node scripts/build.js",
13+
"build": "node scripts/build.js",
1514
"dev:push": "pnpm run build && yalc push",
1615
"test": "jest --collectCoverage",
1716
"test:watch": "jest --watch",

packages/web/scripts/build.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const esbuild = require('esbuild')
23
const pkg = require('../package.json')
34

@@ -14,8 +15,16 @@ esbuild.build({
1415
format: 'cjs',
1516
})
1617

17-
esbuild.build({
18-
...commonProps,
19-
outfile: pkg.module,
20-
format: 'esm',
21-
})
18+
esbuild
19+
.build({
20+
...commonProps,
21+
outfile: pkg.module,
22+
format: 'esm',
23+
})
24+
.then(() => {
25+
fs.copyFile('../shared/src/types.ts', './lib/index.d.ts', (err) => {
26+
if (err) {
27+
throw err
28+
}
29+
})
30+
})

packages/web/src/CountdownCircleTimer.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
import { useCountdown, getWrapperStyle, timeStyle } from '@countdown/shared'
3-
import type { Props } from './types'
3+
import type { Props } from '@countdown/shared'
44

55
const CountdownCircleTimer = (props: Props) => {
66
const { children, strokeLinecap, trailColor, trailStrokeWidth } = props

packages/web/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { CountdownCircleTimer, useCountdown } from './CountdownCircleTimer'
2-
export type { Props } from './types'
2+
export type { Props } from '@countdown/shared'

0 commit comments

Comments
 (0)