Skip to content

Commit 278eadf

Browse files
committed
refactor: convert primitives package to TS
1 parent edcc993 commit 278eadf

File tree

10 files changed

+162
-31
lines changed

10 files changed

+162
-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
}

yarn.lock

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,13 @@
13671367
dependencies:
13681368
eslint-visitor-keys "^3.3.0"
13691369

1370+
"@eslint-community/eslint-utils@^4.4.0":
1371+
version "4.4.1"
1372+
resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz#d1145bf2c20132d6400495d6df4bf59362fd9d56"
1373+
integrity sha512-s3O3waFUrMV8P/XaF/+ZTp1X9XBZW1a4B97ZnjQF2KYWaFD2A8KyFBsrsfSjEmjn3RGWAIuvlneuZm3CUK3jbA==
1374+
dependencies:
1375+
eslint-visitor-keys "^3.4.3"
1376+
13701377
"@eslint-community/regexpp@^4.6.1":
13711378
version "4.10.0"
13721379
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.10.0.tgz#548f6de556857c8bb73bbee70c35dc82a2e74d63"
@@ -2187,6 +2194,14 @@
21872194
smob "^1.0.0"
21882195
terser "^5.17.4"
21892196

2197+
"@rollup/plugin-typescript@^12.1.2":
2198+
version "12.1.2"
2199+
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-12.1.2.tgz#ebaeec2e7376faa889030ccd7cb485a649e63118"
2200+
integrity sha512-cdtSp154H5sv637uMr1a8OTWB0L1SWDSm1rDGiyfcGcvQ6cuTs4MDk2BVEBGysUWago4OJN4EQZqOTl/QY3Jgg==
2201+
dependencies:
2202+
"@rollup/pluginutils" "^5.1.0"
2203+
resolve "^1.22.1"
2204+
21902205
"@rollup/pluginutils@^5.0.1", "@rollup/pluginutils@^5.1.0":
21912206
version "5.1.0"
21922207
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.0.tgz#7e53eddc8c7f483a4ad0b94afb1f7f5fd3c771e0"
@@ -2685,11 +2700,24 @@
26852700
"@typescript-eslint/types" "6.21.0"
26862701
"@typescript-eslint/visitor-keys" "6.21.0"
26872702

2703+
"@typescript-eslint/scope-manager@8.23.0":
2704+
version "8.23.0"
2705+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-8.23.0.tgz#ee3bb7546421ca924b9b7a8b62a77d388193ddec"
2706+
integrity sha512-OGqo7+dXHqI7Hfm+WqkZjKjsiRtFUQHPdGMXzk5mYXhJUedO7e/Y7i8AK3MyLMgZR93TX4bIzYrfyVjLC+0VSw==
2707+
dependencies:
2708+
"@typescript-eslint/types" "8.23.0"
2709+
"@typescript-eslint/visitor-keys" "8.23.0"
2710+
26882711
"@typescript-eslint/types@6.21.0":
26892712
version "6.21.0"
26902713
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.21.0.tgz#205724c5123a8fef7ecd195075fa6e85bac3436d"
26912714
integrity sha512-1kFmZ1rOm5epu9NZEZm1kckCDGj5UJEf7P1kliH4LKu/RkwpsfqqGmY2OOcUs18lSlQBKLDYBOGxRVtrMN5lpg==
26922715

2716+
"@typescript-eslint/types@8.23.0":
2717+
version "8.23.0"
2718+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.23.0.tgz#3355f6bcc5ebab77ef6dcbbd1113ec0a683a234a"
2719+
integrity sha512-1sK4ILJbCmZOTt9k4vkoulT6/y5CHJ1qUYxqpF1K/DBAd8+ZUL4LlSCxOssuH5m4rUaaN0uS0HlVPvd45zjduQ==
2720+
26932721
"@typescript-eslint/typescript-estree@6.21.0":
26942722
version "6.21.0"
26952723
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.21.0.tgz#c47ae7901db3b8bddc3ecd73daff2d0895688c46"
@@ -2704,6 +2732,30 @@
27042732
semver "^7.5.4"
27052733
ts-api-utils "^1.0.1"
27062734

2735+
"@typescript-eslint/typescript-estree@8.23.0":
2736+
version "8.23.0"
2737+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-8.23.0.tgz#f633ef08efa656e386bc44b045ffcf9537cc6924"
2738+
integrity sha512-LcqzfipsB8RTvH8FX24W4UUFk1bl+0yTOf9ZA08XngFwMg4Kj8A+9hwz8Cr/ZS4KwHrmo9PJiLZkOt49vPnuvQ==
2739+
dependencies:
2740+
"@typescript-eslint/types" "8.23.0"
2741+
"@typescript-eslint/visitor-keys" "8.23.0"
2742+
debug "^4.3.4"
2743+
fast-glob "^3.3.2"
2744+
is-glob "^4.0.3"
2745+
minimatch "^9.0.4"
2746+
semver "^7.6.0"
2747+
ts-api-utils "^2.0.1"
2748+
2749+
"@typescript-eslint/utils@^8.23.0":
2750+
version "8.23.0"
2751+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.23.0.tgz#b269cbdc77129fd6e0e600b168b5ef740a625554"
2752+
integrity sha512-uB/+PSo6Exu02b5ZEiVtmY6RVYO7YU5xqgzTIVZwTHvvK3HsL8tZZHFaTLFtRG3CsV4A5mhOv+NZx5BlhXPyIA==
2753+
dependencies:
2754+
"@eslint-community/eslint-utils" "^4.4.0"
2755+
"@typescript-eslint/scope-manager" "8.23.0"
2756+
"@typescript-eslint/types" "8.23.0"
2757+
"@typescript-eslint/typescript-estree" "8.23.0"
2758+
27072759
"@typescript-eslint/visitor-keys@6.21.0":
27082760
version "6.21.0"
27092761
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.21.0.tgz#87a99d077aa507e20e238b11d56cc26ade45fe47"
@@ -2712,6 +2764,14 @@
27122764
"@typescript-eslint/types" "6.21.0"
27132765
eslint-visitor-keys "^3.4.1"
27142766

