Skip to content

Commit 35b8519

Browse files
rozelegrabbou
authored andcommitted
Uses a single code path to link and unlink all platforms
Summary: This commit removes special cases for linking iOS and Android platforms. A previous commit opened up link and other commands for other platforms to provide their own behaviors. It left special cases in tact for iOS and Android. This PR removes the special case. - Added jest tests related to the link command. - Ran the `link` and `unlink` commands for iOS and Android and confirmed no changes. #17745 <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [CLI][FEATURE][local-cli/link/link.js] - Removes special cases for linking in iOS and Android. Closes #17961 Differential Revision: D6975951 Pulled By: hramos fbshipit-source-id: 8dd5da35619e2124ce4b3b18db8b694757792363
1 parent 0e9ed6f commit 35b8519

File tree

13 files changed

+97
-154
lines changed

13 files changed

+97
-154
lines changed

local-cli/core/android/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,5 @@ exports.dependencyConfig = function dependencyConfigAndroid(folder, userConfig)
126126

127127
return { sourceDir, folder, manifest, packageImportPath, packageInstance };
128128
};
129+
130+
exports.linkConfig = require('../../link/android');

local-cli/core/ios/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ exports.projectConfig = function projectConfigIOS(folder, userConfig) {
5757
};
5858

5959
exports.dependencyConfig = exports.projectConfig;
60+
61+
exports.linkConfig = require('../../link/ios');

local-cli/link/__tests__/link.spec.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ describe('link', () => {
8181
it('should register native module when android/ios projects are present', (done) => {
8282
const registerNativeModule = sinon.stub();
8383
const dependencyConfig = {android: {}, ios: {}, assets: [], commands: {}};
84+
const androidLinkConfig = require('../android');
85+
const iosLinkConfig = require('../ios');
8486
const config = {
85-
getPlatformConfig: () => ({ios: {}, android: {}}),
87+
getPlatformConfig: () => ({ios: { linkConfig: iosLinkConfig }, android: { linkConfig: androidLinkConfig }}),
8688
getProjectConfig: () => ({android: {}, ios: {}, assets: []}),
8789
getDependencyConfig: sinon.stub().returns(dependencyConfig),
8890
};
@@ -223,8 +225,9 @@ describe('link', () => {
223225
sinon.stub().returns(false)
224226
);
225227

228+
const linkConfig = require('../ios');
226229
const config = {
227-
getPlatformConfig: () => ({ ios: {}}),
230+
getPlatformConfig: () => ({ ios: { linkConfig: linkConfig }}),
228231
getProjectConfig: () => ({ ios: {}, assets: [] }),
229232
getDependencyConfig: sinon.stub().returns({
230233
ios: {}, assets: [], commands: { prelink, postlink },
@@ -251,8 +254,9 @@ describe('link', () => {
251254
copyAssets
252255
);
253256

257+
const linkConfig = require('../ios');
254258
const config = {
255-
getPlatformConfig: () => ({ ios: {} }),
259+
getPlatformConfig: () => ({ ios: { linkConfig: linkConfig } }),
256260
getProjectConfig: () => ({ ios: {}, assets: projectAssets }),
257261
getDependencyConfig: sinon.stub().returns(dependencyConfig),
258262
};

local-cli/link/android/copyAssets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ const groupFilesByType = require('../groupFilesByType');
88
* For now, the only types of files that are handled are:
99
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
1010
*/
11-
module.exports = function copyAssetsAndroid(files, targetPath) {
11+
module.exports = function copyAssetsAndroid(files, project) {
1212
const assets = groupFilesByType(files);
1313

1414
(assets.font || []).forEach(asset =>
15-
fs.copySync(asset, path.join(targetPath, 'fonts', path.basename(asset)))
15+
fs.copySync(asset, path.join(project.assetsPath, 'fonts', path.basename(asset)))
1616
);
1717
};

local-cli/link/android/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function() {
2+
return {
3+
isInstalled: require('./isInstalled'),
4+
register: require('./registerNativeModule'),
5+
unregister: require('./unregisterNativeModule'),
6+
copyAssets: require('./copyAssets'),
7+
unlinkAssets: require('./unlinkAssets')
8+
};
9+
};

local-cli/link/android/unlinkAssets.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ const groupFilesByType = require('../groupFilesByType');
88
* For now, the only types of files that are handled are:
99
* - Fonts (otf, ttf) - copied to targetPath/fonts under original name
1010
*/
11-
module.exports = function unlinkAssetsAndroid(files, targetPath) {
11+
module.exports = function unlinkAssetsAndroid(files, project) {
1212
const assets = groupFilesByType(files);
1313

1414
(assets.font || []).forEach((file) => {
15-
const filePath = path.join(targetPath, 'fonts', path.basename(file));
15+
const filePath = path.join(project.assetsPath, 'fonts', path.basename(file));
1616
if (fs.existsSync(filePath)) {
1717
fs.unlinkSync(filePath);
1818
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const isInstalledIOS = require('../isInstalled');
2+
const isInstalledPods = require('../../pods/isInstalled');
3+
4+
module.exports = function isInstalled(config, name) {
5+
return isInstalledIOS(config, name) || isInstalledPods(config, name);
6+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const registerDependencyIOS = require('../registerNativeModule');
2+
const registerDependencyPods = require('../../pods/registerNativeModule');
3+
4+
module.exports = function registerNativeModule(
5+
name,
6+
dependencyConfig,
7+
params,
8+
projectConfig
9+
) {
10+
if (projectConfig.podfile && dependencyConfig.podspec) {
11+
registerDependencyPods(name, dependencyConfig, projectConfig);
12+
}
13+
else {
14+
registerDependencyIOS(dependencyConfig, projectConfig);
15+
}
16+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const compact = require('lodash').compact;
2+
const isInstalledIOS = require('../isInstalled');
3+
const isInstalledPods = require('../../pods/isInstalled');
4+
const unregisterDependencyIOS = require('../registerNativeModule');
5+
const unregisterDependencyPods = require('../../pods/registerNativeModule');
6+
7+
module.exports = function unregisterNativeModule(
8+
name,
9+
dependencyConfig,
10+
projectConfig,
11+
otherDependencies
12+
) {
13+
const isIosInstalled = isInstalledIOS(projectConfig, dependencyConfig);
14+
const isPodInstalled = isInstalledPods(projectConfig, dependencyConfig);
15+
if (isIosInstalled) {
16+
const iOSDependencies = compact(otherDependencies.map(d => d.config.ios));
17+
unregisterDependencyIOS(dependencyConfig, projectConfig, iOSDependencies);
18+
}
19+
else if (isPodInstalled) {
20+
unregisterDependencyPods(dependencyConfig, projectConfig);
21+
}
22+
};

local-cli/link/ios/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function() {
2+
return {
3+
isInstalled: require('./common/isInstalled'),
4+
register: require('./common/registerNativeModule'),
5+
unregister: require('./common/unregisterNativeModule'),
6+
copyAssets: require('./copyAssets'),
7+
unlinkAssets: require('./unlinkAssets')
8+
};
9+
};

0 commit comments

Comments
 (0)