Skip to content

Commit 17ac5c5

Browse files
committed
refactor: convert primitives package to TS
1 parent edcc993 commit 17ac5c5

File tree

11 files changed

+163
-31
lines changed

11 files changed

+163
-31
lines changed

.eslintrc.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
"plugin:react/recommended",
1414
"airbnb",
1515
"prettier",
16-
"plugin:react/jsx-runtime"
16+
"plugin:react/jsx-runtime",
17+
"plugin:@vitest/legacy-recommended"
1718
],
1819
"globals": {
1920
"URL": false,
2021
"BROWSER": false,
2122
"Atomics": "readonly",
2223
"SharedArrayBuffer": "readonly"
2324
},
24-
"plugins": ["react"],
25+
"plugins": ["react", "@vitest"],
2526
"rules": {
2627
"arrow-body-style": 0,
2728
"default-case-last": 0,
@@ -43,7 +44,10 @@
4344
"react/jsx-props-no-spreading": 0,
4445
"react/jsx-no-useless-fragment": 0,
4546
"react/prop-types": 0,
46-
"react/state-in-constructor": 0
47+
"react/state-in-constructor": 0,
48+
"@vitest/valid-expect": 0,
49+
"@vitest/no-identical-title": 0,
50+
"@vitest/expect-expect": 0
4751
},
4852
"overrides": [
4953
{

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
"@rollup/plugin-node-resolve": "^15.2.0",
4242
"@rollup/plugin-replace": "^5.0.0",
4343
"@rollup/plugin-terser": "^0.4.4",
44+
"@rollup/plugin-typescript": "^12.1.2",
4445
"@testing-library/react": "^14.0.0",
4546
"@typescript-eslint/parser": "^6.21.0",
47+
"@typescript-eslint/utils": "^8.23.0",
4648
"@vitejs/plugin-react": "^4.2.1",
49+
"@vitest/eslint-plugin": "^1.1.27",
4750
"babel-plugin-add-module-exports": "^1.0.0",
4851
"canvas": "^2.11.2",
4952
"chalk": "^2.4.2",

packages/primitives/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
"author": "Diego Muracciole <diegomuracciole@gmail.com>",
77
"homepage": "https://github.com/diegomura/react-pdf#readme",
88
"type": "module",
9-
"main": "./src/index.js",
9+
"main": "./lib/index.js",
10+
"types": "./lib/index.d.ts",
1011
"repository": {
1112
"type": "git",
1213
"url": "https://github.com/diegomura/react-pdf.git",
1314
"directory": "packages/primitives"
1415
},
1516
"scripts": {
17+
"build": "rimraf ./lib && rollup -c",
18+
"watch": "rimraf ./lib && rollup -c -w",
1619
"test": "vitest"
1720
},
1821
"files": [
19-
"lib",
20-
"src"
22+
"lib"
2123
]
2224
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
3+
const config = {
4+
input: 'src/index.ts',
5+
output: {
6+
dir: 'lib',
7+
format: 'es',
8+
},
9+
plugins: [typescript()],
10+
};
11+
12+
export default config;
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/* eslint-disable import/no-unresolved */
2+
/* eslint-disable import/no-extraneous-dependencies */
3+
14
import { describe, expect, test } from 'vitest';
25

3-
import * as primitives from '../src';
6+
import * as primitives from '../src/index.ts';
47

58
describe('primitives', () => {
69
test('should export group', () => {

packages/primitives/tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"declarationDir": "lib",
5+
"emitDeclarationOnly": true,
6+
"outDir": "lib",
7+
"strict": true,
8+
"types": ["vitest/globals"],
9+
"allowImportingTsExtensions": true,
10+
},
11+
}

packages/types/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"type": "git",
1111
"url": "https://github.com/diegomura/react-pdf.git",
1212
"directory": "packages/types"
13+
},
14+
"dependencies": {
15+
"@react-pdf/primitives": "^4.1.0"
1316
}
1417
}

packages/types/primitive.d.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1+
/* eslint-disable no-shadow */
2+
/* eslint-disable no-unused-vars */
3+
/* eslint-disable import/prefer-default-export */
4+
5+
import * as P from '@react-pdf/primitives';
6+
17
export enum Primitive {
2-
G = 'G',
3-
Svg = 'SVG',
4-
View = 'VIEW',
5-
Text = 'TEXT',
6-
Link = 'LINK',
7-
Page = 'PAGE',
8-
Note = 'NOTE',
9-
Path = 'PATH',
10-
Rect = 'RECT',
11-
Line = 'LINE',
12-
Stop = 'STOP',
13-
Defs = 'DEFS',
14-
Image = 'IMAGE',
15-
Tspan = 'TSPAN',
16-
Canvas = 'CANVAS',
17-
Circle = 'CIRCLE',
18-
Ellipse = 'ELLIPSE',
19-
Polygon = 'POLYGON',
20-
Document = 'DOCUMENT',
21-
Polyline = 'POLYLINE',
22-
ClipPath = 'CLIP_PATH',
23-
TextInstance = 'TEXT_INSTANCE',
24-
LinearGradient = 'LINEAR_GRADIENT',
25-
RadialGradient = 'RADIAL_GRADIENT',
8+
G = P.G,
9+
Svg = P.Svg,
10+
View = P.View,
11+
Text = P.Text,
12+
Link = P.Link,
13+
Page = P.Page,
14+
Note = P.Note,
15+
Path = P.Path,
16+
Rect = P.Rect,
17+
Line = P.Line,
18+
Stop = P.Stop,
19+
Defs = P.Defs,
20+
Image = P.Image,
21+
Tspan = P.Tspan,
22+
Canvas = P.Canvas,
23+
Circle = P.Circle,
24+
Ellipse = P.Ellipse,
25+
Polygon = P.Polygon,
26+
Document = P.Document,
27+
Polyline = P.Polyline,
28+
ClipPath = P.ClipPath,
29+
TextInstance = P.TextInstance,
30+
LinearGradient = P.LinearGradient,
31+
RadialGradient = P.RadialGradient,
2632
}

vitest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import react from '@vitejs/plugin-react';
66
export default defineConfig({
77
plugins: [react()],
88
test: {
9+
globals: true,
910
watch: false,
1011
poolOptions: {
1112
threads: {

0 commit comments

Comments
 (0)