From 18ae348e832264337816cc7d038d0594707e8f01 Mon Sep 17 00:00:00 2001 From: Nestor Quezada Date: Wed, 11 Mar 2026 14:53:21 +0100 Subject: [PATCH] feat: add Dart pubspec.yaml updater with support for prerelease and build numbers --- src/updaters/dart/pubspec-yaml.ts | 2 +- .../updaters/fixtures/pubspec_prerelease.yaml | 8 +++++++ .../pubspec_prerelease_with_build_no.yaml | 8 +++++++ test/updaters/pubspec-yaml.ts | 23 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/updaters/fixtures/pubspec_prerelease.yaml create mode 100644 test/updaters/fixtures/pubspec_prerelease_with_build_no.yaml 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); + }); }); });