Skip to content

Commit

Permalink
feat: start fixing all the types + add esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Feb 7, 2025
1 parent 574f21c commit b5ebe50
Show file tree
Hide file tree
Showing 20 changed files with 398 additions and 201 deletions.
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/src/*.ts"],
"ignore": ["example", "expo-example", "docs", "lib"]
},
"formatter": {
"enabled": false
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"check:ci": "biome check",
"prepare": "husky && bob build",
"precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn check' 'yarn test'",
"release": "release-it"
"release": "release-it",
"build:plugin": "node plugin/esbuild.js"
},
"main": "lib/commonjs/index.js",
"module": "lib/module/index.js",
Expand Down Expand Up @@ -83,9 +84,11 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@babel/core": "7.25.9",
"@babel/plugin-syntax-jsx": "7.25.9",
"@babel/preset-flow": "7.25.9",
"@babel/preset-typescript": "7.26.0",
"@babel/preset-typescript": "7.25.9",
"@babel/types": "7.25.9",
"@biomejs/biome": "1.9.4",
"@commitlint/config-conventional": "19.6.0",
"@react-native/normalize-colors": "0.77.0",
Expand All @@ -95,6 +98,7 @@
"babel-plugin-tester": "11.0.4",
"commitlint": "19.6.1",
"concurrently": "9.1.2",
"esbuild": "0.24.2",
"husky": "9.1.7",
"jest": "29.7.0",
"metro-react-native-babel-preset": "0.77.0",
Expand Down
2 changes: 1 addition & 1 deletion plugin/__tests__/dependencies.spec.js
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 '../index'

pluginTester({
plugin,
Expand Down
2 changes: 1 addition & 1 deletion plugin/__tests__/imports.spec.js
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 '../index'

pluginTester({
plugin,
Expand Down
2 changes: 1 addition & 1 deletion plugin/__tests__/stylesheet.spec.js
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 '../index'

pluginTester({
plugin,
Expand Down
4 changes: 2 additions & 2 deletions plugin/__tests__/userImports.spec.js
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 '../index'

pluginTester({
plugin,
Expand Down Expand Up @@ -101,6 +101,6 @@ pluginTester({
467105739
)
`
},
}
]
})
5 changes: 2 additions & 3 deletions plugin/__tests__/variants.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { pluginTester } from 'babel-plugin-tester'
import { Text } from 'react-native'
import plugin from '../'
import plugin from '../index'

pluginTester({
plugin,
Expand Down Expand Up @@ -217,6 +216,6 @@ pluginTester({
const styles = StyleSheet.create({}, 895830154)
`
},
}
]
})
15 changes: 15 additions & 0 deletions plugin/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const esbuild = require('esbuild');

// TODO: add yarn tsc &&
esbuild.build({
entryPoints: ['./plugin/src/index.ts'],
outfile: './plugin/index.js',
bundle: true,
packages: 'external',
external: ['../package.json'],
allowOverwrite: true,
logLevel: 'warning',
platform: 'node',
sourcemap: 'linked',
minify: true,
});
2 changes: 2 additions & 0 deletions plugin/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions plugin/index.js.map

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions plugin/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { RemapConfig } from "./types"

export const REACT_NATIVE_COMPONENT_NAMES = [
'ActivityIndicator',
'View',
Expand All @@ -20,26 +22,25 @@ export const REACT_NATIVE_COMPONENT_NAMES = [
// TouchableWithoutFeedback - can't accept a ref
]

// auto replace RN imports to Unistyles imports under these paths
// our implementation simply borrows 'ref' to register it in ShadowRegistry
// so we won't affect anyone's implementation
/**
* auto replace RN imports to Unistyles imports under these paths
* our implementation simply borrows 'ref' to register it in ShadowRegistry
* so we won't affect anyone's implementation
*/
export const REPLACE_WITH_UNISTYLES_PATHS = [
'react-native-reanimated/src/component',
'react-native-gesture-handler/src/components'
]

// this is more powerful API as it allows to convert unmatched imports to Unistyles
// { path: string, imports: Array<{ name: string, isDefault: boolean, path: string, mapTo: string }> }
// path => node_modules path
// imports:
// name? <- target import name if isDefault is false
// isDefault <- is the import default?
// path <- path to the target import
// mapTo <- name of the Unistyles component
export const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = []
/**
* A more powerful API that allows converting unmatched imports to Unistyles.
*/
export const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS: Array<RemapConfig> = []

// this list will additionally detect React Native direct imports
export const NATIVE_COMPONENTS_PATHS = {
/**
* This list will additionally detect React Native direct imports
*/
export const NATIVE_COMPONENTS_PATHS: Pick<RemapConfig, 'imports'> = {
imports: [
{
name: 'NativeText',
Expand Down
Loading

0 comments on commit b5ebe50

Please sign in to comment.