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

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

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.*`);
EvanBacon marked this conversation as resolved.
Show resolved Hide resolved
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