diff --git a/local-cli/link/__fixtures__/android/patchedBuild.gradle b/local-cli/link/__fixtures__/android/patchedBuild.gradle index 425aaaf7f44427..d7b58b7c7a7d38 100644 --- a/local-cli/link/__fixtures__/android/patchedBuild.gradle +++ b/local-cli/link/__fixtures__/android/patchedBuild.gradle @@ -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:+" diff --git a/local-cli/link/__tests__/android/isInstalled.spec.js b/local-cli/link/__tests__/android/isInstalled.spec.js index a90649f0339f5f..1955b1dd011453 100644 --- a/local-cli/link/__tests__/android/isInstalled.spec.js +++ b/local-cli/link/__tests__/android/isInstalled.spec.js @@ -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()); }); diff --git a/local-cli/link/android/isInstalled.js b/local-cli/link/android/isInstalled.js index 43a53396e9228d..f133619973fbff 100644 --- a/local-cli/link/android/isInstalled.js +++ b/local-cli/link/android/isInstalled.js @@ -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) + ); }; diff --git a/local-cli/link/android/patches/makeDeprecatedBuildPatch.js b/local-cli/link/android/patches/makeDeprecatedBuildPatch.js new file mode 100644 index 00000000000000..c2dc93810430e8 --- /dev/null +++ b/local-cli/link/android/patches/makeDeprecatedBuildPatch.js @@ -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`, + }; +}; diff --git a/local-cli/link/android/unregisterNativeModule.js b/local-cli/link/android/unregisterNativeModule.js index 880070afa503c4..37dd7a368e17e8 100644 --- a/local-cli/link/android/unregisterNativeModule.js +++ b/local-cli/link/android/unregisterNativeModule.js @@ -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'); @@ -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 = {}; @@ -39,6 +41,7 @@ module.exports = function unregisterNativeAndroidModule( ); revokePatch(projectConfig.buildGradlePath, buildPatch); + revokePatch(projectConfig.buildGradlePath, deprecatedBuildPatch); revokePatch(projectConfig.stringsPath, makeStringsPatch(params, name)); revokePatch(