Skip to content

Commit

Permalink
feat(deps): react native 78 support
Browse files Browse the repository at this point in the history
  • Loading branch information
crherman7 committed Feb 20, 2025
1 parent 6def480 commit d3f36d2
Show file tree
Hide file tree
Showing 47 changed files with 1,722 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {parse} from '@babel/parser';
import traverse from '@babel/traverse';
import {glob} from 'glob';
import {findConfigFile} from 'typescript';
import {BuildConfig, CodeConfig} from '@brandingbrand/code-cli-kit';
import {BuildConfig, CodeConfig, logger} from '@brandingbrand/code-cli-kit';

import {bundleRequire} from './lib';

Expand Down Expand Up @@ -72,6 +72,9 @@ export async function findBuildConfigFiles(
const pattern = path.join(rootDir, '**/build.*.ts');
try {
const files = await glob(pattern, {ignore: ['**/node_modules/**']});
logger.log(
`Found ${files.length} build configurations: ${files.join(', ')}`,
);

const buildFile = files.find(filePath => {
const fileName = path.basename(filePath);
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ const RN_PROFILE_CHOICES = [
'0.74',
'0.75',
'0.76',
'0,77',
'0.77',
'0.78',
] as const;

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-transform-template/src/transformers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ export const transformers = [
use: plistTransformer,
},
{
test: /\b\colors.xml$/,
test: /\bcolors.xml$/,
use: colorsXmlTransformer,
},
{
test: /\b\AndroidManifest.xml$/,
test: /\bAndroidManifest.xml$/,
use: manifestXmlTransformer,
},
{
test: /\b\network_security_config.xml.xml$/,
test: /\bnetwork_security_config.xml.xml$/,
use: networkSecurityConfigXmlTransformer,
},
{
test: /\b\strings.xml$/,
test: /\bstrings.xml$/,
use: stringsXmlTransformer,
},
{
test: /\b\styles.xml$/,
test: /\bstyles.xml$/,
use: stylesXmlTransformer,
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/// <reference types="@brandingbrand/code-cli-kit/types"/>

import type {XcodeProject, PBXFile} from 'xcode';

import {default as projectPbxproj073} from '../../0.73/ios/project-pbxproj';

export default {
...projectPbxproj073,
addFileReferences: (project: XcodeProject): void => {
const targetKey = project.findTargetKey('app');

if (!targetKey) {
throw Error(`[PbxprojTransformerError]: cannot find target "app" uuid`);
}

const opt = {target: targetKey};

const groupKey = project.findPBXGroupKey({name: 'app'});

if (!groupKey) {
throw Error(`[PbxprojTransformerError]: cannot find group "app" uuid`);
}

// These files exist as extras and need to be added to pbxproj file as
// source files or header files
project.addSourceFile('app/EnvSwitcher.m', opt, groupKey);
project.addSourceFile('app/NativeConstants.m', opt, groupKey);

// PrivacyInfo.xcprivacy is already included in the React Native 0.73 template from
// https://github.com/facebook/react-native/blob/v0.73.9/packages/react-native/template/ios/HelloWorld/PrivacyInfo.xcprivacy

// *.entitlements file can be treated same as a header file with
// respect to "xcode" module, force lastKnownFileType and defaultEncoding
// as this is not a detectble filetype by PBXFile.
// https://github.com/apache/cordova-node-xcode/blob/e594cd453e8f26d8916e4be7bdfb309b8e820e2f/lib/pbxFile.js#L27
project.addHeaderFile(
'app/app.entitlements',
{
...opt,
lastKnownFileType: 'text.plist.entitlements',
defaultEncoding: 4,
},
groupKey,
) as PBXFile;

// Required build setting when adding entitlements
project.addToBuildSettings(
'CODE_SIGN_ENTITLEMENTS',
'app/app.entitlements',
);
},
};
11 changes: 7 additions & 4 deletions packages/plugin-verify-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default definePlugin({
* @returns {Promise<void>} A Promise representing the completion of dependency verification
* @throws {Error} If dependency verification encounters critical errors
*/
common: async (_, options: PrebuildOptions): Promise<void> => {
common: async (_: any, options: PrebuildOptions): Promise<void> => {
// Select the profile based on the React Native version
const rnProfile = profile;

Expand All @@ -90,10 +90,13 @@ export default definePlugin({
* @throws {Error} If dependency checking encounters critical errors
*/
const checkDependencies = async (dependencies: Record<string, any>) => {
const rootPackageJson = await getPackageJson(
path.project.resolve('package.json'),
);
const rootPackageJson = await getPackageJson(path.project.resolve());
const rootDeps = {
...rootPackageJson?.dependencies,
...rootPackageJson?.devDependencies,
};
for (const [packageName, config] of Object.entries(dependencies)) {
if (!rootDeps[packageName]) continue;
try {
const installedVersion = (await getPackageJson(packageName))?.version;

Expand Down
74 changes: 74 additions & 0 deletions packages/plugin-verify-dependencies/src/profile/0.78.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Imports the base profile configuration from version 0.77
* @see ./0.77
*/
import {default as profile077} from './0.77';

/**
* Default export containing dependency specifications and configurations
* @exports {Object} Configuration object extending profile077
* @see profile077
*/
export default {
...profile077,
/**
* React Native core package configuration
* @property {string} version - The semantic version requirement
* @property {string[]} capabilities - Required companion packages
* @property {boolean} required - Indicates this is a required dependency
* @see {@link https://reactnative.dev/}
*/
'react-native': {
version: '^0.78.0',
capabilities: [
'react',
'@react-native/babel-preset',
'@react-native/metro-config',
],
required: true,
},
/**
* React Native Babel preset configuration
* @property {string} version - The semantic version requirement
* @property {string[]} capabilities - Required Babel dependencies
* @property {boolean} devOnly - Indicates this is a development-only dependency
* @see {@link https://github.com/facebook/react-native/tree/main/packages/babel-preset-react-native}
*/
'@react-native/babel-preset': {
version: '^0.78.0',
capabilities: ['@babel/core', '@babel/preset-env', '@babel/runtime'],
devOnly: true,
},
/**
* React Native Metro bundler configuration
* @property {string} version - The semantic version requirement
* @property {boolean} devOnly - Indicates this is a development-only dependency
* @see {@link https://facebook.github.io/metro/}
*/
'@react-native/metro-config': {
version: '^0.78.0',
devOnly: true,
},
/**
* React core library configuration
* @property {string} version - The semantic version requirement
* @property {string[]} capabilities - Required type definitions
* @property {boolean} required - Indicates this is a required dependency
* @see {@link https://reactjs.org/}
*/
react: {
version: '19.0.0',
capabilities: ['@types/react'],
required: true,
},
/**
* TypeScript definitions for React
* @property {string} version - The semantic version requirement
* @property {boolean} devOnly - Indicates this is a development-only dependency
* @see {@link https://www.npmjs.com/package/@types/react}
*/
'@types/react': {
version: '^19.0.0',
devOnly: true,
},
};
119 changes: 119 additions & 0 deletions packages/templates/react-native/0.78/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
apply plugin: "com.android.application"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
/* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '../..'
// root = file("../../")
// The folder where the react-native NPM package is. Default is ../../node_modules/react-native
// reactNativeDir = file("../../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../../node_modules/@react-native/codegen
// codegenDir = file("../../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../../node_modules/react-native/cli.js
// cliFile = file("../../node_modules/react-native/cli.js")

/* Variants */
// The list of variants to that are debuggable. For those we're going to
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
// debuggableVariants = ["liteDebug", "prodDebug"]

/* Bundling */
// A list containing the node command and its flags. Default is just 'node'.
// nodeExecutableAndArgs = ["node"]
//
// The command to run when bundling. By default is 'bundle'
// bundleCommand = "ram-bundle"
//
// The path to the CLI configuration file. Default is empty.
// bundleConfig = file(../rn-cli.config.js)
//
// The name of the generated asset file containing your JS bundle
// bundleAssetName = "MyApplication.android.bundle"
//
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
// entryFile = file("../js/MyApplication.android.js")
//
// A list of extra flags to pass to the 'bundle' commands.
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
// extraPackagerArgs = []

/* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc'
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
//
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]

/* Autolinking */
autolinkLibrariesWithApp()
}

/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
def enableProguardInReleaseBuilds = false

/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'

android {
ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdk rootProject.ext.compileSdkVersion

namespace "com.app"
defaultConfig {
applicationId "com.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}

dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")

if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Loading

0 comments on commit d3f36d2

Please sign in to comment.