Files
react-native/local-cli/link/ios/unregisterNativeModule.js
Douglas Lowder a63fd378a4 Link both iOS and tvOS libraries with react-native link (fix #13783)
Summary:
Fix issues with the react-native CLI when linking iOS and tvOS libraries to a project created with `react-native init`. (#13783)

Verified the changes against test project at https://github.com/dlowder-salesforce/react-native-link-test.  Both `react-native link react-native-svg` and `react-native unlink react-native-svg` work correctly on this project.  Added new unit test for the new file added to `local-cli/link/ios`.

[CLI] [BUGFIX] `react-native link` has been fixed to correctly link iOS and tvOS targets.
[IOS] [BUGFIX] `react-native link` has been fixed to correctly link iOS and tvOS targets.
Closes https://github.com/facebook/react-native/pull/17231

Differential Revision: D6837567

Pulled By: hramos

fbshipit-source-id: 234d3d3966ae1b89cd16a37c95d303553f7ba5f5
2018-01-30 16:28:59 -08:00

65 lines
2.1 KiB
JavaScript

const xcode = require('xcode');
const path = require('path');
const fs = require('fs');
const difference = require('lodash').difference;
const isEmpty = require('lodash').isEmpty;
const getGroup = require('./getGroup');
const getProducts = require('./getProducts');
const getTargets = require('./getTargets');
const getHeadersInFolder = require('./getHeadersInFolder');
const getHeaderSearchPath = require('./getHeaderSearchPath');
const removeProjectFromProject = require('./removeProjectFromProject');
const removeProjectFromLibraries = require('./removeProjectFromLibraries');
const removeFromStaticLibraries = require('./removeFromStaticLibraries');
const removeFromHeaderSearchPaths = require('./removeFromHeaderSearchPaths');
const removeSharedLibraries = require('./removeSharedLibraries');
/**
* Unregister native module IOS
*
* If library is already unlinked, this action is a no-op.
*/
module.exports = function unregisterNativeModule(dependencyConfig, projectConfig, iOSDependencies) {
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
const dependencyProject = xcode.project(dependencyConfig.pbxprojPath).parseSync();
const libraries = getGroup(project, projectConfig.libraryFolder);
const file = removeProjectFromProject(
project,
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
);
removeProjectFromLibraries(libraries, file);
getTargets(dependencyProject).forEach(target => {
removeFromStaticLibraries(project, target.name, {
target: project.getFirstTarget().uuid,
});
});
const sharedLibraries = difference(
dependencyConfig.sharedLibraries,
iOSDependencies.reduce(
(libs, dependency) => libs.concat(dependency.sharedLibraries),
projectConfig.sharedLibraries
)
);
removeSharedLibraries(project, sharedLibraries);
const headers = getHeadersInFolder(dependencyConfig.folder);
if (!isEmpty(headers)) {
removeFromHeaderSearchPaths(
project,
getHeaderSearchPath(projectConfig.sourceDir, headers)
);
}
fs.writeFileSync(
projectConfig.pbxprojPath,
project.writeSync()
);
};