forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(install-expo-modules): move over from
expo/expo-cli
(expo#…
…25533) # Why Moving the actively used `install-expo-modules` over from `expo/expo-cli`. Counter-part PR: expo/expo-cli#4786 # How - Copied folder from `expo/expo-cli` - Updated `jest.config.js`, `tsconfig.json`, `package.json` - Added changelog - Bumped packages to latest versions - `@expo/config` (`~8.0.0` → `^8.4.0`) - `@expo/config-plugins` (`~6.0.0` → `^7.7.0`) - `@expo/package-manager` (`0.0.56` → `^1.0.3`) - Updates tests: - Replaced `... as jest.Mock<>` → `jest.mocked(...)` - Fixed failing test due to `def min_ios_version_supported` → `def self.min_ios_version_supported` # Test Plan See if CI passes # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin).
- Loading branch information
Showing
93 changed files
with
6,164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
src/**/__tests__/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @generated by expo-module-scripts | ||
module.exports = require('expo-module-scripts/eslintrc.base.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Changelog | ||
|
||
## Unpublished | ||
|
||
### 🛠 Breaking changes | ||
|
||
### 🎉 New features | ||
|
||
### 🐛 Bug fixes | ||
|
||
### 💡 Others | ||
|
||
- Move package from `expo/expo-cli` to `expo/expo`. ([#25533](https://github.com/expo/expo/pull/25533) by [@byCedric](https://github.com/byCedric)) | ||
- Updated `@expo/config` from `~8.0.0` to `^8.4.0`. ([#25533](https://github.com/expo/expo/pull/25533) by [@byCedric](https://github.com/byCedric)) | ||
- Updated `@expo/config-plugins` from `~6.0.0` to `^7.7.0`. ([#25533](https://github.com/expo/expo/pull/25533) by [@byCedric](https://github.com/byCedric)) | ||
- Updated `@expo/package-manager` from `0.0.56` to `^1.0.3`. ([#25533](https://github.com/expo/expo/pull/25533) by [@byCedric](https://github.com/byCedric)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020-present 650 Industries, Inc. (aka Expo) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- Title --> | ||
<h1 align="center"> | ||
👋 Welcome to <br><code>install-expo-modules</code> | ||
</h1> | ||
|
||
<p align="center">A tool for existing React Native projects to adopt <a href="https://docs.expo.dev/versions/latest/">expo-modules and SDK easier</a>.</p> | ||
|
||
<!-- Body --> | ||
|
||
# Usage | ||
|
||
Just to run `install-expo-modules` command in your project: | ||
|
||
```sh | ||
npx install-expo-modules | ||
``` | ||
|
||
After that, you can add other expo-modules you need, e.g. `expo-device`: | ||
|
||
```sh | ||
expo install expo-device | ||
# the expo command is from expo-cli. if you don't have this, run `npm -g install expo-cli` to install. | ||
``` | ||
|
||
# What did `install-expo-modules` do for your project | ||
|
||
- Install [`expo`](https://www.npmjs.com/package/expo) package for necessary core and react-native autolinking. | ||
- Modify your project files to adopt expo-modules. If your project is managed by `git`, you can use `git diff` to review whatever `install-expo-modules` do for you. | ||
- Since expo-modules' minimal requirements for iOS is 12.0, if your ios deployment target is lower than that, this tool will upgrade your deployment target to 12.0. | ||
- `pod install` at last to update linked modules for iOS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @type {import('jest').Config} */ | ||
module.exports = { | ||
...require('expo-module-scripts/jest-preset-cli'), | ||
preset: 'ts-jest', | ||
displayName: require('./package').name, | ||
rootDir: __dirname, | ||
roots: ['src'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "install-expo-modules", | ||
"version": "0.6.4", | ||
"description": "Tools to install expo-modules for existing react-native projects", | ||
"main": "build", | ||
"scripts": { | ||
"build": "ncc build ./src/index.ts -o build/", | ||
"build:prod": "ncc build ./src/index.ts -o build/ --minify --no-cache --no-source-map-register", | ||
"clean": "expo-module clean", | ||
"lint": "expo-module lint", | ||
"prepare": "expo-module clean && yarn run build:prod", | ||
"prepublishOnly": "expo-module prepublishOnly", | ||
"test": "expo-module test", | ||
"typecheck": "expo-module typecheck", | ||
"watch": "yarn run build --watch" | ||
}, | ||
"bin": "./build/index.js", | ||
"files": [ | ||
"build" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/expo/expo.git", | ||
"directory": "packages/install-expo-modules" | ||
}, | ||
"keywords": [ | ||
"expo", | ||
"expo-modules", | ||
"npx", | ||
"react-native", | ||
"react" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/expo/expo/issues" | ||
}, | ||
"homepage": "https://github.com/expo/expo/tree/main/packages/install-expo-modules#readme", | ||
"dependencies": { | ||
"@expo/config": "^8.4.0", | ||
"@expo/config-plugins": "^7.7.0", | ||
"@expo/package-manager": "^1.0.3", | ||
"chalk": "^4.1.2", | ||
"commander": "2.20.0", | ||
"find-up": "^5.0.0", | ||
"glob": "7.1.6", | ||
"prompts": "^2.3.2", | ||
"resolve-from": "^5.0.0", | ||
"semver": "7.3.2", | ||
"terminal-link": "^2.1.1", | ||
"xcparse": "^0.0.3" | ||
}, | ||
"devDependencies": { | ||
"@types/prompts": "^2.0.6", | ||
"@types/semver": "^6.0.0", | ||
"expo-module-scripts": "^3.3.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
#!/usr/bin/env node | ||
|
||
import { getConfig } from '@expo/config'; | ||
import { compileModsAsync, ModPlatform } from '@expo/config-plugins'; | ||
import chalk from 'chalk'; | ||
import { Command } from 'commander'; | ||
import prompts from 'prompts'; | ||
|
||
import { | ||
shouldUpdateAgpVersionAsync, | ||
withAndroidGradlePluginVersion, | ||
} from './plugins/android/withAndroidGradles'; | ||
import { withAndroidModules } from './plugins/android/withAndroidModules'; | ||
import { withCliIntegration } from './plugins/cli/withCliIntegration'; | ||
import { | ||
shouldUpdateDeployTargetPodfileAsync, | ||
withIosDeploymentTarget, | ||
} from './plugins/ios/withIosDeploymentTarget'; | ||
import { withIosModules } from './plugins/ios/withIosModules'; | ||
import { withXCParseXcodeProjectBaseMod } from './plugins/ios/withXCParseXcodeProject'; | ||
import { getDefaultSdkVersion, getVersionInfo, VersionInfo } from './utils/expoVersionMappings'; | ||
import { learnMore } from './utils/link'; | ||
import { installExpoPackageAsync, installPodsAsync } from './utils/packageInstaller'; | ||
import { normalizeProjectRoot } from './utils/projectRoot'; | ||
|
||
const packageJSON = require('../package.json'); | ||
|
||
let projectRoot: string = ''; | ||
|
||
const program = new Command(packageJSON.name) | ||
.version(packageJSON.version) | ||
.arguments('<project-directory>') | ||
.usage(`${chalk.green('<project-directory>')} [options]`) | ||
.description('Install expo-modules into your project') | ||
.option('-s, --sdk-version <version>', 'Install specified expo-modules sdk version') | ||
.option('--non-interactive', 'Disable interactive prompts') | ||
.action((inputProjectRoot: string) => (projectRoot = inputProjectRoot)) | ||
.parse(process.argv); | ||
|
||
function getSdkVersionInfo(): VersionInfo { | ||
const { sdkVersion } = program; | ||
if (sdkVersion) { | ||
const versionInfo = getVersionInfo(sdkVersion); | ||
if (!versionInfo) { | ||
throw new Error(`Unsupported sdkVersion: ${sdkVersion}`); | ||
} | ||
return versionInfo; | ||
} | ||
return getDefaultSdkVersion(projectRoot); | ||
} | ||
|
||
/** | ||
* Show a prompt before upgrading the Android Gradle Plugin version for the target project. | ||
* | ||
* @returns true if user confirm to update. otherwise, returns false. | ||
*/ | ||
async function promptUpgradeAgpVersionAsync(projectRoot: string, agpVersion: string) { | ||
if (!(await shouldUpdateAgpVersionAsync(projectRoot, agpVersion))) { | ||
return true; | ||
} | ||
|
||
const deploymentTargetMessage = `The minimum Android Gradle Plugin version for Expo modules is ${agpVersion}. This tool will change your AGP version to ${agpVersion}.`; | ||
if (program.nonInteractive) { | ||
console.log(chalk.yellow(`⚠️ ${deploymentTargetMessage}`)); | ||
return true; | ||
} else { | ||
const { value } = await prompts({ | ||
type: 'confirm', | ||
name: 'value', | ||
message: `${deploymentTargetMessage} Do you want to continue?`, | ||
initial: true, | ||
}); | ||
return !!value; | ||
} | ||
} | ||
|
||
/** | ||
* Show a prompt before upgrading the iOS deployment target version for the target project. | ||
* | ||
* @returns true if user confirm to update. otherwise, returns false. | ||
*/ | ||
async function promptUpgradeIosDeployTargetAsync(projectRoot: string, iosDeploymentTarget: string) { | ||
if (!(await shouldUpdateDeployTargetPodfileAsync(projectRoot, iosDeploymentTarget))) { | ||
return true; | ||
} | ||
|
||
const deploymentTargetMessage = `Expo modules minimum iOS requirement is ${iosDeploymentTarget}. This tool will change your iOS deployment target to ${iosDeploymentTarget}.`; | ||
if (program.nonInteractive) { | ||
console.log(chalk.yellow(`⚠️ ${deploymentTargetMessage}`)); | ||
return true; | ||
} else { | ||
const { value } = await prompts({ | ||
type: 'confirm', | ||
name: 'value', | ||
message: `${deploymentTargetMessage} Do you want to continue?`, | ||
initial: true, | ||
}); | ||
return !!value; | ||
} | ||
} | ||
|
||
/** | ||
* Show a prompt to ask for adding Expo CLI integration. | ||
* @returns true if user confirm to add Expo CLI integration. otherwise, returns false. | ||
*/ | ||
async function promptCliIntegrationAsync() { | ||
const message = `This tool can install Expo CLI integration for your project. | ||
Using Expo CLI has some benefits over the the default CLI in bare React Native projects: | ||
- Built-in JavaScript debugger and React Devtools. | ||
- Support for Continuous Native Generation (CNG) with \`npx expo prebuild\` for easy upgrades. | ||
- Automatic web support with Metro. | ||
${learnMore('https://docs.expo.dev/bare/using-expo-cli/')} | ||
Do you want to install the Expo CLI integration?`; | ||
|
||
if (program.nonInteractive) { | ||
return true; | ||
} | ||
const { value } = await prompts({ | ||
type: 'confirm', | ||
name: 'value', | ||
message, | ||
initial: true, | ||
}); | ||
return !!value; | ||
} | ||
|
||
async function runAsync(programName: string) { | ||
projectRoot = normalizeProjectRoot(projectRoot); | ||
|
||
const { | ||
expoSdkVersion: sdkVersion, | ||
iosDeploymentTarget, | ||
androidAgpVersion, | ||
supportCliIntegration, | ||
} = getSdkVersionInfo(); | ||
if (androidAgpVersion && !(await promptUpgradeAgpVersionAsync(projectRoot, androidAgpVersion))) { | ||
return; | ||
} | ||
if (!(await promptUpgradeIosDeployTargetAsync(projectRoot, iosDeploymentTarget))) { | ||
return; | ||
} | ||
|
||
const cliIntegration = supportCliIntegration && (await promptCliIntegrationAsync()); | ||
|
||
const platforms: ModPlatform[] = ['android', 'ios']; | ||
let { exp: config } = getConfig(projectRoot, { | ||
skipSDKVersionRequirement: true, | ||
isModdedConfig: true, | ||
}); | ||
|
||
// for react-native project, we do not verify sdkVersion with the `skipSDKVersionRequirement` flag. | ||
// to get the target sdkVersion easier for config plugins, we fill the target sdkVersion into config. | ||
config.sdkVersion = sdkVersion; | ||
|
||
if (androidAgpVersion) { | ||
config = withAndroidGradlePluginVersion(config, { | ||
androidAgpVersion, | ||
}); | ||
} | ||
config = withAndroidModules(config); | ||
config = withIosModules(config); | ||
config = withIosDeploymentTarget(config, { | ||
deploymentTarget: iosDeploymentTarget, | ||
}); | ||
|
||
if (cliIntegration) { | ||
config = withCliIntegration(config); | ||
} | ||
|
||
// Keeps the base mods last | ||
config = withXCParseXcodeProjectBaseMod(config); | ||
|
||
console.log('\u203A Updating your project...'); | ||
await compileModsAsync(config, { | ||
projectRoot, | ||
platforms, | ||
}); | ||
|
||
console.log('\u203A Installing expo packages...'); | ||
await installExpoPackageAsync(projectRoot, sdkVersion); | ||
|
||
console.log('\u203A Installing ios pods...'); | ||
await installPodsAsync(projectRoot); | ||
|
||
console.log(chalk.bold('\u203A Installation completed!')); | ||
} | ||
|
||
(async () => { | ||
program.parse(process.argv); | ||
try { | ||
await runAsync(packageJSON.name); | ||
} catch (e) { | ||
console.error('Uncaught Error', e); | ||
process.exit(1); | ||
} | ||
})(); |
29 changes: 29 additions & 0 deletions
29
...dules/src/plugins/android/__tests__/fixtures/MainActivity-anonymous-delegate-updated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.helloworld; | ||
import expo.modules.ReactActivityDelegateWrapper; | ||
|
||
import com.facebook.react.ReactActivity; | ||
import com.facebook.react.ReactActivityDelegate; | ||
import com.facebook.react.ReactRootView | ||
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView; | ||
|
||
public class MainActivity extends ReactActivity { | ||
|
||
/** | ||
* Returns the name of the main component registered from JavaScript. This is used to schedule | ||
* rendering of the component. | ||
*/ | ||
@Override | ||
protected String getMainComponentName() { | ||
return "HelloWorld"; | ||
} | ||
|
||
@Override | ||
protected ReactActivityDelegate createReactActivityDelegate() { | ||
return new ReactActivityDelegateWrapper(this, new ReactActivityDelegate(this, getMainComponentName()) { | ||
@Override | ||
protected ReactRootView createRootView() { | ||
return new RNGestureHandlerEnabledRootView(MainActivity.this); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.