Skip to content

Commit 5fde8bf

Browse files
committed
fix(template): update to React Native 0.75 and improve Bun compatibility
release-npm
1 parent d71735f commit 5fde8bf

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Starting point for creating React Native plugins in TypeScript without native co
1212
## Usage
1313

1414
```
15-
bun create react-native-plugin react-native-my-plugin
15+
bun --bun create react-native-plugin react-native-my-plugin
1616
npm init -y react-native-plugin@latest react-native-my-plugin / npx create-react-native-plugin@latest react-native-my-plugin
1717
```
1818

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ console.log(`😃 Created new plugin called ${name.regular} in ${destinationDire
6666
console.log('🛠️ Start coding in the file ./index.tsx.')
6767
console.log('🛠️ To preview the plugin edit app/App.tsx and create a RN installation with:')
6868
console.log(`🐚 cd ${name.regular}`)
69-
console.log('🐚 npm run app')
69+
console.log('🐚 npm run app / bun app:bun')

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"change-case": "^5.4.4"
1313
},
1414
"devDependencies": {
15-
"@biomejs/biome": "^1.8.1",
16-
"zero-configuration": "^0.12.0"
15+
"@biomejs/biome": "^1.8.3",
16+
"zero-configuration": "^0.17.2"
1717
},
1818
"trustedDependencies": [
1919
"zero-configuration"

template/create-app.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { copyFileSync, renameSync, rmSync } from 'fs'
2-
import { join } from 'path'
31
import { execSync } from 'child_process'
2+
import { copyFileSync, cpSync, readFileSync, renameSync, rmSync } from 'fs'
3+
import { join, resolve } from 'path'
4+
import Arborist from '@npmcli/arborist'
5+
import packlist from 'npm-packlist'
46

57
// This script enhances source files inside /app with a fresh React Native template.
68
const appName = '<%= pascal %>App'
79
const isBun = typeof Bun !== 'undefined'
810

911
console.log('⌛ Initializing a fresh RN project...')
1012

11-
execSync(`${isBun ? 'bunx' : 'npx'} react-native init ${appName} --skip-git-init true --install-pods true`, {
13+
execSync(`${isBun ? 'bunx' : 'npx'} @react-native-community/cli init ${appName} --skip-git-init true --install-pods true`, {
1214
// Write output to cnosole.
1315
stdio: 'inherit',
1416
})
@@ -24,17 +26,24 @@ execSync(`${isBun ? 'bun' : 'npm'} run build`, {
2426
stdio: 'inherit',
2527
})
2628

27-
// Install this package locally, avoiding symlinks.
28-
execSync('npm install $(npm pack .. | tail -1)', {
29-
cwd: join(process.cwd(), 'app'),
30-
stdio: 'inherit',
31-
})
29+
const packageName = JSON.parse(readFileSync('./package.json')).name
30+
const packageDirectory = resolve(`app/node_modules/${packageName}`)
31+
32+
// Package files and copy them to app node_modules.
33+
// Couldn't get symlinks to work with metro.
34+
const arborist = new Arborist({ path: process.cwd() })
35+
const tree = await arborist.loadActual()
36+
const files = await packlist(tree)
37+
38+
mkdirSync(packageDirectory, { recursive: true })
39+
40+
files.forEach((file) => cpSync(join(process.cwd(), file), join(packageDirectory, file), { recursive: true }))
3241

3342
console.log('')
3443
console.log('🍞 React Native App created inside /app.')
3544
console.log('🛠️ To run the example with the plugin included:')
3645
console.log('🐚 cd app')
37-
console.log('🐚 npm run ios / npm run android')
46+
console.log('🐚 npm run ios / npm run android | bun ios / bun android')
3847
console.log('🌪️ To copy over the changes from the plugin source run:')
39-
console.log('🐚 npm run watch')
48+
console.log('🐚 npm run watch | bun watch')
4049
console.log('🛠️ This will copy changes over to the app.')

template/package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"scripts": {
66
"app": "node create-app.js",
7+
"app:bun": "bun create-app.js",
78
"app:install": "npm i --no-save $(npm pack . | tail -1) --prefix app",
89
"build": "esbuild index.tsx --outdir=dist --bundle --format=esm --sourcemap --external:react-native --external:react",
910
"watch": "npm-run-all --parallel build:watch copy",
@@ -16,27 +17,30 @@
1617
"format": "prettier \"{,!(app|dist)/**/}*.{ts,tsx}\" --write"
1718
},
1819
"devDependencies": {
19-
"@react-native/babel-preset": "^0.74.84",
20-
"@react-native/eslint-config": "^0.74.84",
21-
"@react-native/typescript-config": "^0.74.84",
20+
"@npmcli/arborist": "^7.5.4",
21+
"@react-native-community/cli": "^14.0.0",
22+
"@react-native/babel-preset": "^0.75.1",
23+
"@react-native/eslint-config": "^0.75.1",
24+
"@react-native/typescript-config": "^0.75.1",
2225
"@types/jest": "^29.5.12",
23-
"@types/node": "^20.14.2",
26+
"@types/node": "^22.4.0",
2427
"@types/react": "^18.3.3",
2528
"@types/react-native": "^0.73.0",
2629
"@types/react-test-renderer": "^18.3.0",
2730
"babel-jest": "^29.7.0",
2831
"cpx": "^1.5.0",
29-
"esbuild": "^0.21.5",
32+
"esbuild": "^0.23.1",
3033
"eslint": "8.57.0",
3134
"eslint-plugin-flowtype": "^8.0.3",
32-
"eslint-plugin-prettier": "^5.1.3",
35+
"eslint-plugin-prettier": "^5.2.1",
3336
"jest": "^29.7.0",
37+
"npm-packlist": "^8.0.2",
3438
"npm-run-all": "^4.1.5",
35-
"prettier": "^3.3.2",
39+
"prettier": "^3.3.3",
3640
"react": "^18.3.1",
37-
"react-native": "^0.74.2",
41+
"react-native": "^0.75.1",
3842
"react-test-renderer": "^18.3.1",
39-
"typescript": "^5.4.5"
43+
"typescript": "^5.5.4"
4044
},
4145
"peerDependencies": {
4246
"react": ">= 18",

0 commit comments

Comments
 (0)