Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/Pods/**
**/build/**
**/node_modules/**
packages/react-native/React/I18n/FBXXHashUtils.h
packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/**
packages/react-native/ReactAndroid/src/main/jni/third-party/**
Expand Down
78 changes: 78 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"indentation": {
"spaces": 2
},
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineBreakBetweenDeclarationAttributes": false,
"lineLength": 2000,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"orderedImports": {
"includeConditionalImports": false,
"shouldGroupImports": false
},
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": true,
"reflowMultilineStringLiterals": {
"never": {}
},
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"AvoidRetroactiveConformances": false,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": false,
"FileScopedDeclarationPrivacy": false,
"FullyIndirectEnum": false,
"GroupNumericLiterals": false,
"IdentifiersMustBeASCII": false,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": false,
"NoAssignmentInExpressions": true,
"NoBlockComments": false,
"NoCasesWithOnlyFallthrough": false,
"NoEmptyLinesOpeningClosingBraces": false,
"NoEmptyTrailingClosureParentheses": false,
"NoLabelsInCasePatterns": false,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": false,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": false,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": false,
"OrderedImports": true,
"ReplaceForEachWithForLoop": false,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": false,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": false,
"UseLetInEveryBoundCaseVariable": false,
"UseShorthandTypeNames": false,
"UseSingleLinePropertyGetter": false,
"UseSynthesizedInitializer": false,
"UseTripleSlashForDocumentationComments": false,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"spacesBeforeEndOfLineComments": 1,
"tabWidth": 8,
"version": 1
}
40 changes: 0 additions & 40 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.binary.compatibility.validator) apply true
alias(libs.plugins.android.test) apply false
alias(libs.plugins.ktfmt) apply true
}

val reactAndroidProperties = java.util.Properties()
Expand Down Expand Up @@ -176,42 +175,3 @@ if (hermesSubstitution != null) {
}
}
}

ktfmt {
blockIndent.set(2)
continuationIndent.set(4)
maxWidth.set(100)
removeUnusedImports.set(false)
manageTrailingCommas.set(false)
}

// Configure ktfmt tasks to include gradle-plugin
listOf("ktfmtCheck", "ktfmtFormat").forEach { taskName ->
tasks.named(taskName) { dependsOn(gradle.includedBuild("gradle-plugin").task(":$taskName")) }
}

allprojects {
// Apply exclusions for specific files that should not be formatted
val excludePatterns = listOf(
"**/build/**",
"**/hermes-engine/**",
"**/internal/featureflags/**",
"**/systeminfo/ReactNativeVersion.kt",
)
listOf(
com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask::class,
com.ncorti.ktfmt.gradle.tasks.KtfmtFormatTask::class,
)
.forEach { tasks.withType(it) { exclude(excludePatterns) } }

// Disable the problematic ktfmt script tasks due to symbolic link issues in subprojects
afterEvaluate {
listOf("ktfmtCheckScripts", "ktfmtFormatScripts").forEach {
tasks.findByName(it)?.enabled = false
}
}
}

