Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[config-plugins] Fix app gradle versionName replacement after ejectin…
Browse files Browse the repository at this point in the history
…g twice (#3082)

* [config-plugins] Fix app gradle versionName replacement after ejecting twice

* Update packages/config-plugins/src/android/Version.ts

Co-authored-by: Evan Bacon <baconbrix@gmail.com>
  • Loading branch information
byCedric and EvanBacon authored Jan 22, 2021
1 parent 441dd62 commit bbf4e68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions packages/config-plugins/src/android/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { ConfigPlugin } from '../Plugin.types';
import { withAppBuildGradle } from '../plugins/android-plugins';
import * as WarningAggregator from '../utils/warnings';

const DEFAULT_VERSION_NAME = '1.0';

export const withVersion: ConfigPlugin = config => {
return withAppBuildGradle(config, config => {
if (config.modResults.language === 'groovy') {
Expand All @@ -25,17 +23,13 @@ export function getVersionName(config: Pick<ExpoConfig, 'version'>) {
return config.version ?? null;
}

export function setVersionName(
config: Pick<ExpoConfig, 'version'>,
buildGradle: string,
versionToReplace = DEFAULT_VERSION_NAME
) {
export function setVersionName(config: Pick<ExpoConfig, 'version'>, buildGradle: string) {
const versionName = getVersionName(config);
if (versionName === null) {
return buildGradle;
}

const pattern = new RegExp(`versionName "${versionToReplace}"`);
const pattern = new RegExp(`versionName ".*"`);
return buildGradle.replace(pattern, `versionName "${versionName}"`);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/config-plugins/src/android/__tests__/Version-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ describe('versionName', () => {
);
});

it(`replaces provided version name in build.gradle if version name is given`, () => {
expect(setVersionName({ version: '1.2.3' }, EXAMPLE_BUILD_GRADLE_2, '2.0')).toMatch(
it(`replaces provided version name in build.gradle if version name is not the default`, () => {
expect(setVersionName({ version: '1.2.3' }, EXAMPLE_BUILD_GRADLE_2)).toMatch(
'versionName "1.2.3"'
);
});
Expand Down

0 comments on commit bbf4e68

Please sign in to comment.