Skip to content

Commit cd23372

Browse files
committed
refactor: convert stylesheet package to TS
1 parent 700535c commit cd23372

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+773
-246
lines changed

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ const tsConfig = {
234234
'no-unreachable': 'off',
235235
'no-unsafe-negation': 'off',
236236
'no-unused-vars': 'off',
237-
'@typescript-eslint/ban-ts-comment': 'error',
238237
'@typescript-eslint/no-array-constructor': 'error',
239238
'@typescript-eslint/no-duplicate-enum-values': 'error',
240239
'@typescript-eslint/no-empty-object-type': 'error',

packages/fns/src/compose.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
import reverse from './reverse';
1+
type ArityOneFn = (arg: any, ...args: any[]) => any;
2+
3+
type FirstFnParameterType<T extends ArityOneFn[]> = T extends [
4+
...any,
5+
(arg: infer A, ...args: any[]) => any,
6+
]
7+
? A
8+
: never;
9+
10+
type LastFnReturnType<T extends ArityOneFn[]> = T extends [
11+
(arg: any, ...args: any[]) => infer R,
12+
...any,
13+
]
14+
? R
15+
: never;
216

317
/**
418
* Performs right-to-left function composition
@@ -7,17 +21,18 @@ import reverse from './reverse';
721
* @returns Composed function
822
*/
923
const compose =
10-
(...fns: any[]) =>
11-
(value: any, ...args: any[]) => {
12-
let result = value;
13-
const reversedFns = reverse(fns);
24+
<T extends ArityOneFn[]>(...fns: T) =>
25+
(value: FirstFnParameterType<T>, ...args: any[]): LastFnReturnType<T> => {
26+
let result: unknown = value;
27+
28+
const reversedFns = fns.slice().reverse();
1429

1530
for (let i = 0; i < reversedFns.length; i += 1) {
1631
const fn = reversedFns[i];
1732
result = fn(result, ...args);
1833
}
1934

20-
return result;
35+
return result as LastFnReturnType<T>;
2136
};
2237

2338
export default compose;
222 Bytes
Loading
536 KB
Loading
475 KB
Loading
682 KB
Loading

packages/renderer/tests/flex.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ describe('flex shorthand', () => {
1919
test('should support auto', async () => {
2020
const image = await mount(
2121
<View style={{ flexDirection: 'row', gap: 2 }}>
22-
<View style={{ height: 20, width: 20, backgroundColor: 'red' }} />
22+
<View style={{ height: 20, width: 20, backgroundColor: 'blue' }} />
2323
<View
2424
style={{
2525
height: 20,
2626
width: 20,
2727
flex: 'auto',
28-
backgroundColor: 'red',
28+
backgroundColor: 'blue',
2929
}}
3030
/>
3131
</View>,

packages/stylesheet/babel.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/stylesheet/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"homepage": "https://github.com/diegomura/react-pdf#readme",
88
"type": "module",
99
"main": "./lib/index.js",
10+
"types": "./lib/index.d.ts",
1011
"repository": {
1112
"type": "git",
1213
"url": "https://github.com/diegomura/react-pdf.git",
@@ -18,7 +19,6 @@
1819
"watch": "rimraf ./lib && rollup -c -w"
1920
},
2021
"dependencies": {
21-
"@babel/runtime": "^7.20.13",
2222
"@react-pdf/fns": "3.1.0",
2323
"@react-pdf/types": "^2.7.1",
2424
"color-string": "^1.9.1",
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1+
import { dts } from 'rollup-plugin-dts';
2+
import del from 'rollup-plugin-delete';
3+
import typescript from '@rollup/plugin-typescript';
14
import localResolve from 'rollup-plugin-local-resolve';
2-
import babel from '@rollup/plugin-babel';
35

46
import pkg from './package.json' with { type: 'json' };
57

6-
const input = 'src/index.js';
7-
8-
const getExternal = () => [
9-
...Object.keys(pkg.dependencies),
10-
/@babel\/runtime/,
11-
/@react-pdf/,
12-
];
13-
14-
const getPlugins = () => [
15-
localResolve(),
16-
babel({
17-
babelrc: true,
18-
babelHelpers: 'runtime',
19-
exclude: 'node_modules/**',
20-
}),
21-
];
22-
238
const config = {
24-
input,
9+
input: 'src/index.ts',
2510
output: { format: 'es', file: 'lib/index.js' },
26-
external: getExternal(),
27-
plugins: getPlugins(),
11+
external: [...Object.keys(pkg.dependencies), /@react-pdf/],
12+
plugins: [typescript(), localResolve()],
13+
};
14+
15+
const dtsConfig = {
16+
input: './lib/types/index.d.ts',
17+
output: [{ file: 'lib/index.d.ts', format: 'es' }],
18+
plugins: [dts(), del({ targets: 'lib/types', hook: 'buildEnd' })],
2819
};
2920

30-
export default config;
21+
export default [config, dtsConfig];

0 commit comments

Comments
 (0)