2767+
"@typescript-eslint/visitor-keys@8.23.0":
2768+
version "8.23.0"
2769+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-8.23.0.tgz#40405fd26a61d23f5f4c2ed0f016a47074781df8"
2770+
integrity sha512-oWWhcWDLwDfu++BGTZcmXWqpwtkwb5o7fxUIGksMQQDSdPW9prsSnfIOZMlsj4vBOSrcnjIUZMiIjODgGosFhQ==
2771+
dependencies:
2772+
"@typescript-eslint/types" "8.23.0"
2773+
eslint-visitor-keys "^4.2.0"
2774+
27152775
"@ungap/structured-clone@^1.2.0":
27162776
version "1.2.0"
27172777
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
@@ -2728,6 +2788,11 @@
27282788
"@types/babel__core" "^7.20.5"
27292789
react-refresh "^0.14.0"
27302790

2791+
"@vitest/eslint-plugin@^1.1.27":
2792+
version "1.1.27"
2793+
resolved "https://registry.yarnpkg.com/@vitest/eslint-plugin/-/eslint-plugin-1.1.27.tgz#54dd7bf9d20dcab9a12e3dd13a205cdec8bebd51"
2794+
integrity sha512-aGPTmeaNiUDo2OIMPj1HKiF5q4fu2IIA9lMc0AwOk0nOvL2kLmQBY8AbFmYj895ApzamN46UtQYmxlRSjbTZqQ==
2795+
27312796
"@vitest/expect@1.6.1":
27322797
version "1.6.1"
27332798
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-1.6.1.tgz#b90c213f587514a99ac0bf84f88cff9042b0f14d"
@@ -4815,6 +4880,11 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4
48154880
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800"
48164881
integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==
48174882

4883+
eslint-visitor-keys@^4.2.0:
4884+
version "4.2.0"
4885+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz#687bacb2af884fcdda8a6e7d65c606f46a14cd45"
4886+
integrity sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==
4887+
48184888
eslint@^8.56.0:
48194889
version "8.56.0"
48204890
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.56.0.tgz#4957ce8da409dc0809f99ab07a1b94832ab74b15"
@@ -7086,6 +7156,13 @@ minimatch@^8.0.2:
70867156
dependencies:
70877157
brace-expansion "^2.0.1"
70887158

7159+
minimatch@^9.0.4:
7160+
version "9.0.5"
7161+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.5.tgz#d74f9dd6b57d83d8e98cfb82133b03978bc929e5"
7162+
integrity sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==
7163+
dependencies:
7164+
brace-expansion "^2.0.1"
7165+
70897166
minimist-options@4.1.0, minimist-options@^4.0.2:
70907167
version "4.1.0"
70917168
resolved "https://registry.yarnpkg.com/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
@@ -9063,6 +9140,11 @@ semver@^7.0.0, semver@^7.1.1, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semve
90639140
dependencies:
90649141
lru-cache "^6.0.0"
90659142

9143+
semver@^7.6.0:
9144+
version "7.7.1"
9145+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.7.1.tgz#abd5098d82b18c6c81f6074ff2647fd3e7220c9f"
9146+
integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==
9147+
90669148
semver@^7.6.3:
90679149
version "7.6.3"
90689150
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
@@ -9936,6 +10018,11 @@ ts-api-utils@^1.0.1:
993610018
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.2.1.tgz#f716c7e027494629485b21c0df6180f4d08f5e8b"
993710019
integrity sha512-RIYA36cJn2WiH9Hy77hdF9r7oEwxAtB/TS9/S4Qd90Ap4z5FSiin5zEiTL44OII1Y3IIlEvxwxFUVgrHSZ/UpA==
993810020

10021+
ts-api-utils@^2.0.1:
10022+
version "2.0.1"
10023+
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-2.0.1.tgz#660729385b625b939aaa58054f45c058f33f10cd"
10024+
integrity sha512-dnlgjFSVetynI8nzgJ+qF62efpglpWRk8isUEWZGWlJYySCTD6aKvbUDu+zbPeDakk3bg5H4XpitHukgfL1m9w==
10025+
993910026
ts-interface-checker@^0.1.9:
994010027
version "0.1.13"
994110028
resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699"

0 commit comments

Comments
 (0)