Skip to content

Commit 940a99c

Browse files
authored
Merge pull request #369 from zoontek/fix-package-name
2 parents a2b831b + 5e272fa commit 940a99c

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

src/__tests__/utils.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('replaceAppDetails ', () => {
9696
'android/app/src/debug/java/com/rndiffapp/ReactNativeFlipper.java',
9797
'SuperApp',
9898
'au.org.mycorp',
99-
'android/app/src/debug/java/au/org/mycorp/superapp/ReactNativeFlipper.java',
99+
'android/app/src/debug/java/au/org/mycorp/ReactNativeFlipper.java',
100100
],
101101
// Update the app details in file contents.
102102
[
@@ -109,7 +109,7 @@ describe('replaceAppDetails ', () => {
109109
'applicationId "com.rndiffapp"',
110110
'ACoolApp',
111111
'net.foobar',
112-
'applicationId "net.foobar.acoolapp"',
112+
'applicationId "net.foobar"',
113113
],
114114
// Don't accidentally pick up other instances of "com" such as in domain
115115
// names, or android or facebook packages.

src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const DEFAULT_APP_NAME = 'RnDiffApp'
2-
export const DEFAULT_APP_PACKAGE = 'com'
2+
export const DEFAULT_APP_PACKAGE = 'com.rndiffapp'
33

44
export const PACKAGE_NAMES = {
55
RN: 'react-native',

src/utils.js

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,23 @@ export const removeAppPathPrefix = (path, appName) =>
5454
path.replace(new RegExp(`${appName || DEFAULT_APP_NAME}/`), '')
5555

5656
/**
57-
* Replaces DEFAULT_APP_NAME and DEFAULT_APP_PACKAGE in str with custom
57+
* Replaces DEFAULT_APP_PACKAGE and DEFAULT_APP_NAME in str with custom
5858
* values if provided.
5959
* str could be a path, or content from a text file.
6060
*/
6161
export const replaceAppDetails = (str, appName, appPackage) => {
62-
let newStr = str
63-
if (appName) {
64-
newStr = newStr
65-
.replaceAll(DEFAULT_APP_NAME, appName)
66-
.replaceAll(DEFAULT_APP_NAME.toLowerCase(), appName.toLowerCase())
67-
}
68-
69-
if (appPackage) {
70-
// TODO should we use node path.sep instead of hardcoding /?
71-
// com.foo.bar -> com/foo/bar
72-
const appPackageAsPath = appPackage.replaceAll('.', '/')
73-
74-
// Only replace if DEFAULT_APP_PACKAGE a.k.a. "com" is followed by lower
75-
// case appName. Otherwise we unwittingly pick up "com.android..." or
76-
// "https://github.com/facebook..."
77-
newStr = newStr
78-
.replaceAll(
79-
`${DEFAULT_APP_PACKAGE}/${appName.toLowerCase()}`,
80-
`${appPackageAsPath}/${appName.toLowerCase()}`
81-
)
82-
.replaceAll(
83-
`${DEFAULT_APP_PACKAGE}.${appName.toLowerCase()}`,
84-
`${appPackage}.${appName.toLowerCase()}`
85-
)
86-
}
87-
88-
return newStr
62+
const appNameOrFallback = appName || DEFAULT_APP_NAME
63+
const appPackageOrFallback =
64+
appPackage || `com.${appNameOrFallback.toLowerCase()}`
65+
66+
return str
67+
.replaceAll(DEFAULT_APP_PACKAGE, appPackageOrFallback)
68+
.replaceAll(
69+
DEFAULT_APP_PACKAGE.replaceAll('.', '/'),
70+
appPackageOrFallback.replaceAll('.', '/')
71+
)
72+
.replaceAll(DEFAULT_APP_NAME, appNameOrFallback)
73+
.replaceAll(DEFAULT_APP_NAME.toLowerCase(), appNameOrFallback.toLowerCase())
8974
}
9075

9176
export const getVersionsContentInDiff = ({

0 commit comments

Comments
 (0)