mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 22:56:32 +08:00
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
77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
const xcode = require('xcode');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const log = require('npmlog');
|
|
|
|
const addToHeaderSearchPaths = require('./addToHeaderSearchPaths');
|
|
const getHeadersInFolder = require('./getHeadersInFolder');
|
|
const getHeaderSearchPath = require('./getHeaderSearchPath');
|
|
const getProducts = require('./getProducts');
|
|
const getTargets = require('./getTargets');
|
|
const createGroupWithMessage = require('./createGroupWithMessage');
|
|
const addFileToProject = require('./addFileToProject');
|
|
const addProjectToLibraries = require('./addProjectToLibraries');
|
|
const addSharedLibraries = require('./addSharedLibraries');
|
|
const isEmpty = require('lodash').isEmpty;
|
|
const getGroup = require('./getGroup');
|
|
|
|
/**
|
|
* Register native module IOS adds given dependency to project by adding
|
|
* its xcodeproj to project libraries as well as attaching static library
|
|
* to the first target (the main one)
|
|
*
|
|
* If library is already linked, this action is a no-op.
|
|
*/
|
|
module.exports = function registerNativeModuleIOS(dependencyConfig, projectConfig) {
|
|
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
|
|
const dependencyProject = xcode.project(dependencyConfig.pbxprojPath).parseSync();
|
|
|
|
const libraries = createGroupWithMessage(project, projectConfig.libraryFolder);
|
|
const file = addFileToProject(
|
|
project,
|
|
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath)
|
|
);
|
|
|
|
const targets = getTargets(project);
|
|
|
|
addProjectToLibraries(libraries, file);
|
|
|
|
getTargets(dependencyProject).forEach(product => {
|
|
var i;
|
|
if (!product.isTVOS) {
|
|
for (i=0; i<targets.length; i++) {
|
|
if(!targets[i].isTVOS) {
|
|
project.addStaticLibrary(product.name, {
|
|
target: targets[i].uuid
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
if (product.isTVOS) {
|
|
for (i=0; i<targets.length; i++) {
|
|
if(targets[i].isTVOS) {
|
|
project.addStaticLibrary(product.name, {
|
|
target: targets[i].uuid
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
addSharedLibraries(project, dependencyConfig.sharedLibraries);
|
|
|
|
const headers = getHeadersInFolder(dependencyConfig.folder);
|
|
if (!isEmpty(headers)) {
|
|
addToHeaderSearchPaths(
|
|
project,
|
|
getHeaderSearchPath(projectConfig.sourceDir, headers)
|
|
);
|
|
}
|
|
|
|
fs.writeFileSync(
|
|
projectConfig.pbxprojPath,
|
|
project.writeSync()
|
|
);
|
|
};
|