Socket
Socket
Sign inDemoInstall

expo-dev-launcher

Package Overview
Dependencies
Maintainers
25
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-dev-launcher - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

ios/assets/__node_modules/css-select/node_modules/dom-serializer/foreignNames.json

10

CHANGELOG.md

@@ -13,2 +13,11 @@ # Changelog

## 0.9.1 — 2021-12-15
### 🐛 Bug fixes
- Fix plugin when `MainActivity.onNewIntent` exists. ([#15459](https://github.com/expo/expo/pull/15459) by [@janicduplessis](https://github.com/janicduplessis))
- Fix plugin when `expo-updates` is not present. ([#15541](https://github.com/expo/expo/pull/15541) by [@esamelson](https://github.com/esamelson))
- Include expo-platform header in manifest requests. ([#15563](https://github.com/expo/expo/pull/15563) by [@esamelson](https://github.com/esamelson))
- Fix plugin compatibility with SDK 44. ([#15562](https://github.com/expo/expo/pull/15562) & [#15570](https://github.com/expo/expo/pull/15570) by [@lukmccall](https://github.com/lukmccall) & [@esamelson](https://github.com/esamelson))
## 0.9.0 — 2021-12-03

@@ -24,3 +33,2 @@

- Fix cannot load url that starts with exp. (by [@lukmccall](https://github.com/lukmccall))
- [plugin] Fix config plugin compatibility with expo-screen-orientation. ([#14752](https://github.com/expo/expo/pull/14752) by [@esamelson](https://github.com/esamelson))

@@ -27,0 +35,0 @@ ## 0.8.4 — 2021-10-21

6

package.json
{
"name": "expo-dev-launcher",
"title": "Expo Development Launcher",
"version": "0.9.0",
"version": "0.9.1",
"description": "Pre-release version of the Expo development launcher package for testing.",

@@ -36,3 +36,3 @@ "main": "build/DevLauncher.js",

"devDependencies": {
"babel-preset-expo": "~8.5.1",
"babel-preset-expo": "~9.0.0",
"expo-module-scripts": "^2.0.0",

@@ -42,3 +42,3 @@ "react": "17.0.1",

},
"gitHead": "33c06f161723dc5b6099b9d7eded686bd92c7bbf"
"gitHead": "58a32c58b6532ec0e14df10b772fa33f7657fbcc"
}

@@ -11,3 +11,10 @@ "use strict";

function resolveExpoUpdatesVersion(projectRoot) {
const expoUpdatesBuildPath = (0, resolve_from_1.default)(projectRoot, 'expo-updates');
let expoUpdatesBuildPath;
try {
expoUpdatesBuildPath = (0, resolve_from_1.default)(projectRoot, 'expo-updates');
}
catch (e) {
// this is expected in projects that don't have expo-updates installed
return null;
}
if (!expoUpdatesBuildPath) {

@@ -14,0 +21,0 @@ return null;

import { ConfigPlugin } from '@expo/config-plugins';
export declare function modifyJavaMainActivity(content: string): string;
declare const _default: ConfigPlugin<unknown>;
export default _default;

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.modifyJavaMainActivity = void 0;
const config_plugins_1 = require("@expo/config-plugins");

@@ -18,12 +19,16 @@ const fs_1 = __importDefault(require("fs"));

const DEV_LAUNCHER_UPDATES_ANDROID_IMPORT = 'expo.modules.updates.UpdatesDevLauncherController';
const DEV_LAUNCHER_ON_NEW_INTENT = `
@Override
public void onNewIntent(Intent intent) {
if (DevLauncherController.tryToHandleIntent(this, intent)) {
return;
}
super.onNewIntent(intent);
}
`;
const DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE = `DevLauncherController.wrapReactActivityDelegate(this, () -> $1);`;
const DEV_LAUNCHER_ON_NEW_INTENT = [
'',
' @Override',
' public void onNewIntent(Intent intent) {',
' super.onNewIntent(intent);',
' }',
'',
].join('\n');
const DEV_LAUNCHER_HANDLE_INTENT = [
' if (DevLauncherController.tryToHandleIntent(this, intent)) {',
' return;',
' }',
].join('\n');
const DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE = (activityDelegateDeclaration) => `DevLauncherController.wrapReactActivityDelegate(this, () -> ${activityDelegateDeclaration})`;
const DEV_LAUNCHER_ANDROID_INIT = 'DevLauncherController.initialize(this, getReactNativeHost());';

@@ -42,2 +47,22 @@ const DEV_LAUNCHER_UPDATES_ANDROID_INIT = `if (BuildConfig.DEBUG) {

}
function findClosingBracketMatchIndex(str, pos) {
if (str[pos] !== '(') {
throw new Error("No '(' at index " + pos);
}
let depth = 1;
for (let i = pos + 1; i < str.length; i++) {
switch (str[i]) {
case '(':
depth++;
break;
case ')':
if (--depth === 0) {
return i;
}
break;
}
}
return -1; // No matching closing parenthesis
}
const replaceBetween = (origin, startIndex, endIndex, insertion) => `${origin.substring(0, startIndex)}${insertion}${origin.substring(endIndex)}`;
function addJavaImports(javaSource, javaImports) {

@@ -116,19 +141,34 @@ const lines = javaSource.split('\n');

};
function modifyJavaMainActivity(content) {
content = addJavaImports(content, [DEV_LAUNCHER_ANDROID_IMPORT, 'android.content.Intent']);
if (!content.includes('onNewIntent')) {
const lines = content.split('\n');
const onCreateIndex = lines.findIndex((line) => line.includes('public class MainActivity'));
lines.splice(onCreateIndex + 1, 0, DEV_LAUNCHER_ON_NEW_INTENT);
content = lines.join('\n');
}
if (!content.includes(DEV_LAUNCHER_HANDLE_INTENT)) {
content = (0, utils_1.addLines)(content, /super\.onNewIntent\(intent\)/, 0, [DEV_LAUNCHER_HANDLE_INTENT]);
}
if (!content.includes('DevLauncherController.wrapReactActivityDelegate')) {
const activityDelegateMatches = Array.from(content.matchAll(/new ReactActivityDelegate(Wrapper)/g));
if (activityDelegateMatches.length !== 1) {
config_plugins_1.WarningAggregator.addWarningAndroid('expo-dev-launcher', `Failed to wrap 'ReactActivityDelegate'
See the expo-dev-client installation instructions to modify your MainActivity.java manually: ${constants_1.InstallationPage}`);
return content;
}
const activityDelegateMatch = activityDelegateMatches[0];
const matchIndex = activityDelegateMatch.index;
const openingBracketIndex = matchIndex + activityDelegateMatch[0].length; // next character after `new ReactActivityDelegateWrapper`
const closingBracketIndex = findClosingBracketMatchIndex(content, openingBracketIndex);
const reactActivityDelegateDeclaration = content.substring(matchIndex, closingBracketIndex + 1);
content = replaceBetween(content, matchIndex, closingBracketIndex + 1, DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE(reactActivityDelegateDeclaration));
}
return content;
}
exports.modifyJavaMainActivity = modifyJavaMainActivity;
const withDevLauncherActivity = (config) => {
return (0, config_plugins_1.withMainActivity)(config, (config) => {
if (config.modResults.language === 'java') {
let content = addJavaImports(config.modResults.contents, [
DEV_LAUNCHER_ANDROID_IMPORT,
'android.content.Intent',
]);
if (!content.includes(DEV_LAUNCHER_ON_NEW_INTENT)) {
const lines = content.split('\n');
const onCreateIndex = lines.findIndex((line) => line.includes('public class MainActivity'));
lines.splice(onCreateIndex + 1, 0, DEV_LAUNCHER_ON_NEW_INTENT);
content = lines.join('\n');
}
if (!content.includes('DevLauncherController.wrapReactActivityDelegate')) {
content = content.replace(/(new ReactActivityDelegate(Wrapper)?(.|\s)*\}\)?);$/mu, DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE);
}
config.modResults.contents = content;
config.modResults.contents = modifyJavaMainActivity(config.modResults.contents);
}

@@ -135,0 +175,0 @@ else {

@@ -101,2 +101,12 @@ "use strict";

[self.window makeKeyAndVisible];`), 'm');
const DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44 = new RegExp(escapeRegExpCharacters(`RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil];
rootView.backgroundColor = [UIColor whiteColor];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = `) +
`([^;]+)` +
escapeRegExpCharacters(`;
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];`), 'm');
const DEV_LAUNCHER_NEW_INIT = `self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

@@ -151,2 +161,16 @@ #if defined(EX_DEV_LAUNCHER_ENABLED)

`;
const DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44 = `
- (RCTBridge *)initializeReactNativeApp:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil];
rootView.backgroundColor = [UIColor whiteColor];
UIViewController *rootViewController = [self.reactDelegate createRootViewController];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return bridge;
}
`;
function addImports(appDelegate, shouldAddUpdatesIntegration) {

@@ -207,14 +231,25 @@ if (!appDelegate.includes(DEV_LAUNCHER_APP_DELEGATE_IOS_IMPORT) &&

const shouldAddUpdatesIntegration = expoUpdatesVersion != null && semver_1.default.gt(expoUpdatesVersion, '0.6.0');
if (!DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_REGEX.test(appDelegate)) {
if (DEV_LAUNCHER_INIT_TO_REMOVE.test(appDelegate)) {
if (!DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_REGEX.test(appDelegate) &&
!appDelegate.includes(DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44)) {
let initToRemove;
let shouldAddSDK44Init = false;
if (DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44.test(appDelegate)) {
initToRemove = DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44;
shouldAddSDK44Init = true;
}
else if (DEV_LAUNCHER_INIT_TO_REMOVE.test(appDelegate)) {
initToRemove = DEV_LAUNCHER_INIT_TO_REMOVE;
}
if (initToRemove) {
// UIViewController can be initialized differently depending on whether expo-screen-orientation is installed,
// so we need to preserve whatever is there already.
let viewControllerInit;
appDelegate = appDelegate.replace(DEV_LAUNCHER_INIT_TO_REMOVE, (match, p1) => {
appDelegate = appDelegate.replace(initToRemove, (match, p1) => {
viewControllerInit = p1;
return DEV_LAUNCHER_NEW_INIT;
});
appDelegate = (0, utils_1.addLines)(appDelegate, '@implementation AppDelegate', 1, [
DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION(viewControllerInit),
]);
const initToAdd = shouldAddSDK44Init
? DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44
: DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION(viewControllerInit);
appDelegate = (0, utils_1.addLines)(appDelegate, '@implementation AppDelegate', 1, [initToAdd]);
}

@@ -221,0 +256,0 @@ else {

@@ -6,3 +6,9 @@ import fs from 'fs';

export function resolveExpoUpdatesVersion(projectRoot: string): string | null {
const expoUpdatesBuildPath = resolveFrom(projectRoot, 'expo-updates');
let expoUpdatesBuildPath;
try {
expoUpdatesBuildPath = resolveFrom(projectRoot, 'expo-updates');
} catch (e) {
// this is expected in projects that don't have expo-updates installed
return null;
}
if (!expoUpdatesBuildPath) {

@@ -9,0 +15,0 @@ return null;

@@ -23,12 +23,17 @@ import {

const DEV_LAUNCHER_UPDATES_ANDROID_IMPORT = 'expo.modules.updates.UpdatesDevLauncherController';
const DEV_LAUNCHER_ON_NEW_INTENT = `
@Override
public void onNewIntent(Intent intent) {
if (DevLauncherController.tryToHandleIntent(this, intent)) {
return;
}
super.onNewIntent(intent);
}
`;
const DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE = `DevLauncherController.wrapReactActivityDelegate(this, () -> $1);`;
const DEV_LAUNCHER_ON_NEW_INTENT = [
'',
' @Override',
' public void onNewIntent(Intent intent) {',
' super.onNewIntent(intent);',
' }',
'',
].join('\n');
const DEV_LAUNCHER_HANDLE_INTENT = [
' if (DevLauncherController.tryToHandleIntent(this, intent)) {',
' return;',
' }',
].join('\n');
const DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE = (activityDelegateDeclaration: string) =>
`DevLauncherController.wrapReactActivityDelegate(this, () -> ${activityDelegateDeclaration})`;
const DEV_LAUNCHER_ANDROID_INIT = 'DevLauncherController.initialize(this, getReactNativeHost());';

@@ -52,2 +57,25 @@ const DEV_LAUNCHER_UPDATES_ANDROID_INIT = `if (BuildConfig.DEBUG) {

function findClosingBracketMatchIndex(str: string, pos: number) {
if (str[pos] !== '(') {
throw new Error("No '(' at index " + pos);
}
let depth = 1;
for (let i = pos + 1; i < str.length; i++) {
switch (str[i]) {
case '(':
depth++;
break;
case ')':
if (--depth === 0) {
return i;
}
break;
}
}
return -1; // No matching closing parenthesis
}
const replaceBetween = (origin: string, startIndex: number, endIndex: number, insertion: string) =>
`${origin.substring(0, startIndex)}${insertion}${origin.substring(endIndex)}`;
function addJavaImports(javaSource: string, javaImports: string[]): string {

@@ -158,27 +186,52 @@ const lines = javaSource.split('\n');

const withDevLauncherActivity: ConfigPlugin = (config) => {
return withMainActivity(config, (config) => {
if (config.modResults.language === 'java') {
let content = addJavaImports(config.modResults.contents, [
DEV_LAUNCHER_ANDROID_IMPORT,
'android.content.Intent',
]);
export function modifyJavaMainActivity(content: string): string {
content = addJavaImports(content, [DEV_LAUNCHER_ANDROID_IMPORT, 'android.content.Intent']);
if (!content.includes(DEV_LAUNCHER_ON_NEW_INTENT)) {
const lines = content.split('\n');
const onCreateIndex = lines.findIndex((line) => line.includes('public class MainActivity'));
if (!content.includes('onNewIntent')) {
const lines = content.split('\n');
const onCreateIndex = lines.findIndex((line) => line.includes('public class MainActivity'));
lines.splice(onCreateIndex + 1, 0, DEV_LAUNCHER_ON_NEW_INTENT);
lines.splice(onCreateIndex + 1, 0, DEV_LAUNCHER_ON_NEW_INTENT);
content = lines.join('\n');
}
content = lines.join('\n');
}
if (!content.includes(DEV_LAUNCHER_HANDLE_INTENT)) {
content = addLines(content, /super\.onNewIntent\(intent\)/, 0, [DEV_LAUNCHER_HANDLE_INTENT]);
}
if (!content.includes('DevLauncherController.wrapReactActivityDelegate')) {
content = content.replace(
/(new ReactActivityDelegate(Wrapper)?(.|\s)*\}\)?);$/mu,
DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE
);
}
if (!content.includes('DevLauncherController.wrapReactActivityDelegate')) {
const activityDelegateMatches = Array.from(
content.matchAll(/new ReactActivityDelegate(Wrapper)/g)
);
config.modResults.contents = content;
if (activityDelegateMatches.length !== 1) {
WarningAggregator.addWarningAndroid(
'expo-dev-launcher',
`Failed to wrap 'ReactActivityDelegate'
See the expo-dev-client installation instructions to modify your MainActivity.java manually: ${InstallationPage}`
);
return content;
}
const activityDelegateMatch = activityDelegateMatches[0];
const matchIndex = activityDelegateMatch.index!;
const openingBracketIndex = matchIndex + activityDelegateMatch[0].length; // next character after `new ReactActivityDelegateWrapper`
const closingBracketIndex = findClosingBracketMatchIndex(content, openingBracketIndex);
const reactActivityDelegateDeclaration = content.substring(matchIndex, closingBracketIndex + 1);
content = replaceBetween(
content,
matchIndex,
closingBracketIndex + 1,
DEV_LAUNCHER_WRAPPED_ACTIVITY_DELEGATE(reactActivityDelegateDeclaration)
);
}
return content;
}
const withDevLauncherActivity: ConfigPlugin = (config) => {
return withMainActivity(config, (config) => {
if (config.modResults.language === 'java') {
config.modResults.contents = modifyJavaMainActivity(config.modResults.contents);
} else {

@@ -185,0 +238,0 @@ WarningAggregator.addWarningAndroid(

@@ -108,2 +108,16 @@ import { ConfigPlugin, WarningAggregator, withAppDelegate } from '@expo/config-plugins';

const DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44 = new RegExp(
escapeRegExpCharacters(`RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil];
rootView.backgroundColor = [UIColor whiteColor];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = `) +
`([^;]+)` +
escapeRegExpCharacters(`;
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];`),
'm'
);
const DEV_LAUNCHER_NEW_INIT = `self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

@@ -166,2 +180,17 @@ #if defined(EX_DEV_LAUNCHER_ENABLED)

const DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44 = `
- (RCTBridge *)initializeReactNativeApp:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil];
rootView.backgroundColor = [UIColor whiteColor];
UIViewController *rootViewController = [self.reactDelegate createRootViewController];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return bridge;
}
`;
function addImports(appDelegate: string, shouldAddUpdatesIntegration: boolean): string {

@@ -264,14 +293,27 @@ if (

if (!DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_REGEX.test(appDelegate)) {
if (DEV_LAUNCHER_INIT_TO_REMOVE.test(appDelegate)) {
if (
!DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_REGEX.test(appDelegate) &&
!appDelegate.includes(DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44)
) {
let initToRemove;
let shouldAddSDK44Init = false;
if (DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44.test(appDelegate)) {
initToRemove = DEV_LAUNCHER_INIT_TO_REMOVE_SDK_44;
shouldAddSDK44Init = true;
} else if (DEV_LAUNCHER_INIT_TO_REMOVE.test(appDelegate)) {
initToRemove = DEV_LAUNCHER_INIT_TO_REMOVE;
}
if (initToRemove) {
// UIViewController can be initialized differently depending on whether expo-screen-orientation is installed,
// so we need to preserve whatever is there already.
let viewControllerInit;
appDelegate = appDelegate.replace(DEV_LAUNCHER_INIT_TO_REMOVE, (match, p1) => {
appDelegate = appDelegate.replace(initToRemove, (match, p1) => {
viewControllerInit = p1;
return DEV_LAUNCHER_NEW_INIT;
});
appDelegate = addLines(appDelegate, '@implementation AppDelegate', 1, [
DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION(viewControllerInit),
]);
const initToAdd = shouldAddSDK44Init
? DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION_SDK_44
: DEV_LAUNCHER_INITIALIZE_REACT_NATIVE_APP_FUNCTION_DEFINITION(viewControllerInit);
appDelegate = addLines(appDelegate, '@implementation AppDelegate', 1, [initToAdd]);
} else {

@@ -278,0 +320,0 @@ WarningAggregator.addWarningIOS(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc