Skip to content

Commit cca3815

Browse files
committed
Fix issue with AppName stripping incorrectly.
Handles cases where appName is empty.
1 parent b6bbf79 commit cca3815

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: src/__tests__/utils.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PACKAGE_NAMES } from '../constants'
22
import '../releases/__mocks__/index'
33
import {
44
getVersionsContentInDiff,
5+
removeAppPathPrefix,
56
replaceAppDetails,
67
getChangelogURL,
78
} from '../utils'
@@ -132,3 +133,21 @@ describe('replaceAppDetails ', () => {
132133
}
133134
)
134135
})
136+
137+
describe('removeAppPathPrefix', () => {
138+
test.each([
139+
['RnDiffApp/package.json', 'package.json'],
140+
['RnDiffApp/RnDiffApp.ts', 'RnDiffApp.ts'],
141+
])('removeAppPathPrefix("%s") -> "%s"', (path, newPath) => {
142+
expect(removeAppPathPrefix(path)).toEqual(newPath)
143+
})
144+
145+
test('removeAppPathPrefix custom AppName', () => {
146+
expect(removeAppPathPrefix('RnDiffApp/package.json', '')).toEqual(
147+
'RnDiffApp/package.json'
148+
)
149+
expect(removeAppPathPrefix('Foobar/package.json', 'Foobar')).toEqual(
150+
'package.json'
151+
)
152+
})
153+
})

Diff for: src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const getBinaryFileURL = ({
7575
}
7676

7777
export const removeAppPathPrefix = (path: string, appName = DEFAULT_APP_NAME) =>
78-
path.replace(new RegExp(`${appName}/`), '')
78+
path.replace(new RegExp(`^${appName}/`), '')
7979

8080
/**
8181
* Replaces DEFAULT_APP_PACKAGE and DEFAULT_APP_NAME in str with custom

0 commit comments

Comments
 (0)