Skip to content

Commit 04a92a0

Browse files
committed
fix: currentVersion and manual bump
1 parent d4c2ef0 commit 04a92a0

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

scripts/release/updateAPIVersions.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fsp from 'fs/promises';
22

33
import dotenv from 'dotenv';
44
import yaml from 'js-yaml';
5+
import type { ReleaseType } from 'semver';
56

67
import clientsConfig from '../../config/clients.config.json' assert { type: 'json' };
78
import openapiConfig from '../../config/openapitools.json' assert { type: 'json' };
@@ -110,7 +111,7 @@ export async function updateAPIVersions(
110111
versionsToRelease
111112
)) {
112113
if (lang === 'dart') {
113-
await updateDartPackages(changelog[lang]!);
114+
await updateDartPackages(changelog[lang]!, releaseType);
114115

115116
continue;
116117
}
@@ -136,14 +137,11 @@ export async function updateAPIVersions(
136137
* Updates packages versions and generates the changelog.
137138
* Documentation: {@link https://melos.invertase.dev/commands/version | melos version}.
138139
*/
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') });
147145

148146
// Update packages configs based on generated versions
149147
for (const gen of Object.values(GENERATORS)) {
@@ -152,13 +150,22 @@ async function updateDartPackages(changelog: string): Promise<void> {
152150
}
153151

154152
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');
157164
if (!newVersion) {
158165
throw new Error(`Failed to bump '${gen.packageName}'.`);
159166
}
160-
additionalProperties.packageVersion = newVersion;
161-
additionalProperties.packageName = undefined;
167+
gen.additionalProperties.packageVersion = newVersion;
168+
gen.additionalProperties.packageName = undefined;
162169

163170
if (gen.client === 'algoliasearch') {
164171
clientsConfig.dart.packageVersion = newVersion;
@@ -189,15 +196,18 @@ async function updateDartPackages(changelog: string): Promise<void> {
189196
/**
190197
* Get 'version' from pubspec.yaml file.
191198
*/
192-
async function getPubspecVersion(
193-
filePath: string
199+
async function getPubspecField(
200+
filePath: string,
201+
field: string
194202
): Promise<string | undefined> {
195203
try {
196204
const fileContent = await fsp.readFile(
197205
toAbsolutePath(`${filePath}/pubspec.yaml`),
198206
'utf8'
199207
);
200-
return (yaml.load(fileContent) as { version?: string }).version;
208+
const pubspec = yaml.load(fileContent) as Record<string, any>;
209+
210+
return pubspec[field];
201211
} catch (error) {
202212
throw new Error(`Error reading the file: ${error}`);
203213
}

0 commit comments

Comments
 (0)