diff --git a/src/updaters/dart/pubspec-yaml.ts b/src/updaters/dart/pubspec-yaml.ts index 0e23f4160..5f0bd7cdc 100644 --- a/src/updaters/dart/pubspec-yaml.ts +++ b/src/updaters/dart/pubspec-yaml.ts @@ -26,7 +26,7 @@ export class PubspecYaml extends DefaultUpdater { */ updateContent(content: string, logger: Logger = defaultLogger): string { - const oldVersion = content.match(/^version: ([0-9.]+)\+?(.*$)/m); + const oldVersion = content.match(/^version: ([0-9]+\.[0-9]+\.[0-9]+(?:-[^\s+]+)?)\+?(.*$)/m); let buildNumber = ''; if (oldVersion) { diff --git a/test/updaters/fixtures/pubspec_prerelease.yaml b/test/updaters/fixtures/pubspec_prerelease.yaml new file mode 100644 index 000000000..e163845f1 --- /dev/null +++ b/test/updaters/fixtures/pubspec_prerelease.yaml @@ -0,0 +1,8 @@ +name: hello_world +description: Hello World +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +version: 0.5.0-beta.1 + +environment: + sdk: '>=2.12.0 <3.0.0' diff --git a/test/updaters/fixtures/pubspec_prerelease_with_build_no.yaml b/test/updaters/fixtures/pubspec_prerelease_with_build_no.yaml new file mode 100644 index 000000000..65cd7bcea --- /dev/null +++ b/test/updaters/fixtures/pubspec_prerelease_with_build_no.yaml @@ -0,0 +1,8 @@ +name: hello_world +description: Hello World +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +version: 0.5.0-beta.1+5 + +environment: + sdk: '>=2.12.0 <3.0.0' diff --git a/test/updaters/pubspec-yaml.ts b/test/updaters/pubspec-yaml.ts index bf5081c3e..bae4edd96 100644 --- a/test/updaters/pubspec-yaml.ts +++ b/test/updaters/pubspec-yaml.ts @@ -58,5 +58,28 @@ describe('PubspecYaml', () => { const newContent = version.updateContent(oldContent); snapshot(newContent); }); + it('updates prerelease version in pubspec.yaml file', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './pubspec_prerelease.yaml'), + 'utf8' + ).replace(/\r\n/g, '\n'); // required for windows + const version = new PubspecYaml({ + version: Version.parse('0.6.0'), + }); + const newContent = version.updateContent(oldContent); + snapshot(newContent); + }); + + it('updates prerelease version with build number in pubspec.yaml file', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './pubspec_prerelease_with_build_no.yaml'), + 'utf8' + ).replace(/\r\n/g, '\n'); // required for windows + const version = new PubspecYaml({ + version: Version.parse('0.6.0'), + }); + const newContent = version.updateContent(oldContent); + snapshot(newContent); + }); }); });