@@ -2,6 +2,7 @@ import fsp from 'fs/promises';
2
2
3
3
import dotenv from 'dotenv' ;
4
4
import yaml from 'js-yaml' ;
5
+ import type { ReleaseType } from 'semver' ;
5
6
6
7
import clientsConfig from '../../config/clients.config.json' assert { type : 'json' } ;
7
8
import openapiConfig from '../../config/openapitools.json' assert { type : 'json' } ;
@@ -110,7 +111,7 @@ export async function updateAPIVersions(
110
111
versionsToRelease
111
112
) ) {
112
113
if ( lang === 'dart' ) {
113
- await updateDartPackages ( changelog [ lang ] ! ) ;
114
+ await updateDartPackages ( changelog [ lang ] ! , releaseType ) ;
114
115
115
116
continue ;
116
117
}
@@ -136,14 +137,11 @@ export async function updateAPIVersions(
136
137
* Updates packages versions and generates the changelog.
137
138
* Documentation: {@link https://melos.invertase.dev/commands/version | melos version}.
138
139
*/
139
- async function updateDartPackages ( changelog : string ) : Promise < void > {
140
- const cwd = getLanguageFolder ( 'dart' ) ;
141
-
142
- // Generate dart packages versions and changelogs
143
- await run (
144
- `dart pub get && melos version --no-changelog --no-git-tag-version --yes --diff ${ RELEASED_TAG } ` ,
145
- { cwd }
146
- ) ;
140
+ async function updateDartPackages (
141
+ changelog : string ,
142
+ releaseType : ReleaseType
143
+ ) : Promise < void > {
144
+ await run ( 'dart pub get' , { cwd : getLanguageFolder ( 'dart' ) } ) ;
147
145
148
146
// Update packages configs based on generated versions
149
147
for ( const gen of Object . values ( GENERATORS ) ) {
@@ -152,13 +150,22 @@ async function updateDartPackages(changelog: string): Promise<void> {
152
150
}
153
151
154
152
const currentVersion = gen . additionalProperties . packageVersion ;
155
- const { additionalProperties } = gen ;
156
- const newVersion = await getPubspecVersion ( gen . output ) ;
153
+ const packageName = await getPubspecField ( gen . output , 'name' ) ;
154
+ if ( ! packageName ) {
155
+ throw new Error ( `Unable to find packageName for '${ gen . packageName } '.` ) ;
156
+ }
157
+
158
+ await run (
159
+ `melos version --manual-version=${ packageName } :${ releaseType } --no-changelog --no-git-tag-version --yes --diff ${ RELEASED_TAG } ` ,
160
+ { cwd : gen . output }
161
+ ) ;
162
+
163
+ const newVersion = await getPubspecField ( gen . output , 'version' ) ;
157
164
if ( ! newVersion ) {
158
165
throw new Error ( `Failed to bump '${ gen . packageName } '.` ) ;
159
166
}
160
- additionalProperties . packageVersion = newVersion ;
161
- additionalProperties . packageName = undefined ;
167
+ gen . additionalProperties . packageVersion = newVersion ;
168
+ gen . additionalProperties . packageName = undefined ;
162
169
163
170
if ( gen . client === 'algoliasearch' ) {
164
171
clientsConfig . dart . packageVersion = newVersion ;
@@ -189,15 +196,18 @@ async function updateDartPackages(changelog: string): Promise<void> {
189
196
/**
190
197
* Get 'version' from pubspec.yaml file.
191
198
*/
192
- async function getPubspecVersion (
193
- filePath : string
199
+ async function getPubspecField (
200
+ filePath : string ,
201
+ field : string
194
202
) : Promise < string | undefined > {
195
203
try {
196
204
const fileContent = await fsp . readFile (
197
205
toAbsolutePath ( `${ filePath } /pubspec.yaml` ) ,
198
206
'utf8'
199
207
) ;
200
- return ( yaml . load ( fileContent ) as { version ?: string } ) . version ;
208
+ const pubspec = yaml . load ( fileContent ) as Record < string , any > ;
209
+
210
+ return pubspec [ field ] ;
201
211
} catch ( error ) {
202
212
throw new Error ( `Error reading the file: ${ error } ` ) ;
203
213
}
0 commit comments