Skip to content
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

CLI supports ordering of tasks #44301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
// overriding the JS config from @react-native/eslint-config to ensure
// that we use hermes-eslint for all js files
{
files: ['*.js', '*.js.flow'],
files: ['*.js', '*.js.flow', '*.jsx'],
parser: 'hermes-eslint',
rules: {
// These rules are not required with hermes-eslint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type StartCommandArgs = {
https?: boolean,
maxWorkers?: number,
key?: string,
platforms?: string[],
platforms: string[],
port?: number,
resetCache?: boolean,
sourceExts?: string[],
Expand Down
10 changes: 5 additions & 5 deletions packages/core-cli-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"name": "@react-native/core-cli-utils",
"version": "0.75.0-main",
"description": "React Native CLI library for Frameworks to build on",
"main": "./src/index.js",
"main": "./src/index.flow.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/react-native.git",
"directory": "packages/core-cli-utils"
},
"exports": {
".": "./src/index.js",
".": "./src/index.flow.js",
"./package.json": "./package.json",
"./version.js": "./src/public/version.js"
},
"types": "./dist/index.d.ts",
"types": "./dist/index.flow.d.ts",
"homepage": "https://github.com/facebook/react-native/tree/HEAD/packages/core-cli-utils#readme",
"keywords": [
"cli-utils",
Expand All @@ -25,8 +25,8 @@
"node": ">=18"
},
"files": [
"dist"
"src"
],
"dependencies": {},
"devDependencies": {}
}
}
34 changes: 0 additions & 34 deletions packages/core-cli-utils/src/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions packages/core-cli-utils/src/monorepo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall react_native
*/

// Should only used when called in the monorepo when we don't want to use the `yarn run build`
// step to transpile to project. When used as a vanilla npm package, it should be built and
// exported with `dist/index.flow.js` as main.
//
// The reason for this workaround is that flow-api-translator can't understand ESM and CJS style
// exports in the same file. Throw in a bit of Flow in the mix and it all goes to hell.
//
// See packages/helloworld/cli.js for an example of how to swap this out in the monorepo.
if (process.env.BUILD_EXCLUDE_BABEL_REGISTER == null) {
require('../../../scripts/build/babel-register').registerForMonorepo();
}

module.exports = require('./index.flow.js');
6 changes: 1 addition & 5 deletions packages/core-cli-utils/src/private/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ type AndroidBuild = {
gradleArgs?: Array<string>,
};

async function gradle(
cwd: string,
...args: string[]
): ReturnType<typeof execa> {
function gradle(cwd: string, ...args: string[]): ExecaPromise {
const gradlew = isWindows ? 'gradlew.bat' : './gradlew';
// $FlowFixMe[incompatible-return] Mismatch between flow and TypeScript types
return execa(gradlew, args, {
cwd,
stdio: 'inherit',
Expand Down
1 change: 1 addition & 0 deletions packages/core-cli-utils/src/private/apple.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type AppleInstallApp = {
// `xcrun simctl list devices`
device: string,
appPath: string,
bundleId: string,
...AppleOptions,
};

Expand Down
1 change: 1 addition & 0 deletions packages/core-cli-utils/src/private/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type PathCheckResult = {
export function isOnPath(dep: string, description: string): PathCheckResult {
const cmd = isWindows ? ['where', [dep]] : ['command', ['-v', dep]];
try {
const args = isWindows ? ['where', [dep]] : ['command', ['-v', dep]];
return {
dep,
description,
Expand Down
23 changes: 2 additions & 21 deletions packages/helloworld/.gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
Expand All @@ -23,7 +21,6 @@ DerivedData
**/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
Expand All @@ -35,36 +32,20 @@ local.properties
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
/vendor/bundle/
ios/Pods/
vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# Yarn
.yarn/*
!.yarn/patches
Expand Down
File renamed without changes.
24 changes: 0 additions & 24 deletions packages/helloworld/__tests__/App.test.tsx

This file was deleted.

69 changes: 69 additions & 0 deletions packages/helloworld/__tests__/cli-skip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

// TODO(T187224491): js1 jest doesn't install the correct commander, instead
// using the one in xplat/js/node_modules/commander which is much older.
// Either roll back to that version or upgrade.
import cli from '../cli.flow.js';
import fs from 'fs';

describe('cli.js', () => {
let pkgJson = {
name: 'helloworld-mock',
dependencies: {
'react-native': '0.0.0',
},
devDependencies: {
listr: '^1.2.3',
'some-dev-dep': '1.0.0',
},
};
beforeEach(() => {
jest.resetAllMocks();
});
describe('set-version', () => {
it('without arguments this should not modify the package.json', () => {
const snapshot = JSON.stringify(pkgJson, null, 2);
jest.spyOn(fs, 'readFileSync').mockReturnValue(snapshot);
const spy = jest.spyOn(fs, 'writeFileSync');

cli.parse(['set-version'], {from: 'user'});

expect(spy.mock.lastCall[1]).toEqual(snapshot);
});

it('modified and adds dependencies', () => {
const snapshot = JSON.stringify(pkgJson, null, 2);
jest.spyOn(fs, 'readFileSync').mockReturnValue(snapshot);
const spy = jest.spyOn(fs, 'writeFileSync');

cli.parse(
[
'set-version',
'react-native@^0.1.1',
'foobar@file:/woot/berry',
'some-dev-dep@*',
],
{from: 'user'},
);
const updated = JSON.parse(spy.mock.lastCall[1]);
expect(updated).toMatchObject({
dependencies: {
'react-native': '^0.1.1',
foobar: 'file:/woot/berry',
},
devDependencies: {
'some-dev-dep': '*',
},
});
});
});
});
2 changes: 1 addition & 1 deletion packages/helloworld/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ dependencies {
}

// TODO: This needs to use the new autolinking code in the gradle-plugin instead
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
// apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
41 changes: 6 additions & 35 deletions packages/helloworld/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
# Project-wide Gradle settings.
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
org.gradle.parallel=true
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
# TODO: Do we want to limit the architectures we test on?
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
reactNativeArchitectures=arm64-v8a
newArchEnabled=true

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true
5 changes: 2 additions & 3 deletions packages/helloworld/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

rootProject.name = 'HelloWorld'
// TODO: Use the new autolinking feature in the gradle plugin (not that it's necessary as we don't have any native extensions here. Maybe we should have?)
// apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../../../../react-native-gradle-plugin')
// Autolinking has now moved into the React Native Gradle Plugin
includeBuild('../../react-native-gradle-plugin')
4 changes: 0 additions & 4 deletions packages/helloworld/app.json

This file was deleted.