Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions local-cli/link/__fixtures__/android/patchedBuild.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
implementation(project(':test2')) {
exclude(group: 'org.unwanted', module: 'test10')
}
compile project(':testDeprecated')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.facebook.react:react-native:+"
Expand Down
4 changes: 4 additions & 0 deletions local-cli/link/__tests__/android/isInstalled.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ describe('android::isInstalled', () => {
expect(isInstalled(projectConfig, 'test2')).toBeTruthy();
});

it('should return true when project is already in build.gradle using compile', () => {
expect(isInstalled(projectConfig, 'testDeprecated')).toBeTruthy();
});

it('should return false when project is not in build.gradle', () =>
expect(isInstalled(projectConfig, 'test3')).toBeFalsy());
});
6 changes: 5 additions & 1 deletion local-cli/link/android/isInstalled.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

const fs = require('fs');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeDeprecatedBuildPatch = require('./patches/makeDeprecatedBuildPatch');

module.exports = function isInstalled(config, name) {
const buildGradle = fs.readFileSync(config.buildGradlePath);
return makeBuildPatch(name).installPattern.test(buildGradle);
return (
makeBuildPatch(name).installPattern.test(buildGradle) ||
makeDeprecatedBuildPatch(name).installPattern.test(buildGradle)
);
};
23 changes: 23 additions & 0 deletions local-cli/link/android/patches/makeDeprecatedBuildPatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

const normalizeProjectName = require('./normalizeProjectName');

module.exports = function makeDeprecatedBuildPatch(name) {
const normalizedProjectName = normalizeProjectName(name);
const installPattern = new RegExp(
`\\s{4}(compile)(\\(|\\s)(project)\\(\\\':${normalizedProjectName}\\\'\\)(\\)|\\s)`,
);

return {
installPattern,
pattern: /[^ \t]dependencies {(\r\n|\n)/,
patch: ` compile project(':${normalizedProjectName}')\n`,
};
};
3 changes: 3 additions & 0 deletions local-cli/link/android/unregisterNativeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const toCamelCase = require('lodash').camelCase;
const revokePatch = require('./patches/revokePatch');
const makeSettingsPatch = require('./patches/makeSettingsPatch');
const makeBuildPatch = require('./patches/makeBuildPatch');
const makeDeprecatedBuildPatch = require('./patches/makeDeprecatedBuildPatch');
const makeStringsPatch = require('./patches/makeStringsPatch');
const makeImportPatch = require('./patches/makeImportPatch');
const makePackagePatch = require('./patches/makePackagePatch');
Expand All @@ -23,6 +24,7 @@ module.exports = function unregisterNativeAndroidModule(
projectConfig,
) {
const buildPatch = makeBuildPatch(name);
const deprecatedBuildPatch = makeDeprecatedBuildPatch(name);
const strings = fs.readFileSync(projectConfig.stringsPath, 'utf8');
var params = {};

Expand All @@ -39,6 +41,7 @@ module.exports = function unregisterNativeAndroidModule(
);

revokePatch(projectConfig.buildGradlePath, buildPatch);
revokePatch(projectConfig.buildGradlePath, deprecatedBuildPatch);
revokePatch(projectConfig.stringsPath, makeStringsPatch(params, name));

revokePatch(
Expand Down