Skip to content

Commit 4b4b771

Browse files
committed
Migrate to TypeScript
This PR does the minimum necessary work to migrate the package to TypeScript while keeping the existing package shape and runtime behavior intact. Changes: - install and configure TypeScript (duh) - migrate the source and test files from .js to .ts - add explicit types across the codebase - replace the handwritten index.d.ts with an autogenerated one - bump and reconfigure Rollup to build root index.js and index.d.ts - add CI step
1 parent 8440c2c commit 4b4b771

52 files changed

Lines changed: 896 additions & 1937 deletions

Some content is hidden

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

.babelrc

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

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ jobs:
2424
- name: Run linting
2525
run: biome lint
2626

27+
typescript:
28+
name: Type checking
29+
runs-on: ubuntu-24.04-arm
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v6
34+
35+
- name: Use pnpm
36+
uses: pnpm/action-setup@v4
37+
38+
- name: Use Node.js
39+
uses: actions/setup-node@v6
40+
with:
41+
node-version: "24"
42+
cache: "pnpm"
43+
44+
- name: Install dependencies
45+
run: pnpm install --frozen-lockfile
46+
47+
- name: Run type checking
48+
run: pnpm tsc
49+
2750
format:
2851
name: Format
2952
runs-on: ubuntu-24.04-arm

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ npm-debug.log
2020

2121
# Built files
2222
/index.js
23+
/index.d.ts

index.d.ts

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

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
"description": "Convert CSS text to a React Native stylesheet object",
55
"main": "index.js",
66
"types": "index.d.ts",
7+
"sideEffects": false,
78
"scripts": {
8-
"build": "rollup ./src/index.js -o index.js --f cjs && babel index.js -o index.js",
9+
"build": "rollup -c",
10+
"clean": "node -e \"fs.rmSync('./index.js', { force: true }); fs.rmSync('./index.d.ts', { force: true })\"",
911
"format": "biome format",
1012
"lint": "biome lint",
1113
"precommit": "lint-staged",
12-
"prepublish": "npm run build",
13-
"test": "pnpm lint && pnpm format && pnpm unit",
14+
"prebuild": "pnpm clean && pnpm tsc",
15+
"prepack": "pnpm build",
16+
"test": "pnpm lint && pnpm tsc && pnpm format && pnpm unit",
17+
"tsc": "tsc",
1418
"unit": "vitest",
1519
"unit:watch": "vitest --watch"
1620
},
@@ -37,12 +41,14 @@
3741
},
3842
"homepage": "https://github.com/styled-components/css-to-react-native#readme",
3943
"devDependencies": {
40-
"@babel/cli": "^7.6.2",
41-
"@babel/core": "^7.1.0",
42-
"@babel/preset-env": "^7.6.2",
44+
"@types/node": "^24.7.2",
45+
"@rollup/plugin-typescript": "^12.1.2",
4346
"@biomejs/biome": "2.4.9",
4447
"lint-staged": "^6.1.0",
45-
"rollup": "^1.22.0",
48+
"rollup": "^4.40.2",
49+
"rollup-plugin-dts": "^6.2.1",
50+
"tslib": "^2.8.1",
51+
"typescript": "^6.0.2",
4652
"vitest": "^4.0.1"
4753
},
4854
"dependencies": {
@@ -51,7 +57,7 @@
5157
"postcss-value-parser": "^4.0.2"
5258
},
5359
"lint-staged": {
54-
"*.js": [
60+
"*.{js,ts}": [
5561
"biome check",
5662
"git add"
5763
]

0 commit comments

Comments
 (0)