Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert babel plugin to typescript #570

Merged
merged 33 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
574f21c
feat: convert js files to ts
jeremybarbet Feb 7, 2025
a77c993
feat: add first draft of esbuild for the babel plugin
jeremybarbet Feb 11, 2025
3b604d4
refactor: avoid passing down `t` and use `@babel/types` package instead
jeremybarbet Feb 11, 2025
55ca42e
feat: set types for functions params + define consts/types
jeremybarbet Feb 11, 2025
0b15aae
feat: `import.ts` is now type-safe
jeremybarbet Feb 11, 2025
8fcc948
feat: `exotic.ts` mostly type-safe
jeremybarbet Feb 11, 2025
7c74d6f
feat: `variants.ts` is now type-safe
jeremybarbet Feb 11, 2025
4cf5078
feat: `isUnistylesStyleSheet` is now type-safe
jeremybarbet Feb 11, 2025
4446532
feat: `isKindOfStyleSheet` is now type-safe
jeremybarbet Feb 11, 2025
4a546e7
feat: `addStyleSheetTag` is now type-safe
jeremybarbet Feb 11, 2025
1f3e198
feat: `getStylesDependenciesFromObject` is now type-safe
jeremybarbet Feb 11, 2025
ca25248
feat: `getStylesDependenciesFromFunction` is now type-safe
jeremybarbet Feb 11, 2025
acf2564
chore: group private functions together
jeremybarbet Feb 11, 2025
e5755ab
feat: `addDependencies` is now type-safe
jeremybarbet Feb 11, 2025
2dce9e9
feat: `toUnistylesDependency` is now type-safe
jeremybarbet Feb 11, 2025
d5e4d1a
feat: `getProperty` is now type-safe
jeremybarbet Feb 11, 2025
52bf741
feat: `index.ts` is now type-safe
jeremybarbet Feb 11, 2025
f341b5c
chore: run biome on plugin files
jeremybarbet Feb 11, 2025
c7856cd
feat: add build:plugin to prepare command
jeremybarbet Feb 11, 2025
673dddb
feat: manually apply latest changes
jeremybarbet Feb 11, 2025
47d3473
Merge branch 'main' into feat/convert-plugin-to-typescript
jeremybarbet Feb 11, 2025
90c6522
fix: avoid mismatch between @babel/types deps
jeremybarbet Feb 11, 2025
50c6064
chore: cleanup semicolons
jeremybarbet Feb 11, 2025
1b62201
refactor: remove sourcemap
jeremybarbet Feb 11, 2025
551538d
fix: refs for babel plugin types
jeremybarbet Feb 13, 2025
5556abc
refactor: use `import * as t from '@babel/types'`
jeremybarbet Feb 13, 2025
f5bb4aa
chore: rework prepare command for new plugin bundle
jeremybarbet Feb 13, 2025
a18f303
chore: tests against source files
jeremybarbet Feb 13, 2025
692dd56
fix: infer babel pass types
jeremybarbet Feb 13, 2025
666ba27
docs: update type description
jeremybarbet Feb 13, 2025
5f1fa6e
fix: update plugin path
jeremybarbet Feb 13, 2025
3971e5f
chore: convert test files to typescript
jeremybarbet Feb 13, 2025
49ed75c
fix: update tests identifiers
jeremybarbet Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"files": {
"include": ["src/**/*.ts", "src/**/*.tsx"],
"ignore": ["example", "expo-example", "docs", "plugin", "lib"]
"include": ["src/**/*.ts", "src/**/*.tsx", "plugin/**/*.ts"],
"ignore": ["example", "expo-example", "docs", "lib"]
},
"formatter": {
"enabled": false
Expand Down
2 changes: 1 addition & 1 deletion docs/src/content/docs/v3/other/babel-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ It will `console.log` name of the file and component with Unistyles dependencies
You can apply any of the options above as follows:

```js title="babel.config.js"
/** @type {import('react-native-unistyles/plugin').UnistylesPluginOptions} */
/** @type {import('react-native-unistyles/plugin/src/types').UnistylesPluginOptions} */
const unistylesPluginOptions = {
autoProcessRoot: 'src',
autoProcessImports: ['@react-native-ui-kit', '@codemask/styles'],
Expand Down
2 changes: 1 addition & 1 deletion example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')
const pak = require('../package.json')

/** @type {import('../plugin').UnistylesPluginOptions} */
/** @type {import('../plugin/src/types').UnistylesPluginOptions} */
const unistylesPluginOptions = {
debug: true,
isLocal: true,
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"lint": "biome lint",
"check": "biome check --write",
"check:ci": "biome check",
"prepare": "husky && bob build",
"prepare": "husky && bob build && yarn plugin:build && yarn plugin:types",
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn check' 'yarn test'",
"release": "release-it"
"release": "release-it",
"plugin:build": "node plugin/esbuild.js",
"plugin:types": "tsc --emitDeclarationOnly --declaration plugin/src/types.ts --outDir plugin && mv plugin/types.d.ts plugin/index.d.ts && yarn check"
},
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
Expand All @@ -31,6 +33,7 @@
},
"./plugin": {
"module": "./plugin/index.js",
"types": "./plugin/index.d.ts",
"default": "./plugin/index.js"
},
"./package.json": "./package.json",
Expand All @@ -54,6 +57,8 @@
"react-native.config.js",
"Unistyles.podspec",
"!plugin/__tests__",
"!plugin/src",
"!plugin/esbuild.js",
"!ios/build",
"!android/build",
"!android/gradle",
Expand Down Expand Up @@ -83,9 +88,11 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@babel/core": "7.26.8",
"@babel/plugin-syntax-jsx": "7.25.9",
"@babel/preset-flow": "7.25.9",
"@babel/preset-typescript": "7.26.0",
"@babel/types": "7.26.8",
"@biomejs/biome": "1.9.4",
"@commitlint/config-conventional": "19.6.0",
"@react-native/normalize-colors": "0.77.0",
Expand All @@ -95,6 +102,7 @@
"babel-plugin-tester": "11.0.4",
"commitlint": "19.6.1",
"concurrently": "9.1.2",
"esbuild": "0.25.0",
"husky": "9.1.7",
"jest": "29.7.0",
"metro-react-native-babel-preset": "0.77.0",
Expand Down Expand Up @@ -178,5 +186,8 @@
"name": "TurboUnistyles",
"type": "modules",
"jsSrcsDir": "./src/specs/TurboUnistyles"
},
"resolutions": {
"@babel/types": "7.26.8"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pluginTester } from 'babel-plugin-tester'
import plugin from '../'
import plugin from '../src/index'

pluginTester({
plugin,
Expand Down Expand Up @@ -72,7 +72,7 @@ pluginTester({
uni__dependencies: [0, 9, 4]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -127,7 +127,7 @@ pluginTester({
uni__dependencies: [0, 9]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -176,7 +176,7 @@ pluginTester({
uni__dependencies: [0, 9, 12, 13]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -352,7 +352,7 @@ pluginTester({
uni__dependencies: [0, 11, 10, 3, 5]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -415,7 +415,7 @@ pluginTester({
}
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -462,7 +462,7 @@ pluginTester({
uni__dependencies: [0, 14]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -509,7 +509,7 @@ pluginTester({
uni__dependencies: [0, 5]
})
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -562,7 +562,7 @@ pluginTester({
uni__dependencies: [14]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -652,7 +652,7 @@ pluginTester({
}
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -704,7 +704,7 @@ pluginTester({
uni__dependencies: [0, 3]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -756,7 +756,7 @@ pluginTester({
uni__dependencies: [0]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -798,7 +798,7 @@ pluginTester({
container: { ...theme.components.container, uni__dependencies: [0] },
container2: { ...theme.components.text.nested.deep, uni__dependencies: [0] }
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -854,7 +854,7 @@ pluginTester({
uni__dependencies: [14, 6, 12]
}
}),
664955283
664955593
)
`
},
Expand Down Expand Up @@ -953,7 +953,7 @@ pluginTester({
})
}
},
664955283
664955593
)
`
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pluginTester } from 'babel-plugin-tester'
import plugin from '../'
import plugin from '../src/index'

pluginTester({
plugin,
Expand Down Expand Up @@ -47,7 +47,7 @@ pluginTester({
flex: 1
}
},
75510274
75510584
)
`
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/__tests__/playground.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const babel = require('@babel/core')
const plugin = require('../index.js')
const plugin = require('../index')

const filePath = '../../expo-example/app/(tabs)/index.tsx'

const result = babel.transformFileSync(filePath, {
presets: ['@babel/preset-typescript', '@babel/preset-flow'],
plugins: [plugin],
filename: filePath,
filename: filePath
})

console.log(result.code)
Loading