Skip to content

Commit

Permalink
chore: Re-structure project to use global ESLint, Prettier and Typesc…
Browse files Browse the repository at this point in the history
…ript configs (#267)

* chore: re-structure eslint, prettier and typescript

* chore: update scripts and deps

* chore(deps): add global typescript dep

* fix: TS

* fix: eslint

* fix: run eslint

* fix: update global bun lint script

* chore: update nitrogen dependency to nitro-modules on release

* fix: builder-bob in lib

* chore: update bun.lockb

* fix: bootstrap script

* chore: update scripts

* fix: builder-bob tsconfig

* chore: add nitrogen prepare script

* fix: postinstall and build scripts

* update release config

* chore: revert version change

* fix: invalid package name

* chore: specs script should not run for all bun workspaces

* chore(deps): update bun.lockb

* chore: move .clang-format file back to root (GH action will fail otherwise)

* fix: missing slash

* fix: specs script

* fix: clang format path

* fix: nitrogen ci

* chore: udpate nitrogen gh workflow

* fix: use bunx in CI instead of bun

* chore(deps): add typescript dev dependency in nitro-image

* Revert "chore(deps): add typescript dev dependency in nitro-image"

This reverts commit b60eab1.

* chore(deps): update bun.lockb

* chore: allow diffing bun.lockb

* Revert "chore(deps): update bun.lockb"

This reverts commit 69d41a5.

* fix: capitalize for consistency

* fix: add ignore files to eslintrc

* chore: add nitro-modules to peerDeps

* chore: simplify example tsconfig

* fix: workspace build

* fix: typescript pipeline

* fix: linting

* chore(deps): update typescript eslint deps

* chore: don't run bootstrap on install

* fix: remove ignorePattern in nitro.json

* Revert "fix: remove ignorePattern in nitro.json"

This reverts commit fe21f0e.

* chore: add path to rn nitro modules in image

* Revert "chore: add path to rn nitro modules in image"

This reverts commit cf6e8fb.

* disable noEmit manuallc

* fix: Podfile.lock

* chore: simplify eslint config

* chore: build packages before running nitro-codegen

* fix: nitrogen workflow build

* trigger workflow

* reverse dummy change

* fix: update example pods during release

* fix: update release hooks

* chore: update bootstrap script

* chore(deps): update bun.lockb

* fix: update nitro-image specs

* fix: revert nitrogen specs changes

* fix: Replace `bunx` with `bun` again

* Update Podfile.lock

* chore: Rename modules to nitro

* Update package.json

* Update run-nitrogen.yml

* chore: Rename `check-all` to `lint-cpp`

---------

Co-authored-by: Marc Rousavy <[email protected]>
  • Loading branch information
chrispader and mrousavy authored Nov 5, 2024
1 parent 38ad53f commit 2cead7f
Show file tree
Hide file tree
Showing 25 changed files with 267 additions and 345 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.lockb binary diff=lockb
4 changes: 3 additions & 1 deletion .github/workflows/lint-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- main
paths:
- '.github/workflows/lint-typescript.yml'
- 'config'
- '**/*.ts'
- '**/*.tsx'
- '**/*.js'
Expand All @@ -21,6 +22,7 @@ on:
pull_request:
paths:
- '.github/workflows/lint-typescript.yml'
- 'config'
- '**/*.ts'
- '**/*.tsx'
- '**/*.js'
Expand All @@ -43,7 +45,7 @@ jobs:

- name: Run TypeScript (tsc)
run: |
bun typescript | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee
bun typecheck | reviewdog -name="tsc" -efm="%f(%l,%c): error TS%n: %m" -reporter="github-pr-review" -filter-mode="nofilter" -fail-on-error -tee
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/run-nitrogen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,12 @@ jobs:
- name: Install npm dependencies (bun)
run: bun install

- name: Install npm dependencies (bun)
working-directory: example
run: bun install
- name: Install npm dependencies (bun)
working-directory: packages/nitrogen
run: bun install
- name: Install npm dependencies (bun)
working-directory: packages/react-native-nitro-modules
run: bun install
- name: Install npm dependencies (bun)
working-directory: packages/react-native-nitro-image
run: bun install
- name: Build all packages
run: bun run build

- name: Run nitro-codegen in packages/react-native-nitro-image
working-directory: packages/react-native-nitro-image
run: bun run nitro-codegen --logLevel="debug"
run: bun i && bun specs-ci

- name: Verify no files have changed after nitrogen
run: git diff --exit-code HEAD -- . ':(exclude)bun.lockb'
Binary file modified bun.lockb
Binary file not shown.
39 changes: 39 additions & 0 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = {
root: true,
extends: ['@react-native', 'plugin:prettier/recommended'],
ignorePatterns: [
'**/node_modules',
'**/lib',
'**/.eslintrc.js',
'**/.prettierrc.js',
'**/jest.config.js',
'**/babel.config.js',
'**/metro.config.js',
'**/react-native.config.js',
'**/tsconfig.json'
],
plugins: ['@typescript-eslint', 'prettier'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'prettier/prettier': [
'warn',
{
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
semi: false,
},
],
},
}
35 changes: 35 additions & 0 deletions config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"exclude": [
"**/node_modules",
"**/lib",
"**/.eslintrc.js",
"**/.prettierrc.js",
"**/jest.config.js",
"**/babel.config.js",
"**/metro.config.js",
"**/tsconfig.json"
],
"compilerOptions": {
"composite": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Node",
"noEmit": false,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": true
}
}
8 changes: 8 additions & 0 deletions example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
root: true,
extends: '../config/.eslintrc.js',
parserOptions: {
tsconfigRootDir: __dirname,
project: true,
},
}
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- hermes-engine (0.75.2):
- hermes-engine/Pre-built (= 0.75.2)
- hermes-engine/Pre-built (0.75.2)
- NitroImage (0.0.3):
- NitroImage (0.14.1):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1827,7 +1827,7 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: 69ef571f3de08433d766d614c73a9838a06bf7eb
hermes-engine: 3b6e0717ca847e2fc90a201e59db36caf04dee88
NitroImage: 601a8f4fa9bf057600cee0b3812c8d72b15d2702
NitroImage: 7e4de4afa145285ce1996a0fe53ae44e8a3fcea4
NitroModules: 4c61905835b80db8a6be65fd5ffe898219e35f9e
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
RCTDeprecation: 34cbf122b623037ea9facad2e92e53434c5c7422
Expand Down
46 changes: 5 additions & 41 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "react-native-nitro-example",
"version": "0.0.1",
"version": "0.14.1",
"private": true,
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"clean": "rm -rf android/build node_modules/**/android/build lib",
"typescript": "tsc --noEmit false",
"typescript": "tsc",
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
"start": "react-native start",
"pods": "cd ios && pod install && rm -rf .xcode.env.local",
"build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"build:ios": "cd ios && xcodebuild -workspace NitroExample.xcworkspace -scheme NitroExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"
Expand All @@ -30,48 +31,11 @@
"@react-native/typescript-config": "^0.75.2",
"@types/deep-equal": "^1.0.4",
"babel-plugin-module-resolver": "^5.0.2",
"eslint-config-prettier": "^9.1.0",
"eslint": "^8.57.0",
"eslint-plugin-prettier": "^5.2.1",
"nitro-codegen": "*",
"prettier": "^3.3.3",
"react-native-nitro-image": "*",
"react-native-nitro-modules": "*",
"typescript": "^5.5.4"
"react-native-nitro-modules": "*"
},
"engines": {
"node": ">=18"
},
"eslintConfig": {
"root": true,
"extends": [
"@react-native",
"prettier"
],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": [
"warn",
{
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
}
]
}
},
"eslintIgnore": [
"node_modules/",
"lib/"
],
"prettier": {
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"semi": false
}
}
1 change: 1 addition & 0 deletions example/src/Testers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { stringify } from './utils'

