Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e151563
chore: initial commit - remove files
grabbou Jan 27, 2022
0ae9eea
chore: further removal
grabbou Jan 27, 2022
30103d3
chore: wip
grabbou Jan 27, 2022
6c53e48
continue work
grabbou Jan 28, 2022
596d849
chore: fix warnings and errors
grabbou Jan 28, 2022
8a24cd2
chore: move findXcodeProj to config and upgrade run-ios
grabbou Feb 2, 2022
a1fe895
chore: add todo
grabbou Feb 2, 2022
2f8baf8
chore: remove example
grabbou Feb 2, 2022
510a903
chore: update source dir and update dependnecy config for ios
grabbou Feb 2, 2022
2a43345
chore: remove logger
grabbou Feb 2, 2022
410ec1a
chore: fix type issues
grabbou Feb 2, 2022
b3e0730
chore: remove tests for missing properties, prefer snapshots instead …
grabbou Feb 2, 2022
16996b3
chore: update snapshots for iOS config (removed properties)
grabbou Feb 2, 2022
a67a5a6
chore: fix upgrade tests
grabbou Feb 2, 2022
65f4335
chore: remove extra tests
grabbou Feb 2, 2022
edf3175
chore: update config tests
grabbou Feb 2, 2022
3854ee3
chore: two tests tbd to support new resolution mechanism
grabbou Feb 2, 2022
f8a9ade
chore: fix ios tests and bring back configurable sourceDir
grabbou Feb 2, 2022
1c9508e
feat: align findPodfilePath with old findProject heuristics
grabbou Feb 2, 2022
be963e1
chore: fix lint
grabbou Feb 2, 2022
194ee75
chore: update snapshot
grabbou Feb 2, 2022
387f9ee
fix: filter invalid deps
grabbou Feb 2, 2022
299285f
chore: update tests
grabbou Feb 2, 2022
d665720
chore: add missing properties to Joi schema
grabbou Feb 2, 2022
020aa16
chore: another update
grabbou Feb 2, 2022
0153690
chore: fix Joi schema
grabbou Feb 2, 2022
f8fd19d
chore: update schema
grabbou Feb 2, 2022
de1a5d2
chore: fix snapshot
grabbou Feb 2, 2022
2c732a8
chore: note on the future development for this file
grabbou Feb 2, 2022
6051201
chore: update snapshot one more time - nitpick
grabbou Feb 2, 2022
361f0c9
one last time
grabbou Feb 2, 2022
64b4ef7
feat: print when multiple podfiles are found
grabbou Feb 3, 2022
00ccd36
update docs
grabbou Feb 3, 2022
59cb6e0
chore: fix
grabbou Feb 3, 2022
9e70eb3
Update autolinking.md
grabbou Feb 4, 2022
48686a9
chore: remove xmldoc dep
thymikee Feb 4, 2022
7326892
chore: remove xcode dep
thymikee Feb 4, 2022
794d9b3
chore: return type for dependencyConfig
thymikee Feb 4, 2022
ae7c66e
Merge branch 'master' into feat/remove-link
grabbou Feb 7, 2022
3e5cb0b
Update index.ts
grabbou Feb 7, 2022
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
Prev Previous commit
Next Next commit
continue work
  • Loading branch information
grabbou committed Jan 28, 2022
commit 6c53e48c036f803fad7e4964f19f59f0cd5bc3b0
2 changes: 1 addition & 1 deletion docs/platforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
};
```

On Android and iOS, this function returns:
On Android and iOS, this function returns a dependency configuration for:

```ts
type IOSDependencyConfig = {
Expand Down
7 changes: 2 additions & 5 deletions packages/cli-hermes/src/profileHermes/downloadProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import path from 'path';
import os from 'os';
import transformer from 'hermes-profile-transformer';
import {findSourcemap, generateSourcemap} from './sourcemapUtils';
import {
getAndroidProject,
getPackageName,
} from '@react-native-community/cli-platform-android';
import {getAndroidProject} from '@react-native-community/cli-platform-android';
/**
* Get the last modified hermes profile
* @param packageNameWithSuffix
Expand Down Expand Up @@ -54,7 +51,7 @@ export async function downloadProfile(
try {
const androidProject = getAndroidProject(ctx);
const packageNameWithSuffix = [
appId || getPackageName(androidProject),
appId || androidProject.packageName,
appIdSuffix,
]
.filter(Boolean)
Expand Down
1 change: 1 addition & 0 deletions packages/cli-types/src/android.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface AndroidProjectConfig {
sourceDir: string;
appName: string;
packageName: string;
dependencyConfiguration?: string;
}
Expand Down
11 changes: 7 additions & 4 deletions packages/cli-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,20 @@ type IOSPlatformConfig = PlatformConfig<
>;

export type ProjectConfig = {
android?: ReturnType<AndroidPlatformConfig['projectConfig']>;
ios?: ReturnType<IOSPlatformConfig['projectConfig']>;
android?: Exclude<ReturnType<AndroidPlatformConfig['projectConfig']>, void>;
ios?: Exclude<ReturnType<IOSPlatformConfig['projectConfig']>, void>;
[key: string]: any;
};

export interface DependencyConfig {
name: string;
root: string;
platforms: {
android?: ReturnType<AndroidPlatformConfig['dependencyConfig']>;
ios?: ReturnType<IOSPlatformConfig['dependencyConfig']>;
android?: Exclude<
ReturnType<AndroidPlatformConfig['dependencyConfig']>,
void
>;
ios?: Exclude<ReturnType<IOSPlatformConfig['dependencyConfig']>, void>;
[key: string]: any;
};
}
Expand Down
32 changes: 12 additions & 20 deletions packages/platform-android/src/commands/runAndroid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import {
getDefaultUserTerminal,
CLIError,
} from '@react-native-community/cli-tools';
import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs';
import {getAndroidProject, getPackageName} from '../../utils/getAndroidProject';
import {getAndroidProject} from '../../config/getAndroidProject';

function displayWarnings(config: Config, args: Flags) {
warnAboutManuallyLinkedLibs(config);
function displayWarnings(args: Flags) {
if (args.appFolder) {
logger.warn(
'Using deprecated "--appFolder" flag. Use "project.android.appName" in react-native.config.js instead.',
Expand Down Expand Up @@ -60,7 +58,7 @@ type AndroidProject = NonNullable<Config['project']['android']>;
* Starts the app on a connected Android emulator or device.
*/
async function runAndroid(_argv: Array<string>, config: Config, args: Flags) {
displayWarnings(config, args);
displayWarnings(args);
const androidProject = getAndroidProject(config);

if (args.jetifier) {
Expand Down Expand Up @@ -112,21 +110,17 @@ function buildAndRun(args: Flags, androidProject: AndroidProject) {
process.chdir(androidProject.sourceDir);
const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';

const {appFolder} = args;
const packageName = getPackageName(androidProject, appFolder);

const adbPath = getAdbPath();
if (args.deviceId) {
return runOnSpecificDevice(args, cmd, packageName, adbPath, androidProject);
return runOnSpecificDevice(args, cmd, adbPath, androidProject);
} else {
return runOnAllDevices(args, cmd, packageName, adbPath, androidProject);
return runOnAllDevices(args, cmd, adbPath, androidProject);
}
}

function runOnSpecificDevice(
args: Flags,
gradlew: 'gradlew.bat' | './gradlew',
packageName: string,
adbPath: string,
androidProject: AndroidProject,
) {
Expand All @@ -135,13 +129,7 @@ function runOnSpecificDevice(
if (devices.length > 0 && deviceId) {
if (devices.indexOf(deviceId) !== -1) {
buildApk(gradlew, androidProject.sourceDir);
installAndLaunchOnDevice(
args,
deviceId,
packageName,
adbPath,
androidProject,
);
installAndLaunchOnDevice(args, deviceId, adbPath, androidProject);
} else {
logger.error(
`Could not find device with the id: "${deviceId}". Please choose one of the following:`,
Expand Down Expand Up @@ -226,13 +214,17 @@ function getInstallApkName(
function installAndLaunchOnDevice(
args: Flags,
selectedDevice: string,
packageName: string,
adbPath: string,
androidProject: AndroidProject,
) {
tryRunAdbReverse(args.port, selectedDevice);
tryInstallAppOnDevice(args, adbPath, selectedDevice, androidProject);
tryLaunchAppOnDevice(selectedDevice, packageName, adbPath, args);
tryLaunchAppOnDevice(
selectedDevice,
androidProject.packageName,
adbPath,
args,
);
}

function startServerInNewWindow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type AndroidProject = NonNullable<Config['project']['android']>;
async function runOnAllDevices(
args: Flags,
cmd: string,
packageName: string,
adbPath: string,
androidProject: AndroidProject,
) {
Expand Down Expand Up @@ -98,7 +97,7 @@ async function runOnAllDevices(
(devices.length > 0 ? devices : [undefined]).forEach(
(device: string | void) => {
tryRunAdbReverse(args.port, device);
tryLaunchAppOnDevice(device, packageName, adbPath, args);
tryLaunchAppOnDevice(device, androidProject.packageName, adbPath, args);
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// @todo

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Config, AndroidProjectConfig} from '@react-native-community/cli-types';
import {Config} from '@react-native-community/cli-types';
import {logger, CLIError} from '@react-native-community/cli-tools';
import fs from 'fs';
import chalk from 'chalk';
Expand All @@ -20,18 +20,14 @@ export function getAndroidProject(config: Config) {
* Get the package name of the running React Native app
* @param config
*/
export function getPackageName(
androidProject: AndroidProjectConfig,
appFolder?: string,
) {
const {appName, manifestPath} = androidProject;
export function getPackageName(manifestPath: string) {
const androidManifest = fs.readFileSync(manifestPath, 'utf8');

let packageNameMatchArray = androidManifest.match(/package="(.+?)"/);
if (!packageNameMatchArray || packageNameMatchArray.length === 0) {
throw new CLIError(
`Failed to build the app: No package name found. Found errors in ${chalk.underline.dim(
`${appFolder || appName}/src/main/AndroidManifest.xml`,
`${manifestPath}`,
)}`,
);
}
Expand Down
13 changes: 4 additions & 9 deletions packages/platform-android/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import fs from 'fs';
import findAndroidDir from './findAndroidDir';
import findManifest from './findManifest';
import findPackageClassName from './findPackageClassName';
import readManifest from './readManifest';
import {
AndroidProjectParams,
AndroidDependencyParams,
AndroidProjectConfig,
} from '@react-native-community/cli-types';
import {XmlDocument} from 'xmldoc';

const getPackageName = (manifest: XmlDocument) => manifest.attr.package;
import {getPackageName} from './getAndroidProject';

/**
* Gets android project config by analyzing given folder and taking some
Expand All @@ -46,16 +43,15 @@ export function projectConfig(
return null;
}

const manifest = readManifest(manifestPath);

const packageName = userConfig.packageName || getPackageName(manifest);
const packageName = userConfig.packageName || getPackageName(manifestPath);

if (!packageName) {
throw new Error(`Package name not found in ${manifestPath}`);
}

return {
sourceDir,
appName,
packageName,
dependencyConfiguration: userConfig.dependencyConfiguration,
};
Expand Down Expand Up @@ -97,8 +93,7 @@ export function dependencyConfig(
return null;
}

const manifest = readManifest(manifestPath);
const packageName = userConfig.packageName || getPackageName(manifest);
const packageName = userConfig.packageName || getPackageName(manifestPath);
const packageClassName = findPackageClassName(sourceDir);

/**
Expand Down
21 changes: 0 additions & 21 deletions packages/platform-android/src/config/readManifest.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/platform-android/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

export {default as commands} from './commands';
export {projectConfig, dependencyConfig} from './config';
export {getAndroidProject, getPackageName} from './utils/getAndroidProject';
export {getAndroidProject, getPackageName} from './config/getAndroidProject';
7 changes: 1 addition & 6 deletions packages/platform-ios/src/commands/runIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import findXcodeProject, {ProjectInfo} from './findXcodeProject';
import parseIOSDevicesList from './parseIOSDevicesList';
import parseXctraceIOSDevicesList from './parseXctraceIOSDevicesList';
import findMatchingSimulator from './findMatchingSimulator';
import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs';
import warnAboutPodInstall from '../../link/warnAboutPodInstall';
import {
logger,
CLIError,
Expand All @@ -43,16 +41,13 @@ type FlagsT = {
terminal: string | undefined;
};

function runIOS(_: Array<string>, ctx: Config, args: FlagsT) {
function runIOS(_: Array<string>, _ctx: Config, args: FlagsT) {
if (!fs.existsSync(args.projectPath)) {
throw new CLIError(
'iOS project folder not found. Are you sure this is a React Native project?',
);
}

warnAboutManuallyLinkedLibs(ctx);
warnAboutPodInstall(ctx);

process.chdir(args.projectPath);

const xcodeProject = findXcodeProject(fs.readdirSync('.'));
Expand Down