// We intentionally disable the `ktfmtCheck` tasks as the formatting is primarly handled inside
// fbsource
allprojects { tasks.withType<com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask>() { enabled = false } }
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@
"build-android": "./gradlew :packages:react-native:ReactAndroid:build",
"build": "node ./scripts/build/build.js",
"build-types": "node ./scripts/js-api/build-types",
"clang-format": "node ./scripts/clang-format.js",
"clean": "node ./scripts/build/clean.js",
"cxx-api-build": "python -m scripts.cxx-api.parser",
"cxx-api-validate": "python -m scripts.cxx-api.parser --validate",
"flow-check": "flow full-check",
"flow": "flow",
"format-check": "prettier --list-different \"./**/*.{js,md,yml,ts,tsx}\"",
"format": "npm run prettier && npm run clang-format",
"format-check": "yarn format-check-javascript && yarn format-check-cpp && yarn format-check-kotlin && yarn format-check-java && yarn format-check-python && yarn format-check-swift",
"format-check-cpp": "node ./scripts/clang-format.js --check",
"format-check-java": "node ./scripts/format-java.js --check",
"format-check-javascript": "prettier --check \"./**/*.{cjs,cts,flow,js,jsx,md,mjs,mts,ts,tsx,yaml,yml}\"",
"format-check-kotlin": "node ./scripts/format-kotlin.js --check",
"format-check-python": "node ./scripts/format-python.js --check",
"format-check-swift": "node ./scripts/format-swift.js --check",
"format": "yarn format-javascript && yarn format-cpp && yarn format-kotlin && yarn format-java && yarn format-python && yarn format-swift",
"format-cpp": "node ./scripts/clang-format.js",
"format-java": "node ./scripts/format-java.js",
"format-javascript": "prettier --write \"./**/*.{cjs,cts,flow,js,jsx,md,mjs,mts,ts,tsx,yaml,yml}\"",
"format-kotlin": "node ./scripts/format-kotlin.js",
"format-python": "node ./scripts/format-python.js",
"format-swift": "node ./scripts/format-swift.js",
"featureflags": "yarn --cwd packages/react-native featureflags",
"js-api-diff": "node ./scripts/js-api/diff-api-snapshot",
"lint-kotlin-check": "./gradlew ktfmtCheck",
"lint-kotlin": "./gradlew ktfmtFormat",
"lint-markdown": "markdownlint-cli2 2>&1",
"lint": "eslint --max-warnings 0 .",
"preinstall": "node ./scripts/try-set-hermes-compiler-prebuilt.js",
"prettier": "prettier --write \"./**/*.{js,md,yml,ts,tsx}\"",
"shellcheck": "./.github/workflow-scripts/analyze_scripts.sh",
"start": "yarn --cwd packages/rn-tester start",
"set-version": "node ./scripts/releases/set-version.js",
Expand Down Expand Up @@ -91,6 +99,7 @@
"flow-eslint": "0.331.0",
"flow-parser": "0.331.0",
"flow-transform": "0.331.0",
"google-java-format": "1.4.0",
"ini": "^5.0.0",
"inquirer": "^7.1.0",
"jest": "^29.7.0",
Expand All @@ -99,6 +108,7 @@
"jest-junit": "^16.0.0",
"jest-snapshot": "^29.7.0",
"jsonc-parser": "2.2.1",
"ktfmt": "0.59.0",
"markdownlint-cli2": "^0.17.2",
"markdownlint-rule-relative-links": "^3.0.0",
"memfs": "^4.38.2",
Expand Down
27 changes: 1 addition & 26 deletions packages/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

plugins {
alias(libs.plugins.kotlin.jvm).apply(false)
alias(libs.plugins.ktfmt).apply(true)
}
plugins { alias(libs.plugins.kotlin.jvm).apply(false) }

tasks.register("build") {
dependsOn(
Expand All @@ -27,25 +24,3 @@ tasks.register("clean") {
":shared:clean",
)
}

tasks.named("ktfmtCheck") {
dependsOn(
":react-native-gradle-plugin:ktfmtCheck",
":settings-plugin:ktfmtCheck",
":shared-testutil:ktfmtCheck",
":shared:ktfmtCheck",
)
}

tasks.named("ktfmtFormat") {
dependsOn(
":react-native-gradle-plugin:ktfmtFormat",
":settings-plugin:ktfmtFormat",
":shared-testutil:ktfmtFormat",
":shared:ktfmtFormat",
)
}

// We intentionally disable the `ktfmtCheck` tasks as the formatting is primarly handled inside
// fbsource
allprojects { tasks.withType<com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask>() { enabled = false } }
2 changes: 0 additions & 2 deletions packages/gradle-plugin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ javapoet = "1.13.0"
junit = "4.13.2"
kotlin = "2.2.0"
assertj = "3.25.1"
ktfmt = "0.22.0"

[libraries]
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
Expand All @@ -19,4 +18,3 @@ assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" }
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.ktfmt)
id("java-gradle-plugin")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,42 +200,44 @@ class ReactPlugin : Plugin<Project> {
}

