Skip to content

Commit

Permalink
fix(configuration): add more React Native specific configurations
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed Jun 13, 2024
1 parent 0b28856 commit a945e3f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const tailwind = object | File
export const postcss = object | File
export const babel = object | File (JavaScript only)
export const metro = object | 'react-native' | File (JavaScript only)
export const reactNative = object | File
export const vercel = 'spa' | 'SPA' | 'single-page-application' | 'spa-routes' | 'github-silent' | { extends: 'spa', routes: { ... }}
export const license = 'MIT' | 'mit'
export const ignore = true | 'recommended' | 'bundle' | string[]
Expand Down
8 changes: 8 additions & 0 deletions configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as next from './next'
import * as playwright from './playwright'
import * as postcss from './postcss'
import * as prettier from './prettier'
import * as reactNative from './react-native'
import * as rsbuild from './rsbuild'
import * as tailwind from './tailwind'
import * as typescript from './typescript'
Expand Down Expand Up @@ -38,6 +39,8 @@ export type ConfigurationKeys =
| 'postcss'
| 'babel'
| 'metro'
| 'react-native'
| 'reactNative'
| 'vercel'
| 'license'
// Require separate logic, not found in configuraitons below.
Expand Down Expand Up @@ -107,6 +110,11 @@ export const configurations: Configuration[] = [
name: 'metro',
configuration: metro,
},
{
name: 'react-native',
alias: 'reactNative',
configuration: reactNative,
},
{
name: 'vercel',
configuration: vercel,
Expand Down
12 changes: 12 additions & 0 deletions configuration/react-native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { log } from '../log'

export const extension = (path: string) => ({ extends: path })

export function createFile(configuration: object) {
if (typeof configuration !== 'object') {
log('Configuration for "react-native" (app.json) must be an object', 'warning')
return
}

return { name: 'app.json', contents: JSON.stringify(configuration, null, 2) }
}
7 changes: 7 additions & 0 deletions configuration/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export const templates = {
noEmit: true,
},
},
'react-native': {
extends: '@react-native/typescript-config/tsconfig.json',
compilerOptions: {
module: 'NodeNext',
moduleResolution: 'node',
},
},
}

export const extension = (path: string) => ({ extends: path })
Expand Down
2 changes: 2 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test('Adds configuration files for basic file setup.', async () => {
expect(existsSync(join(fixturePath, 'biome.json'))).toBe(true)
expect(existsSync(join(fixturePath, 'vitest.config.ts'))).toBe(true)
expect(existsSync(join(fixturePath, 'cypress.config.ts'))).toBe(true)
expect(existsSync(join(fixturePath, 'app.json'))).toBe(true)
// TODO should not work with TS.
expect(existsSync(join(fixturePath, 'eslint.config.js'))).toBe(true)

Expand Down Expand Up @@ -175,6 +176,7 @@ test("Doesn't add deployment files to gitignore in CI.", async () => {
expect(existsSync(join(fixturePath, 'vercel.json'))).toBe(true)
expect(existsSync(join(fixturePath, 'metro.config.cjs'))).toBe(true)
expect(existsSync(join(fixturePath, '.gitignore'))).toBe(true)
expect(existsSync(join(fixturePath, 'app.json'))).toBe(true)

const gitignoreFile = await Bun.file(join(fixturePath, '.gitignore')).text()

Expand Down
5 changes: 5 additions & 0 deletions test/fixture/file/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ export const vitest = {
}

export const eslint = true

export const reactNative = {
name: "break'a'bit",
displayName: "break'a'bit",
}
6 changes: 5 additions & 1 deletion test/fixture/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"silent": true
}
},
"metro": "react-native"
"metro": "react-native",
"react-native": {
"name": "hairplan",
"displayName": "hairplan"
}
}
}

0 comments on commit a945e3f

Please sign in to comment.