2018-02-09 01:10:29 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 19:43:49 +00:00
|
|
|
*
|
|
|
|
* @format
|
2018-02-09 01:10:29 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-20 11:52:08 +00:00
|
|
|
const xcode = require('xcode');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
2016-07-30 15:59:16 +00:00
|
|
|
const difference = require('lodash').difference;
|
|
|
|
const isEmpty = require('lodash').isEmpty;
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
const getGroup = require('./getGroup');
|
2016-05-20 11:52:08 +00:00
|
|
|
const getProducts = require('./getProducts');
|
2018-01-31 00:04:04 +00:00
|
|
|
const getTargets = require('./getTargets');
|
2016-05-20 11:52:08 +00:00
|
|
|
const getHeadersInFolder = require('./getHeadersInFolder');
|
|
|
|
const getHeaderSearchPath = require('./getHeaderSearchPath');
|
|
|
|
const removeProjectFromProject = require('./removeProjectFromProject');
|
|
|
|
const removeProjectFromLibraries = require('./removeProjectFromLibraries');
|
|
|
|
const removeFromStaticLibraries = require('./removeFromStaticLibraries');
|
|
|
|
const removeFromHeaderSearchPaths = require('./removeFromHeaderSearchPaths');
|
2016-07-30 15:59:16 +00:00
|
|
|
const removeSharedLibraries = require('./removeSharedLibraries');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister native module IOS
|
|
|
|
*
|
|
|
|
* If library is already unlinked, this action is a no-op.
|
|
|
|
*/
|
2018-05-11 19:43:49 +00:00
|
|
|
module.exports = function unregisterNativeModule(
|
|
|
|
dependencyConfig,
|
|
|
|
projectConfig,
|
|
|
|
iOSDependencies,
|
|
|
|
) {
|
2016-05-20 11:52:08 +00:00
|
|
|
const project = xcode.project(projectConfig.pbxprojPath).parseSync();
|
2018-05-11 19:43:49 +00:00
|
|
|
const dependencyProject = xcode
|
|
|
|
.project(dependencyConfig.pbxprojPath)
|
|
|
|
.parseSync();
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
const libraries = getGroup(project, projectConfig.libraryFolder);
|
|
|
|
|
|
|
|
const file = removeProjectFromProject(
|
|
|
|
project,
|
2018-05-11 19:43:49 +00:00
|
|
|
path.relative(projectConfig.sourceDir, dependencyConfig.projectPath),
|
2016-05-20 11:52:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
removeProjectFromLibraries(libraries, file);
|
|
|
|
|
2018-01-31 00:04:04 +00:00
|
|
|
getTargets(dependencyProject).forEach(target => {
|
|
|
|
removeFromStaticLibraries(project, target.name, {
|
2016-05-20 11:52:08 +00:00
|
|
|
target: project.getFirstTarget().uuid,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
const sharedLibraries = difference(
|
|
|
|
dependencyConfig.sharedLibraries,
|
|
|
|
iOSDependencies.reduce(
|
|
|
|
(libs, dependency) => libs.concat(dependency.sharedLibraries),
|
2018-05-11 19:43:49 +00:00
|
|
|
projectConfig.sharedLibraries,
|
|
|
|
),
|
2016-07-30 15:59:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
removeSharedLibraries(project, sharedLibraries);
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
const headers = getHeadersInFolder(dependencyConfig.folder);
|
|
|
|
if (!isEmpty(headers)) {
|
|
|
|
removeFromHeaderSearchPaths(
|
|
|
|
project,
|
2018-05-11 19:43:49 +00:00
|
|
|
getHeaderSearchPath(projectConfig.sourceDir, headers),
|
2016-05-20 11:52:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
fs.writeFileSync(projectConfig.pbxprojPath, project.writeSync());
|
2016-05-20 11:52:08 +00:00
|
|
|
};
|