Local cli/android/normalize project name

Summary:
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.

Help us understand your motivation by explaining why you decided to make this change.

You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html

Happy contributing!

-->

Scoped packages are starting to be the new thing, and gradle does not work properly with '/' in the project name, so this PR links them and replaces '/' by '_' . This only affects android.

I added tests in the 2 impacted functions + a test file for the normalizer function

<!--
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.**

-->
[CLI] [BUGFIX] [local-cli/link/link.js] - On android, Scoped packages will now get the '/' replaced with '_' to ensure gradle works nicely.  ⚠️ However if you previously linked scoped packages, they will get linked again. ⚠️
Closes https://github.com/facebook/react-native/pull/18275

Differential Revision: D7305227

Pulled By: hramos

fbshipit-source-id: 1c95563e884175529692948b29407a7733c44353
This commit is contained in:
Thibault Malbranche
2018-03-16 11:11:40 -07:00
committed by Facebook Github Bot
parent b02b1670d6
commit dbd47592a1
6 changed files with 89 additions and 4 deletions

View File

@@ -5,14 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/
const normalizeProjectName = require('./normalizeProjectName');
module.exports = function makeBuildPatch(name) {
const normalizedProjectName = normalizeProjectName(name);
const installPattern = new RegExp(
`\\s{4}(compile)(\\(|\\s)(project)\\(\\\':${name}\\\'\\)(\\)|\\s)`
`\\s{4}(compile)(\\(|\\s)(project)\\(\\\':${normalizedProjectName}\\\'\\)(\\)|\\s)`
);
return {
installPattern,
pattern: /[^ \t]dependencies {\n/,
patch: ` compile project(':${name}')\n`
patch: ` compile project(':${normalizedProjectName}')\n`
};
};

View File

@@ -6,6 +6,8 @@
*/
const path = require('path');
const normalizeProjectName = require('./normalizeProjectName');
const isWin = process.platform === 'win32';
module.exports = function makeSettingsPatch(name, androidConfig, projectConfig) {
@@ -13,6 +15,8 @@ module.exports = function makeSettingsPatch(name, androidConfig, projectConfig)
path.dirname(projectConfig.settingsGradlePath),
androidConfig.sourceDir
);
const normalizedProjectName = normalizeProjectName(name);
/*
* Fix for Windows
@@ -26,8 +30,8 @@ module.exports = function makeSettingsPatch(name, androidConfig, projectConfig)
return {
pattern: '\n',
patch: `include ':${name}'\n` +
`project(':${name}').projectDir = ` +
patch: `include ':${normalizedProjectName}'\n` +
`project(':${normalizedProjectName}').projectDir = ` +
`new File(rootProject.projectDir, '${projectDir}')\n`,
};
};

View File

@@ -0,0 +1,4 @@
module.exports = function normalizeProjectName(name) {
return name.replace(/\//g, '_');
};