export type Must = 'equals' | 'throws'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _someType = typeof false
export type JSType = typeof _someType

Expand Down
2 changes: 1 addition & 1 deletion example/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function stringify(value: unknown): string {
if (string !== '[object Object]') return string
}
return `{ ${value} ${Object.keys(value).join(', ')} }`
} catch (e) {
} catch {
// toString() threw - maybe because we accessed it on a prototype.
return `{ [Object] ${Object.keys(value).join(', ')} }`
}
Expand Down
36 changes: 5 additions & 31 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
{
"references": [
{
"path": "../packages/react-native-nitro-modules"
}
],
"include": [
"src"
"extends": [
"@tsconfig/react-native/tsconfig.json",
"../config/tsconfig.json"
],
"include": ["src", "index.js"],
"compilerOptions": {
"composite": true,
"noEmit": true,
"outDir": "lib",
"rootDir": ".",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["esnext"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": true
"jsx": "react"
}
}
57 changes: 47 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,45 @@
"version": "0.14.1",
"repository": "https://github.com/mrousavy/nitro.git",
"author": "Marc Rousavy <[email protected]> (https://github.com/mrousavy)",
"scripts": {
"check-all": "./scripts/clang-format.sh",
"bootstrap": "bun --filter=\"**\" install && bun tsc && bun --filter=\"react-native-nitro-example\" pods",
"typescript": "bun --filter=\"**\" typescript",
"release": "release-it",
"clean": "rm -rf packages/**/tsconfig.tsbuildinfo packages/**/node_modules packages/**/lib"
},
"workspaces": [
"packages/react-native-nitro-modules",
"packages/nitrogen",
"packages/react-native-nitro-image",
"packages/template",
"example",
"docs"
],
"scripts": {
"build": "bun run --cwd packages/react-native-nitro-modules build && bun run --cwd packages/nitrogen build && bun run --cwd packages/react-native-nitro-image build",
"bootstrap": "bun install && bun run build && bun example pods",
"typecheck": "bun --filter=\"**\" typecheck",
"lint": "bun nitro lint && bun nitrogen lint && bun image lint && bun example lint",
"lint-cpp": "./scripts/clang-format.sh",
"clean": "rm -rf packages/**/tsconfig.tsbuildinfo packages/**/node_modules packages/**/lib",
"release": "release-it --workspaces",
"nitro": "bun --cwd packages/react-native-nitro-modules",
"nitrogen": "bun --cwd packages/nitrogen",
"image": "bun --cwd packages/react-native-nitro-image",
"example": "bun --cwd example"
},
"devDependencies": {
"@release-it/conventional-changelog": "^8.0.1",
"@release-it/bumper": "^6.0.1",
"@eslint/js": "^9.10.0",
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
"release-it": "^17.6.0"
"@react-native/eslint-config": "0.75.2",
"@release-it-plugins/workspaces": "^4.2.0",
"@release-it/bumper": "^6.0.1",
"@release-it/conventional-changelog": "^8.0.2",
"@tsconfig/react-native": "^2.0.2",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.13",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"eslint": "8.57.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"release-it": "^17.10.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.13.0"
},
"release-it": {
"npm": {
Expand All @@ -37,7 +57,24 @@
"github": {
"release": true
},
"hooks": {
"before:init": "bun typecheck && bun lint",
"before:bump": "bun example pods",
"after:bump": "bun run build"
},
"plugins": {
"@release-it/bumper": {
"out": [
{
"file": "packages/react-native-nitro-image/package.json",
"path": "version"
},
{
"file": "example/package.json",
"path": "version"
}
]
},
"@release-it/conventional-changelog": {
"preset": {
"name": "conventionalcommits",
Expand Down
11 changes: 11 additions & 0 deletions packages/nitrogen/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
root: true,
extends: "../../config/.eslintrc.js",
parserOptions: {
tsconfigRootDir: __dirname,
project: true,
ecmaFeatures: {
jsx: false,
},
},
};
Loading

0 comments on commit 2cead7f

Please sign in to comment.