24 lines
668 B
JavaScript
Raw Normal View History

/**
* 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 makeBuildPatch(name) {
const normalizedProjectName = normalizeProjectName(name);
Support additional dependency declaration format Summary: Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. Previously, `isInstalled` was somewhat naively checking for the presence of a string in the `build.gradle` file to determine whether or not that dependency was already linked. I.e.: ``` compile project(':${name}')\n ``` …where `name` is replaced with the name of the dependency being checked. This was inflexible as it only supported that particular format of `compile` definition. Another, valid `compile` definition follows: ``` compile(project(':example') { … } ``` However, this failed the check because it didn't _exactly_ match the format for which the check was searching the `build.gradle` contents. As a result, running `react-native link` would incorrectly duplicate the dependency definition and thus cause a crash upon launching the app. This change adds an `installPattern` to the object returned from `makeBuildPatch`, which includes the particular dependency name and is valid for both `compile` definition formats. This commit adds an additional compile definition in the associated fixture, an additional test case in `isInstalled.spec.js` to check for this additional format, and an additional test in `makeBuildPatch.spec.js` to ensure the object returned includes the aforementioned `installPattern` Regex pattern. Sign the [CLA][2], if you haven't already. ✅ Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. ✅ Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/14475 Differential Revision: D5398552 Pulled By: hramos fbshipit-source-id: 1eaf84ba5bcfc43202f13c6b8fcfc68c30f36c33
2017-07-11 11:04:24 -07:00
const installPattern = new RegExp(
`\\s{4}(implementation)(\\(|\\s)(project)\\(\\\':${normalizedProjectName}\\\'\\)(\\)|\\s)`,
);
Support additional dependency declaration format Summary: Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. Previously, `isInstalled` was somewhat naively checking for the presence of a string in the `build.gradle` file to determine whether or not that dependency was already linked. I.e.: ``` compile project(':${name}')\n ``` …where `name` is replaced with the name of the dependency being checked. This was inflexible as it only supported that particular format of `compile` definition. Another, valid `compile` definition follows: ``` compile(project(':example') { … } ``` However, this failed the check because it didn't _exactly_ match the format for which the check was searching the `build.gradle` contents. As a result, running `react-native link` would incorrectly duplicate the dependency definition and thus cause a crash upon launching the app. This change adds an `installPattern` to the object returned from `makeBuildPatch`, which includes the particular dependency name and is valid for both `compile` definition formats. This commit adds an additional compile definition in the associated fixture, an additional test case in `isInstalled.spec.js` to check for this additional format, and an additional test in `makeBuildPatch.spec.js` to ensure the object returned includes the aforementioned `installPattern` Regex pattern. Sign the [CLA][2], if you haven't already. ✅ Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. ✅ Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/14475 Differential Revision: D5398552 Pulled By: hramos fbshipit-source-id: 1eaf84ba5bcfc43202f13c6b8fcfc68c30f36c33
2017-07-11 11:04:24 -07:00
return {
Support additional dependency declaration format Summary: Thanks for submitting a PR! Please read these instructions carefully: - [x] Explain the **motivation** for making this change. - [x] Provide a **test plan** demonstrating that the code is solid. - [x] Match the **code formatting** of the rest of the codebase. - [x] Target the `master` branch, NOT a "stable" branch. Previously, `isInstalled` was somewhat naively checking for the presence of a string in the `build.gradle` file to determine whether or not that dependency was already linked. I.e.: ``` compile project(':${name}')\n ``` …where `name` is replaced with the name of the dependency being checked. This was inflexible as it only supported that particular format of `compile` definition. Another, valid `compile` definition follows: ``` compile(project(':example') { … } ``` However, this failed the check because it didn't _exactly_ match the format for which the check was searching the `build.gradle` contents. As a result, running `react-native link` would incorrectly duplicate the dependency definition and thus cause a crash upon launching the app. This change adds an `installPattern` to the object returned from `makeBuildPatch`, which includes the particular dependency name and is valid for both `compile` definition formats. This commit adds an additional compile definition in the associated fixture, an additional test case in `isInstalled.spec.js` to check for this additional format, and an additional test in `makeBuildPatch.spec.js` to ensure the object returned includes the aforementioned `installPattern` Regex pattern. Sign the [CLA][2], if you haven't already. ✅ Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it. ✅ Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged. For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines. [1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9 [2]: https://code.facebook.com/cla [3]: https://travis-ci.org/facebook/react-native [4]: http://circleci.com/gh/facebook/react-native [5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests Closes https://github.com/facebook/react-native/pull/14475 Differential Revision: D5398552 Pulled By: hramos fbshipit-source-id: 1eaf84ba5bcfc43202f13c6b8fcfc68c30f36c33
2017-07-11 11:04:24 -07:00
installPattern,
Fix #18244 Support CRLF build.gradle for Linking Summary: Fix for #18244 Add support for build.gradle with CRLF based line ending when running react-native link <!-- 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! --> `react native link` fails if andorid/app/build.gradle has CRLF based line endings. Minor 3 character code change. Ran `react native link` on Windows and Mac to verify. None <!-- 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] [BUGFIX] [local-cli/link/android/patches/makeBuildPath.js] - Support CRLF line endings Closes https://github.com/facebook/react-native/pull/18245 Differential Revision: D8044774 Pulled By: hramos fbshipit-source-id: 93fad3db7022784ee949936777aa5ac25e3a64a3
2018-05-25 10:35:52 -07:00
pattern: /[^ \t]dependencies {(\r\n|\n)/,
patch: ` implementation project(':${normalizedProjectName}')\n`,
};
};