// We create the tasks to produce schema from JS files and generate artifacts from schema.
val generateCodegenArtifactsTask = registerCodegenTasks(
project = project,
rootExtension = rootExtension,
generatedSrcDir = generatedSrcDir,
packageJsonFile = { findPackageJsonFile(project, rootExtension.root) },
schemaTaskName = "generateCodegenSchemaFromJavaScript",
artifactsTaskName = "generateCodegenArtifactsFromSchema",
configureJsRoot = { task, packageJson ->
// We're reading the package.json at configuration time to properly feed
// the `jsRootDir` @Input property of this task & the onlyIf. Therefore, the
// parsePackageJson should be invoked inside this lambda.
val parsedPackageJson = packageJson?.let { JsonUtils.fromPackageJson(it) }
val jsSrcsDirInPackageJson = parsedPackageJson?.codegenConfig?.jsSrcsDir

if (packageJson != null && jsSrcsDirInPackageJson != null) {
task.jsRootDir.set(File(packageJson.parentFile, jsSrcsDirInPackageJson))
} else {
task.jsRootDir.set(localExtension.jsRootDir)
}
},
configureCodegenArtifacts = { task, _ ->
task.codegenJavaPackageName.set(localExtension.codegenJavaPackageName)
task.libraryName.set(localExtension.libraryName)
},
onlyIf = { packageJson ->
// Please note that needsCodegenFromPackageJson is triggering a read of the
// package.json at configuration time as we need to feed the onlyIf condition of this
// task. Therefore, needsCodegenFromPackageJson needs to be invoked inside this
// lambda.
val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(rootExtension.root)
val parsedPackageJson = packageJson?.let { JsonUtils.fromPackageJson(it) }
val includesGeneratedCode =
parsedPackageJson?.codegenConfig?.includesGeneratedCode ?: false
(isLibrary || needsCodegenFromPackageJson) && !includesGeneratedCode
},
)
val generateCodegenArtifactsTask =
registerCodegenTasks(
project = project,
rootExtension = rootExtension,
generatedSrcDir = generatedSrcDir,
packageJsonFile = { findPackageJsonFile(project, rootExtension.root) },
schemaTaskName = "generateCodegenSchemaFromJavaScript",
artifactsTaskName = "generateCodegenArtifactsFromSchema",
configureJsRoot = { task, packageJson ->
// We're reading the package.json at configuration time to properly feed
// the `jsRootDir` @Input property of this task & the onlyIf. Therefore, the
// parsePackageJson should be invoked inside this lambda.
val parsedPackageJson = packageJson?.let { JsonUtils.fromPackageJson(it) }
val jsSrcsDirInPackageJson = parsedPackageJson?.codegenConfig?.jsSrcsDir

if (packageJson != null && jsSrcsDirInPackageJson != null) {
task.jsRootDir.set(File(packageJson.parentFile, jsSrcsDirInPackageJson))
} else {
task.jsRootDir.set(localExtension.jsRootDir)
}
},
configureCodegenArtifacts = { task, _ ->
task.codegenJavaPackageName.set(localExtension.codegenJavaPackageName)
task.libraryName.set(localExtension.libraryName)
},
onlyIf = { packageJson ->
// Please note that needsCodegenFromPackageJson is triggering a read of the
// package.json at configuration time as we need to feed the onlyIf condition of this
// task. Therefore, needsCodegenFromPackageJson needs to be invoked inside this
// lambda.
val needsCodegenFromPackageJson =
project.needsCodegenFromPackageJson(rootExtension.root)
val parsedPackageJson = packageJson?.let { JsonUtils.fromPackageJson(it) }
val includesGeneratedCode =
parsedPackageJson?.codegenConfig?.includesGeneratedCode ?: false
(isLibrary || needsCodegenFromPackageJson) && !includesGeneratedCode
},
)

// We update the android configuration to include the generated sources.
// This is equivalent to this DSL:
Expand Down Expand Up @@ -353,13 +355,14 @@ class ReactPlugin : Plugin<Project> {
project.rootProject.layout.buildDirectory.file("generated/autolinking/autolinking.json")
val pureCxxDependencies =
getPureCxxCodegenDependencies(rootGeneratedAutolinkingFile.get().asFile)
val pureCxxCodegenTasks = configurePureCxxDependenciesCodegen(
project,
extension,
rootExtension,
generatedPureCxxSourceDir,
pureCxxDependencies,
)
val pureCxxCodegenTasks =
configurePureCxxDependenciesCodegen(
project,
extension,
rootExtension,
generatedPureCxxSourceDir,
pureCxxDependencies,
)

// We add a task called generateAutolinkingPackageList to do not clash with the existing task
// called generatePackageList. This can to be renamed once we unlink the rn <-> cli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ abstract class BundleHermesCTask : DefaultTask() {

val reactNativeDir = reactNativeDir.get().asFile
val composeScriptFile = File(reactNativeDir, "scripts/compose-source-maps.js")
val composeSourceMapsCommand = getComposeSourceMapsCommand(
composeScriptFile,
packagerSourceMap,
compilerSourceMap,
outputSourceMap,
)
val composeSourceMapsCommand =
getComposeSourceMapsCommand(
composeScriptFile,
packagerSourceMap,
compilerSourceMap,
outputSourceMap,
)
runCommand(composeSourceMapsCommand)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ internal object AgpConfiguratorUtils {
manifestFile
.takeIf { it.exists() }
?.let { file ->
getPackageNameFromManifest(file)?.let { packageName ->
ext.namespace = packageName
}
getPackageNameFromManifest(file)?.let { packageName -> ext.namespace = packageName }
}
}
}
Expand Down
Loading
Loading