From df425cd764db588c8d18aded594242e9f59c1e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Thu, 27 Jun 2019 23:41:33 +0200 Subject: [PATCH 1/4] wip --- packages/cli/src/commands/link/link.js | 2 +- packages/cli/src/commands/link/linkAll.js | 51 ++++++++++++++----- .../cli/src/commands/link/linkDependency.js | 8 ++- .../platform-ios/src/commands/runIOS/index.js | 3 ++ .../platform-ios/src/config/findProject.js | 8 +-- packages/platform-ios/src/link/isInstalled.js | 12 ++++- 6 files changed, 64 insertions(+), 20 deletions(-) diff --git a/packages/cli/src/commands/link/link.js b/packages/cli/src/commands/link/link.js index d7e458e82..c79b8c63f 100644 --- a/packages/cli/src/commands/link/link.js +++ b/packages/cli/src/commands/link/link.js @@ -50,7 +50,7 @@ async function link( if (rawPackageName === undefined) { logger.debug('No package name provided, will linking all possible assets.'); - return linkAll(ctx, {linkDeps: opts.all, linkAssets: true}); + return linkAll(ctx, {linkDeps: opts.all, linkAssets: true, dryRun: true}); } // Trim the version / tag out of the package name (eg. package@latest) diff --git a/packages/cli/src/commands/link/linkAll.js b/packages/cli/src/commands/link/linkAll.js index 97ce27ade..3bb8c1801 100644 --- a/packages/cli/src/commands/link/linkAll.js +++ b/packages/cli/src/commands/link/linkAll.js @@ -17,29 +17,39 @@ const dedupeAssets = (assets: Array): Array => type Options = { linkDeps?: boolean, linkAssets?: boolean, + checkInstalled?: boolean, }; async function linkAll(config: ConfigT, options: Options) { + let deps = []; if (options.linkDeps) { - logger.debug('Linking all dependencies'); - logger.info( - `Linking dependencies using "${chalk.bold( - 'link', - )}" command is now legacy and likely unnecessary. We encourage you to try ${chalk.bold( - 'autolinking', - )} that comes with React Native v0.60 default template. Autolinking happens at build time – during CocoaPods install or Gradle install phase. More information: ${chalk.dim.underline( - 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', - )}`, - ); + if (!options.checkInstalled) { + logger.debug('Linking all dependencies'); + logger.info( + `Linking dependencies using "${chalk.bold( + 'link', + )}" command is now legacy and likely unnecessary. We encourage you to try ${chalk.bold( + 'autolinking', + )} that comes with React Native v0.60 default template. Autolinking happens at build time – during CocoaPods install or Gradle install phase. More information: ${chalk.dim.underline( + 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', + )}`, + ); + } for (let key in config.dependencies) { const dependency = config.dependencies[key]; try { - if (dependency.hooks.prelink) { + if (!options.checkInstalled && dependency.hooks.prelink) { await makeHook(dependency.hooks.prelink)(); } - await linkDependency(config.platforms, config.project, dependency); - if (dependency.hooks.postlink) { + const x = await linkDependency( + config.platforms, + config.project, + dependency, + options.checkInstalled, + ); + deps = deps.concat(x.filter(d => d && d.isInstalled)); + if (!options.checkInstalled && dependency.hooks.postlink) { await makeHook(dependency.hooks.postlink)(); } } catch (error) { @@ -50,6 +60,21 @@ async function linkAll(config: ConfigT, options: Options) { } } } + + if (options.checkInstalled) { + const installedModules = [...new Set(deps.map(dep => dep.dependency.name))]; + if (installedModules.length) { + logger.warn( + `Following modules are linked using legacy "react-native link": \n${installedModules + .map(x => ` - ${chalk.bold(x)}`) + .join( + '\n', + )}\nPlease unlink them to not conflict with autolinking. You can do so with "react-native unlink" command. If any module is not compatible with autolinking (it breaks the build phase), please ignore this warning and notify its maintainers about it.`, + ); + } + return; + } + if (options.linkAssets) { logger.debug('Linking all assets'); const projectAssets = config.assets; diff --git a/packages/cli/src/commands/link/linkDependency.js b/packages/cli/src/commands/link/linkDependency.js index a893076a8..82557befb 100644 --- a/packages/cli/src/commands/link/linkDependency.js +++ b/packages/cli/src/commands/link/linkDependency.js @@ -9,10 +9,10 @@ const linkDependency = async ( platforms: PlatformsT, project: ProjectConfigT, dependency: DependencyConfigT, + dryRun?: boolean = false, ) => { const params = await pollParams(dependency.params); - - Object.keys(platforms || {}).forEach(platform => { + return Object.keys(platforms || {}).map(platform => { const projectConfig = project[platform]; const dependencyConfig = dependency.platforms[platform]; @@ -37,6 +37,10 @@ const linkDependency = async ( dependencyConfig, ); + if (dryRun) { + return {dependency, platform, isInstalled}; + } + if (isInstalled) { logger.info( `${getPlatformName(platform)} module "${chalk.bold( diff --git a/packages/platform-ios/src/commands/runIOS/index.js b/packages/platform-ios/src/commands/runIOS/index.js index 239334d07..a179dfaf5 100644 --- a/packages/platform-ios/src/commands/runIOS/index.js +++ b/packages/platform-ios/src/commands/runIOS/index.js @@ -16,6 +16,7 @@ import type {ConfigT} from 'types'; import findXcodeProject from './findXcodeProject'; import parseIOSDevicesList from './parseIOSDevicesList'; import findMatchingSimulator from './findMatchingSimulator'; +import getIOSLinkConfig from '../../link/index'; import { logger, CLIError, @@ -41,6 +42,8 @@ function runIOS(_: Array, ctx: ConfigT, args: FlagsT) { 'iOS project folder not found. Are you sure this is a React Native project?', ); } + // const linkConfig = getIOSLinkConfig(); + // linkConfig.isInstalled(ctx.project) process.chdir(args.projectPath); diff --git a/packages/platform-ios/src/config/findProject.js b/packages/platform-ios/src/config/findProject.js index d798fea24..2f912971d 100644 --- a/packages/platform-ios/src/config/findProject.js +++ b/packages/platform-ios/src/config/findProject.js @@ -10,6 +10,7 @@ import glob from 'glob'; import path from 'path'; +import {memoize} from 'lodash'; /** * Glob pattern to look for xcodeproj @@ -37,9 +38,10 @@ const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules)/**']; * * Returns first match if files are found or null * - * Note: `./ios/*.xcodeproj` are returned regardless of the name + * Note: `./ios/*.xcodeproj` are returned regardless of the name. + * Note2: Globbing is expensive and likely repeated on the same folder, hence memoizing */ -export default function findProject(folder: string): string | null { +export default memoize(function findProject(folder: string): string | null { const projects = glob .sync(GLOB_PATTERN, { cwd: folder, @@ -56,4 +58,4 @@ export default function findProject(folder: string): string | null { } return projects[0]; -} +}); diff --git a/packages/platform-ios/src/link/isInstalled.js b/packages/platform-ios/src/link/isInstalled.js index cf88883bc..bf826a8ab 100644 --- a/packages/platform-ios/src/link/isInstalled.js +++ b/packages/platform-ios/src/link/isInstalled.js @@ -11,12 +11,22 @@ import xcode from 'xcode'; import getGroup from './getGroup'; import hasLibraryImported from './hasLibraryImported'; +const memo = new Map(); + /** * Returns true if `xcodeproj` specified by dependencyConfig is present * in a top level `libraryFolder` */ export default function isInstalled(projectConfig, dependencyConfig) { - const project = xcode.project(projectConfig.pbxprojPath).parseSync(); + let project; + + if (memo.has(projectConfig.pbxprojPath)) { + project = memo.get(projectConfig.pbxprojPath); + } else { + project = xcode.project(projectConfig.pbxprojPath).parseSync(); + memo.set(projectConfig.pbxprojPath, project); + } + // const project = xcode.project(projectConfig.pbxprojPath).parseSync(); const libraries = getGroup(project, projectConfig.libraryFolder); if (!libraries) { From c1b23d2287da49f3918a4f6427e5b19e39eff95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 29 Jun 2019 11:59:06 +0200 Subject: [PATCH 2/4] add warnings for run-ios and run-android --- packages/cli/src/commands/link/link.js | 2 +- packages/cli/src/commands/link/linkAll.js | 51 +++++-------------- .../cli/src/commands/link/linkDependency.js | 8 +-- .../src/commands/runAndroid/index.js | 3 ++ .../src/link/warnAboutManuallyLinkedLibs.js | 51 +++++++++++++++++++ .../platform-ios/src/commands/runIOS/index.js | 7 ++- .../platform-ios/src/config/findProject.js | 2 +- .../platform-ios/src/link-pods/isInstalled.js | 10 ++-- .../src/link/common/isInstalled.js | 9 +++- packages/platform-ios/src/link/index.js | 2 +- packages/platform-ios/src/link/isInstalled.js | 8 ++- .../src/link/warnAboutManuallyLinkedLibs.js | 51 +++++++++++++++++++ 12 files changed, 146 insertions(+), 58 deletions(-) create mode 100644 packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js create mode 100644 packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js diff --git a/packages/cli/src/commands/link/link.js b/packages/cli/src/commands/link/link.js index c79b8c63f..d7e458e82 100644 --- a/packages/cli/src/commands/link/link.js +++ b/packages/cli/src/commands/link/link.js @@ -50,7 +50,7 @@ async function link( if (rawPackageName === undefined) { logger.debug('No package name provided, will linking all possible assets.'); - return linkAll(ctx, {linkDeps: opts.all, linkAssets: true, dryRun: true}); + return linkAll(ctx, {linkDeps: opts.all, linkAssets: true}); } // Trim the version / tag out of the package name (eg. package@latest) diff --git a/packages/cli/src/commands/link/linkAll.js b/packages/cli/src/commands/link/linkAll.js index 3bb8c1801..97ce27ade 100644 --- a/packages/cli/src/commands/link/linkAll.js +++ b/packages/cli/src/commands/link/linkAll.js @@ -17,39 +17,29 @@ const dedupeAssets = (assets: Array): Array => type Options = { linkDeps?: boolean, linkAssets?: boolean, - checkInstalled?: boolean, }; async function linkAll(config: ConfigT, options: Options) { - let deps = []; if (options.linkDeps) { - if (!options.checkInstalled) { - logger.debug('Linking all dependencies'); - logger.info( - `Linking dependencies using "${chalk.bold( - 'link', - )}" command is now legacy and likely unnecessary. We encourage you to try ${chalk.bold( - 'autolinking', - )} that comes with React Native v0.60 default template. Autolinking happens at build time – during CocoaPods install or Gradle install phase. More information: ${chalk.dim.underline( - 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', - )}`, - ); - } + logger.debug('Linking all dependencies'); + logger.info( + `Linking dependencies using "${chalk.bold( + 'link', + )}" command is now legacy and likely unnecessary. We encourage you to try ${chalk.bold( + 'autolinking', + )} that comes with React Native v0.60 default template. Autolinking happens at build time – during CocoaPods install or Gradle install phase. More information: ${chalk.dim.underline( + 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', + )}`, + ); for (let key in config.dependencies) { const dependency = config.dependencies[key]; try { - if (!options.checkInstalled && dependency.hooks.prelink) { + if (dependency.hooks.prelink) { await makeHook(dependency.hooks.prelink)(); } - const x = await linkDependency( - config.platforms, - config.project, - dependency, - options.checkInstalled, - ); - deps = deps.concat(x.filter(d => d && d.isInstalled)); - if (!options.checkInstalled && dependency.hooks.postlink) { + await linkDependency(config.platforms, config.project, dependency); + if (dependency.hooks.postlink) { await makeHook(dependency.hooks.postlink)(); } } catch (error) { @@ -60,21 +50,6 @@ async function linkAll(config: ConfigT, options: Options) { } } } - - if (options.checkInstalled) { - const installedModules = [...new Set(deps.map(dep => dep.dependency.name))]; - if (installedModules.length) { - logger.warn( - `Following modules are linked using legacy "react-native link": \n${installedModules - .map(x => ` - ${chalk.bold(x)}`) - .join( - '\n', - )}\nPlease unlink them to not conflict with autolinking. You can do so with "react-native unlink" command. If any module is not compatible with autolinking (it breaks the build phase), please ignore this warning and notify its maintainers about it.`, - ); - } - return; - } - if (options.linkAssets) { logger.debug('Linking all assets'); const projectAssets = config.assets; diff --git a/packages/cli/src/commands/link/linkDependency.js b/packages/cli/src/commands/link/linkDependency.js index 82557befb..a893076a8 100644 --- a/packages/cli/src/commands/link/linkDependency.js +++ b/packages/cli/src/commands/link/linkDependency.js @@ -9,10 +9,10 @@ const linkDependency = async ( platforms: PlatformsT, project: ProjectConfigT, dependency: DependencyConfigT, - dryRun?: boolean = false, ) => { const params = await pollParams(dependency.params); - return Object.keys(platforms || {}).map(platform => { + + Object.keys(platforms || {}).forEach(platform => { const projectConfig = project[platform]; const dependencyConfig = dependency.platforms[platform]; @@ -37,10 +37,6 @@ const linkDependency = async ( dependencyConfig, ); - if (dryRun) { - return {dependency, platform, isInstalled}; - } - if (isInstalled) { logger.info( `${getPlatformName(platform)} module "${chalk.bold( diff --git a/packages/platform-android/src/commands/runAndroid/index.js b/packages/platform-android/src/commands/runAndroid/index.js index 096da3991..a687ff69b 100644 --- a/packages/platform-android/src/commands/runAndroid/index.js +++ b/packages/platform-android/src/commands/runAndroid/index.js @@ -24,6 +24,7 @@ import { getDefaultUserTerminal, CLIError, } from '@react-native-community/cli-tools'; +import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; // Verifies this is an Android project function checkAndroid(root) { @@ -55,6 +56,8 @@ function runAndroid(argv: Array, config: ConfigT, args: FlagsT) { return; } + warnAboutManuallyLinkedLibs(config); + if (!args.packager) { return buildAndRun(args); } diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js new file mode 100644 index 000000000..bfc829197 --- /dev/null +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js @@ -0,0 +1,51 @@ +// @flow + +import chalk from 'chalk'; +import {logger} from '@react-native-community/cli-tools'; +import type {ConfigT} from 'types'; +import getLinkConfig from './index'; + +// TODO: move to cli-tools once platform-ios and platform-android are migrated +// to TS and unify with iOS implementation +export default function warnAboutManuallyLinkedLibs( + config: ConfigT, + platform: string = 'android', + linkConfig: $Call = getLinkConfig(), +) { + let deps = []; + + for (let key in config.dependencies) { + const dependency = config.dependencies[key]; + try { + const projectConfig = config.project[platform]; + const dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); + } + } catch (error) { + logger.debug('error'); + } + } + + const installedModules = [...new Set(deps)]; + + if (installedModules.length) { + logger.error( + `React Native CLI uses autolinking for native dependencies, but following modules are linked manually: \n${installedModules + .map( + x => + ` - ${chalk.bold(x)} ${chalk.dim( + `(to unlink run: "react-native unlink ${x}")`, + )}`, + ) + .join( + '\n', + )}\nThis is likely to happen when upgrading React Native from version lower than 0.60 to 0.60 or later. Please unlink them as they are likely to cause build failures. You can do so with "react-native unlink" command as shown above. If a library is not compatible with autolinking yet, please ignore this warning and notify the library maintainers.`, + ); + } +} diff --git a/packages/platform-ios/src/commands/runIOS/index.js b/packages/platform-ios/src/commands/runIOS/index.js index a179dfaf5..1726d2ea4 100644 --- a/packages/platform-ios/src/commands/runIOS/index.js +++ b/packages/platform-ios/src/commands/runIOS/index.js @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. * * @flow - * @format */ import child_process from 'child_process'; @@ -16,7 +15,7 @@ import type {ConfigT} from 'types'; import findXcodeProject from './findXcodeProject'; import parseIOSDevicesList from './parseIOSDevicesList'; import findMatchingSimulator from './findMatchingSimulator'; -import getIOSLinkConfig from '../../link/index'; +import warnAboutManuallyLinkedLibs from '../../link/warnAboutManuallyLinkedLibs'; import { logger, CLIError, @@ -42,8 +41,8 @@ function runIOS(_: Array, ctx: ConfigT, args: FlagsT) { 'iOS project folder not found. Are you sure this is a React Native project?', ); } - // const linkConfig = getIOSLinkConfig(); - // linkConfig.isInstalled(ctx.project) + + warnAboutManuallyLinkedLibs(ctx); process.chdir(args.projectPath); diff --git a/packages/platform-ios/src/config/findProject.js b/packages/platform-ios/src/config/findProject.js index 2f912971d..83e64ec0a 100644 --- a/packages/platform-ios/src/config/findProject.js +++ b/packages/platform-ios/src/config/findProject.js @@ -39,7 +39,7 @@ const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules)/**']; * Returns first match if files are found or null * * Note: `./ios/*.xcodeproj` are returned regardless of the name. - * Note2: Globbing is expensive and likely repeated on the same folder, hence memoizing + * Note2: Globbing is expensive and often repeated on the same folder, hence memoizing */ export default memoize(function findProject(folder: string): string | null { const projects = glob diff --git a/packages/platform-ios/src/link-pods/isInstalled.js b/packages/platform-ios/src/link-pods/isInstalled.js index d925a5592..caf97eb71 100644 --- a/packages/platform-ios/src/link-pods/isInstalled.js +++ b/packages/platform-ios/src/link-pods/isInstalled.js @@ -4,14 +4,18 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format + * @flow */ import readPodfile from './readPodfile'; import getPodspecName from '../config/getPodspecName'; +import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; -export default function isInstalled(iOSProject, dependencyConfig) { - if (!iOSProject.podfile) { +export default function isInstalled( + iOSProject: ProjectConfigIOST, + dependencyConfig: DependencyConfigIOST, +) { + if (!iOSProject.podfile || !dependencyConfig.podspecPath) { return false; } // match line with pod declaration: pod 'dependencyPodName' (other possible parameters of pod are ignored) diff --git a/packages/platform-ios/src/link/common/isInstalled.js b/packages/platform-ios/src/link/common/isInstalled.js index acbe38838..fcb5fab00 100644 --- a/packages/platform-ios/src/link/common/isInstalled.js +++ b/packages/platform-ios/src/link/common/isInstalled.js @@ -4,13 +4,18 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format + * @flow */ import isInstalledIOS from '../isInstalled'; import isInstalledPods from '../../link-pods/isInstalled'; +import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; -export default function isInstalled(projectConfig, name, dependencyConfig) { +export default function isInstalled( + projectConfig: ProjectConfigIOST, + name?: string, + dependencyConfig: DependencyConfigIOST, +) { return ( isInstalledIOS(projectConfig, dependencyConfig) || isInstalledPods(projectConfig, dependencyConfig) diff --git a/packages/platform-ios/src/link/index.js b/packages/platform-ios/src/link/index.js index cb7d49142..687e922f4 100644 --- a/packages/platform-ios/src/link/index.js +++ b/packages/platform-ios/src/link/index.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format + * @flow */ import isInstalled from './common/isInstalled'; diff --git a/packages/platform-ios/src/link/isInstalled.js b/packages/platform-ios/src/link/isInstalled.js index bf826a8ab..e2e09f58e 100644 --- a/packages/platform-ios/src/link/isInstalled.js +++ b/packages/platform-ios/src/link/isInstalled.js @@ -4,12 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @format + * @flow */ import xcode from 'xcode'; import getGroup from './getGroup'; import hasLibraryImported from './hasLibraryImported'; +import type {ProjectConfigIOST, DependencyConfigIOST} from 'types'; const memo = new Map(); @@ -17,7 +18,10 @@ const memo = new Map(); * Returns true if `xcodeproj` specified by dependencyConfig is present * in a top level `libraryFolder` */ -export default function isInstalled(projectConfig, dependencyConfig) { +export default function isInstalled( + projectConfig: ProjectConfigIOST, + dependencyConfig: DependencyConfigIOST, +) { let project; if (memo.has(projectConfig.pbxprojPath)) { diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js new file mode 100644 index 000000000..93e673867 --- /dev/null +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js @@ -0,0 +1,51 @@ +// @flow + +import chalk from 'chalk'; +import {logger} from '@react-native-community/cli-tools'; +import type {ConfigT} from 'types'; +import getLinkConfig from './index'; + +// TODO: move to cli-tools once platform-ios and platform-android are migrated +// to TS and unify with Android implementation +export default function warnAboutManuallyLinkedLibs( + config: ConfigT, + platform?: string = 'ios', + linkConfig: $Call = getLinkConfig(), +) { + let deps = []; + + for (let key in config.dependencies) { + const dependency = config.dependencies[key]; + try { + const projectConfig = config.project[platform]; + const dependencyConfig = dependency.platforms[platform]; + if (projectConfig && dependencyConfig) { + const x = linkConfig.isInstalled( + projectConfig, + dependency.name, + dependencyConfig, + ); + deps = deps.concat(x ? dependency.name : []); + } + } catch (error) { + logger.debug('error'); + } + } + + const installedModules = [...new Set(deps)]; + + if (installedModules.length) { + logger.error( + `React Native CLI uses autolinking for native dependencies, but following modules are linked manually: \n${installedModules + .map( + x => + ` - ${chalk.bold(x)} ${chalk.dim( + `(to unlink run: "react-native unlink ${x}")`, + )}`, + ) + .join( + '\n', + )}\nThis is likely to happen when upgrading React Native from version lower than 0.60 to 0.60 or later. Please unlink them as they are likely to cause build failures. You can do so with "react-native unlink" command as shown above. If a library is not compatible with autolinking yet, please ignore this warning and notify the library maintainers.`, + ); + } +} From 15652f822cde4e6660724c33d6c4870e6583c29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 29 Jun 2019 12:18:40 +0200 Subject: [PATCH 3/4] memoize in place --- packages/platform-ios/src/config/findProject.js | 8 +++----- packages/platform-ios/src/config/index.js | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/platform-ios/src/config/findProject.js b/packages/platform-ios/src/config/findProject.js index 83e64ec0a..d798fea24 100644 --- a/packages/platform-ios/src/config/findProject.js +++ b/packages/platform-ios/src/config/findProject.js @@ -10,7 +10,6 @@ import glob from 'glob'; import path from 'path'; -import {memoize} from 'lodash'; /** * Glob pattern to look for xcodeproj @@ -38,10 +37,9 @@ const GLOB_EXCLUDE_PATTERN = ['**/@(Pods|node_modules)/**']; * * Returns first match if files are found or null * - * Note: `./ios/*.xcodeproj` are returned regardless of the name. - * Note2: Globbing is expensive and often repeated on the same folder, hence memoizing + * Note: `./ios/*.xcodeproj` are returned regardless of the name */ -export default memoize(function findProject(folder: string): string | null { +export default function findProject(folder: string): string | null { const projects = glob .sync(GLOB_PATTERN, { cwd: folder, @@ -58,4 +56,4 @@ export default memoize(function findProject(folder: string): string | null { } return projects[0]; -}); +} diff --git a/packages/platform-ios/src/config/index.js b/packages/platform-ios/src/config/index.js index a6f7b4855..5bf40f7b8 100644 --- a/packages/platform-ios/src/config/index.js +++ b/packages/platform-ios/src/config/index.js @@ -9,11 +9,14 @@ */ import path from 'path'; +import {memoize} from 'lodash'; import findProject from './findProject'; import findPodfilePath from './findPodfilePath'; import findPodspec from './findPodspec'; import type {UserConfigT} from 'types'; +const memoizedFindProject = memoize(findProject); + /** * For libraries specified without an extension, add '.tbd' for those that * start with 'lib' and '.framework' to the rest. @@ -37,7 +40,7 @@ export function projectConfig( if (!userConfig) { return; } - const project = userConfig.project || findProject(folder); + const project = userConfig.project || memoizedFindProject(folder); /** * No iOS config found here From 0d5ffa809085d542ef98545239f7790b55a0ecf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 29 Jun 2019 12:37:39 +0200 Subject: [PATCH 4/4] cleanup --- .../platform-android/src/link/warnAboutManuallyLinkedLibs.js | 2 +- packages/platform-ios/src/link/isInstalled.js | 2 +- packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js index bfc829197..78ceb9a29 100644 --- a/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js +++ b/packages/platform-android/src/link/warnAboutManuallyLinkedLibs.js @@ -28,7 +28,7 @@ export default function warnAboutManuallyLinkedLibs( deps = deps.concat(x ? dependency.name : []); } } catch (error) { - logger.debug('error'); + logger.debug('Checking manually linked modules failed.', error); } } diff --git a/packages/platform-ios/src/link/isInstalled.js b/packages/platform-ios/src/link/isInstalled.js index e2e09f58e..13c74cdc1 100644 --- a/packages/platform-ios/src/link/isInstalled.js +++ b/packages/platform-ios/src/link/isInstalled.js @@ -30,7 +30,7 @@ export default function isInstalled( project = xcode.project(projectConfig.pbxprojPath).parseSync(); memo.set(projectConfig.pbxprojPath, project); } - // const project = xcode.project(projectConfig.pbxprojPath).parseSync(); + const libraries = getGroup(project, projectConfig.libraryFolder); if (!libraries) { diff --git a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js index 93e673867..fc5a67d6b 100644 --- a/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js +++ b/packages/platform-ios/src/link/warnAboutManuallyLinkedLibs.js @@ -28,7 +28,7 @@ export default function warnAboutManuallyLinkedLibs( deps = deps.concat(x ? dependency.name : []); } } catch (error) { - logger.debug('error'); + logger.debug('Checking manually linked modules failed.', error); } }