Skip to content

fix: support new react native #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
59 changes: 43 additions & 16 deletions src/lib/react-native-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isValidVersion, isLowVersion } from './validation-utils';
import { fileDoesNotExistOrIsDirectory } from './file-utils';
import chalk from 'chalk';
import * as cli from '../definitions/cli';
import { coerce, compare } from 'semver';

const plist = require('plist');
const g2js = require('gradle-to-js/lib/parser');
Expand Down Expand Up @@ -79,11 +80,12 @@ export function getReactNativeProjectAppVersion(
if (/MARKETING_VERSION/i.test(parsedPlist.CFBundleShortVersionString)) {
try {
const xcodeProjectConfig =
path.resolve(resolvedPlistFile, "../") +
".xcodeproj/project.pbxproj";
path.resolve(resolvedPlistFile, '../') + '.xcodeproj/project.pbxproj';
out.text(
'Using xcodeProjectConfig version, file path "'
.concat(xcodeProjectConfig, '".\n')
'Using xcodeProjectConfig version, file path "'.concat(
xcodeProjectConfig,
'".\n',
),
);
const xcodeContents = fs.readFileSync(xcodeProjectConfig).toString();

Expand All @@ -98,15 +100,10 @@ export function getReactNativeProjectAppVersion(
break; // 因为我们只需要第一个匹配项,所以找到后就可以退出循环
}
out.text(
'Using xcodeProjectConfig version, version "'.concat(
xcodeVersion,
'".\n'
)
'Using xcodeProjectConfig version, version "'.concat(xcodeVersion, '".\n'),
);
parsedPlist.CFBundleShortVersionString = xcodeVersion;
} catch (error) {

}
} catch (error) {}
}
if (isValidVersion(parsedPlist.CFBundleShortVersionString)) {
out.text(
Expand Down Expand Up @@ -288,12 +285,40 @@ export function getReactNativeProjectAppVersion(
// https://github.com/microsoft/appcenter-cli/blob/13495af812558bd952d8aeb9dc01b5be089cd1fc/src/commands/codepush/lib/react-native-utils.ts#L277
function getCliPath(): string {
if (process.platform === 'win32') {
return path.join('node_modules', 'react-native', 'local-cli', 'cli.js');
const reactNativeVersion = coerce(getReactNativeVersion()).version;
const isVersion75OrAbove = compare(reactNativeVersion, '0.75.0') >= 0;
return isVersion75OrAbove
? path.join(getReactNativePackagePath(), 'cli.js')
: path.join(getReactNativePackagePath(), 'local-cli', 'cli.js');
}

return path.join('node_modules', '.bin', 'react-native');
}

function directoryExistsSync(dirname: string): boolean {
try {
return fs.statSync(dirname).isDirectory();
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
return false;
}

function getReactNativePackagePath(): string {
const result = childProcess.spawnSync('node', [
'--print',
"require.resolve('react-native/package.json')",
]);
const packagePath = path.dirname(result.stdout.toString());
if (result.status === 0 && directoryExistsSync(packagePath)) {
return packagePath;
}

return path.join('node_modules', 'react-native');
}

export function runReactNativeBundleCommand(
bundleName: string,
development: boolean,
Expand Down Expand Up @@ -515,9 +540,11 @@ export async function getHermesEnabled(gradleFile?: string): Promise<boolean> {
let hermesBuildEnabled = false;

// 如果buildGradle["project.ext.react"]是一个数组,则继续处理
if (Array.isArray(buildGradle["project.ext.react"])) {
const reactSettings: string[] = buildGradle["project.ext.react"];
hermesBuildEnabled = reactSettings.some(line => /^enableHermes\s*:\s*true/.test(line));
if (Array.isArray(buildGradle['project.ext.react'])) {
const reactSettings: string[] = buildGradle['project.ext.react'];
hermesBuildEnabled = reactSettings.some((line) =>
/^enableHermes\s*:\s*true/.test(line),
);
}

return hermesPropertyEnabled || hermesBuildEnabled;
Expand Down Expand Up @@ -588,7 +615,7 @@ function getHermesCommand(): string {
'sdks',
'hermesc',
getHermesOSBin(),
getHermesOSExe()
getHermesOSExe(),
);
if (fileExists(hermesEngineNew)) {
return hermesEngineNew;
Expand Down