@nx/gradle 21.5.0-canary.20250822-2e39402 → 21.5.0-canary.20250823-a93e74e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/migrations/21-4-0/change-plugin-version-0-1-5.js +3 -3
- package/src/utils/version-catalog-ast-utils.d.ts +15 -0
- package/src/utils/version-catalog-ast-utils.d.ts.map +1 -0
- package/src/utils/version-catalog-ast-utils.js +334 -0
- package/src/utils/version-catalog-utils.d.ts +0 -7
- package/src/utils/version-catalog-utils.d.ts.map +0 -1
- package/src/utils/version-catalog-utils.js +0 -128
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/gradle",
|
3
|
-
"version": "21.5.0-canary.
|
3
|
+
"version": "21.5.0-canary.20250823-a93e74e",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
|
6
6
|
"repository": {
|
@@ -35,9 +35,9 @@
|
|
35
35
|
"migrations": "./migrations.json"
|
36
36
|
},
|
37
37
|
"dependencies": {
|
38
|
-
"@nx/devkit": "21.5.0-canary.
|
39
|
-
"nx": "21.5.0-canary.
|
40
|
-
"
|
38
|
+
"@nx/devkit": "21.5.0-canary.20250823-a93e74e",
|
39
|
+
"nx": "21.5.0-canary.20250823-a93e74e",
|
40
|
+
"toml-eslint-parser": "^0.10.0"
|
41
41
|
},
|
42
42
|
"publishConfig": {
|
43
43
|
"access": "public"
|
@@ -4,7 +4,7 @@ exports.default = update;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const has_gradle_plugin_1 = require("../../utils/has-gradle-plugin");
|
6
6
|
const gradle_project_graph_plugin_utils_1 = require("../../generators/init/gradle-project-graph-plugin-utils");
|
7
|
-
const
|
7
|
+
const version_catalog_ast_utils_1 = require("../../utils/version-catalog-ast-utils");
|
8
8
|
/* Change the plugin version to 0.1.5
|
9
9
|
*/
|
10
10
|
async function update(tree) {
|
@@ -16,8 +16,8 @@ async function update(tree) {
|
|
16
16
|
return;
|
17
17
|
}
|
18
18
|
const gradlePluginVersionToUpdate = '0.1.5';
|
19
|
-
// Update version in version catalogs
|
20
|
-
await (0,
|
19
|
+
// Update version in version catalogs using AST-based approach to preserve formatting
|
20
|
+
await (0, version_catalog_ast_utils_1.updateNxPluginVersionInCatalogsAst)(tree, gradlePluginVersionToUpdate);
|
21
21
|
// Then update in build.gradle(.kts) files
|
22
22
|
await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, gradlePluginVersionToUpdate);
|
23
23
|
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
2
|
+
export declare function findVersionCatalogFiles(tree: Tree): Promise<string[]>;
|
3
|
+
/**
|
4
|
+
* Updates a plugin version in a TOML catalog while preserving formatting
|
5
|
+
*/
|
6
|
+
export declare function updatePluginVersionInCatalogAst(sourceText: string, pluginName: string, newVersion: string): string | null;
|
7
|
+
/**
|
8
|
+
* Extracts plugin version from catalog using AST parsing
|
9
|
+
*/
|
10
|
+
export declare function extractPluginVersionFromCatalogAst(sourceText: string, pluginName: string): string | null;
|
11
|
+
/**
|
12
|
+
* Updates Nx plugin version in all catalog files using AST-based approach
|
13
|
+
*/
|
14
|
+
export declare function updateNxPluginVersionInCatalogsAst(tree: Tree, expectedVersion: string): Promise<boolean>;
|
15
|
+
//# sourceMappingURL=version-catalog-ast-utils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"version-catalog-ast-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/gradle/src/utils/version-catalog-ast-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,IAAI,EAAE,MAAM,YAAY,CAAC;AAI7C,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAW3E;AAiKD;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CA6Gf;AAED;;GAEG;AACH,wBAAgB,kCAAkC,CAChD,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CA4Df;AAED;;GAEG;AACH,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,IAAI,EACV,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAkClB"}
|
@@ -0,0 +1,334 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.findVersionCatalogFiles = findVersionCatalogFiles;
|
4
|
+
exports.updatePluginVersionInCatalogAst = updatePluginVersionInCatalogAst;
|
5
|
+
exports.extractPluginVersionFromCatalogAst = extractPluginVersionFromCatalogAst;
|
6
|
+
exports.updateNxPluginVersionInCatalogsAst = updateNxPluginVersionInCatalogsAst;
|
7
|
+
const devkit_1 = require("@nx/devkit");
|
8
|
+
const toml_eslint_parser_1 = require("toml-eslint-parser");
|
9
|
+
const versions_1 = require("./versions");
|
10
|
+
async function findVersionCatalogFiles(tree) {
|
11
|
+
const versionCatalogPaths = [];
|
12
|
+
const globFiles = await (0, devkit_1.globAsync)(tree, ['**/gradle/*.versions.toml']);
|
13
|
+
for (const filePath of globFiles) {
|
14
|
+
if (!versionCatalogPaths.includes(filePath)) {
|
15
|
+
versionCatalogPaths.push(filePath);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
return versionCatalogPaths;
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Reconstructs TOML content from source text with selective replacements
|
22
|
+
* based on AST node ranges. This preserves all original formatting.
|
23
|
+
*/
|
24
|
+
function reconstructTomlWithUpdates(sourceText, updates) {
|
25
|
+
// Sort updates by start position in reverse order to apply from end to beginning
|
26
|
+
const sortedUpdates = updates.sort((a, b) => b.start - a.start);
|
27
|
+
let result = sourceText;
|
28
|
+
for (const update of sortedUpdates) {
|
29
|
+
result =
|
30
|
+
result.slice(0, update.start) +
|
31
|
+
update.replacement +
|
32
|
+
result.slice(update.end);
|
33
|
+
}
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* Finds a key-value pair in a TOML table by key name
|
38
|
+
*/
|
39
|
+
function findKeyValueInTable(table, keyName) {
|
40
|
+
if (!table.body)
|
41
|
+
return null;
|
42
|
+
for (const item of table.body) {
|
43
|
+
if (item.type === 'TOMLKeyValue') {
|
44
|
+
if (getKeyName(item.key) === keyName) {
|
45
|
+
return item;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return null;
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Gets the string representation of a TOML key
|
53
|
+
*/
|
54
|
+
function getKeyName(key) {
|
55
|
+
if (key.type === 'TOMLKey' && key.keys && key.keys.length > 0) {
|
56
|
+
// Handle TOMLKey type which contains an array of keys (for dotted keys like version.ref)
|
57
|
+
return key.keys
|
58
|
+
.map((k) => {
|
59
|
+
if (k.type === 'TOMLBare') {
|
60
|
+
return k.name;
|
61
|
+
}
|
62
|
+
else if (k.type === 'TOMLQuoted') {
|
63
|
+
return k.value;
|
64
|
+
}
|
65
|
+
return '';
|
66
|
+
})
|
67
|
+
.join('.');
|
68
|
+
}
|
69
|
+
else if (key.type === 'TOMLBare') {
|
70
|
+
return key.name;
|
71
|
+
}
|
72
|
+
else if (key.type === 'TOMLQuoted') {
|
73
|
+
return key.value;
|
74
|
+
}
|
75
|
+
return '';
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* Gets the string value from a TOML value node
|
79
|
+
*/
|
80
|
+
function getStringValue(value) {
|
81
|
+
if (value.type === 'TOMLValue' && value.kind === 'string') {
|
82
|
+
return value.value;
|
83
|
+
}
|
84
|
+
return null;
|
85
|
+
}
|
86
|
+
/**
|
87
|
+
* Finds plugin configuration in the plugins table
|
88
|
+
*/
|
89
|
+
function findPluginConfig(pluginsTable, pluginName) {
|
90
|
+
if (!pluginsTable.body)
|
91
|
+
return null;
|
92
|
+
for (const item of pluginsTable.body) {
|
93
|
+
if (item.type === 'TOMLKeyValue') {
|
94
|
+
const value = item.value;
|
95
|
+
if (value.type === 'TOMLValue' && value.kind === 'string') {
|
96
|
+
// Simple format: plugin = "id:version"
|
97
|
+
const stringValue = value.value;
|
98
|
+
if (stringValue.startsWith(`${pluginName}:`)) {
|
99
|
+
return { keyValue: item, format: 'simple' };
|
100
|
+
}
|
101
|
+
}
|
102
|
+
else if (value.type === 'TOMLInlineTable') {
|
103
|
+
// Object format: { id = "plugin.name", version = "1.0.0" }
|
104
|
+
const idKeyValue = findKeyValueInTable(value, 'id');
|
105
|
+
if (idKeyValue) {
|
106
|
+
const idValue = getStringValue(idKeyValue.value);
|
107
|
+
if (idValue === pluginName) {
|
108
|
+
return { keyValue: item, format: 'object' };
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
114
|
+
return null;
|
115
|
+
}
|
116
|
+
/**
|
117
|
+
* Finds the plugins table in the AST
|
118
|
+
*/
|
119
|
+
function findPluginsTable(ast) {
|
120
|
+
// Look through all top-level elements
|
121
|
+
for (const topLevel of ast.body) {
|
122
|
+
if (topLevel.type === 'TOMLTopLevelTable') {
|
123
|
+
// Look through the body of the top-level table for [plugins] table
|
124
|
+
for (const item of topLevel.body) {
|
125
|
+
if (item.type === 'TOMLTable' && item.key && item.key.keys) {
|
126
|
+
const tableName = item.key.keys
|
127
|
+
.map((key) => getKeyName(key))
|
128
|
+
.join('.');
|
129
|
+
if (tableName === 'plugins') {
|
130
|
+
return item;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
// If no [plugins] table found, check if there's a plugins key in the root table
|
135
|
+
const pluginsKeyValue = findKeyValueInTable(topLevel, 'plugins');
|
136
|
+
if (pluginsKeyValue?.value.type === 'TOMLInlineTable') {
|
137
|
+
return pluginsKeyValue.value;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
return null;
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* Finds the versions table in the AST
|
145
|
+
*/
|
146
|
+
function findVersionsTable(ast) {
|
147
|
+
// Look through all top-level elements
|
148
|
+
for (const topLevel of ast.body) {
|
149
|
+
if (topLevel.type === 'TOMLTopLevelTable') {
|
150
|
+
// Look through the body of the top-level table for [versions] table
|
151
|
+
for (const item of topLevel.body) {
|
152
|
+
if (item.type === 'TOMLTable' && item.key && item.key.keys) {
|
153
|
+
const tableName = item.key.keys
|
154
|
+
.map((key) => getKeyName(key))
|
155
|
+
.join('.');
|
156
|
+
if (tableName === 'versions') {
|
157
|
+
return item;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
return null;
|
164
|
+
}
|
165
|
+
/**
|
166
|
+
* Updates a plugin version in a TOML catalog while preserving formatting
|
167
|
+
*/
|
168
|
+
function updatePluginVersionInCatalogAst(sourceText, pluginName, newVersion) {
|
169
|
+
try {
|
170
|
+
const ast = (0, toml_eslint_parser_1.parseTOML)(sourceText);
|
171
|
+
const updates = [];
|
172
|
+
const pluginsTable = findPluginsTable(ast);
|
173
|
+
if (!pluginsTable) {
|
174
|
+
return null; // No plugins table found
|
175
|
+
}
|
176
|
+
const pluginConfig = findPluginConfig(pluginsTable, pluginName);
|
177
|
+
if (!pluginConfig) {
|
178
|
+
return null; // Plugin not found
|
179
|
+
}
|
180
|
+
const { keyValue, format } = pluginConfig;
|
181
|
+
if (format === 'simple') {
|
182
|
+
// Update simple format: "plugin:version" -> "plugin:newVersion"
|
183
|
+
const value = keyValue.value;
|
184
|
+
const newValue = `${pluginName}:${newVersion}`;
|
185
|
+
// Preserve the quote style
|
186
|
+
const quote = value.style === 'basic' ? '"' : "'";
|
187
|
+
const replacement = `${quote}${newValue}${quote}`;
|
188
|
+
updates.push({
|
189
|
+
start: value.range[0],
|
190
|
+
end: value.range[1],
|
191
|
+
replacement,
|
192
|
+
});
|
193
|
+
}
|
194
|
+
else if (format === 'object') {
|
195
|
+
// Handle object format
|
196
|
+
const inlineTable = keyValue.value;
|
197
|
+
// First, try to find direct version
|
198
|
+
const versionKeyValue = findKeyValueInTable(inlineTable, 'version');
|
199
|
+
if (versionKeyValue) {
|
200
|
+
const versionValue = versionKeyValue.value;
|
201
|
+
if (versionValue.type === 'TOMLValue' &&
|
202
|
+
versionValue.kind === 'string') {
|
203
|
+
// Direct version update
|
204
|
+
const quote = versionValue.style === 'basic' ? '"' : "'";
|
205
|
+
const replacement = `${quote}${newVersion}${quote}`;
|
206
|
+
updates.push({
|
207
|
+
start: versionValue.range[0],
|
208
|
+
end: versionValue.range[1],
|
209
|
+
replacement,
|
210
|
+
});
|
211
|
+
}
|
212
|
+
}
|
213
|
+
else {
|
214
|
+
// Check for version.ref pattern - look for either quoted or unquoted key
|
215
|
+
let versionRefKeyValue = findKeyValueInTable(inlineTable, 'version.ref');
|
216
|
+
if (!versionRefKeyValue) {
|
217
|
+
// Try with quotes since TOML inline tables may require quoted keys for dotted keys
|
218
|
+
versionRefKeyValue = findKeyValueInTable(inlineTable, '"version.ref"');
|
219
|
+
}
|
220
|
+
if (versionRefKeyValue) {
|
221
|
+
// This means we need to update the referenced version in the [versions] table
|
222
|
+
const refValue = getStringValue(versionRefKeyValue.value);
|
223
|
+
if (refValue) {
|
224
|
+
const versionsTable = findVersionsTable(ast);
|
225
|
+
if (versionsTable) {
|
226
|
+
const referencedVersion = findKeyValueInTable(versionsTable, refValue);
|
227
|
+
if (referencedVersion) {
|
228
|
+
const refVersionValue = referencedVersion.value;
|
229
|
+
if (refVersionValue.type === 'TOMLValue' &&
|
230
|
+
refVersionValue.kind === 'string') {
|
231
|
+
const quote = refVersionValue.style === 'basic' ? '"' : "'";
|
232
|
+
const replacement = `${quote}${newVersion}${quote}`;
|
233
|
+
updates.push({
|
234
|
+
start: refVersionValue.range[0],
|
235
|
+
end: refVersionValue.range[1],
|
236
|
+
replacement,
|
237
|
+
});
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
if (updates.length === 0) {
|
246
|
+
return null;
|
247
|
+
}
|
248
|
+
return reconstructTomlWithUpdates(sourceText, updates);
|
249
|
+
}
|
250
|
+
catch (error) {
|
251
|
+
console.error('Error parsing TOML with AST:', error);
|
252
|
+
return null;
|
253
|
+
}
|
254
|
+
}
|
255
|
+
/**
|
256
|
+
* Extracts plugin version from catalog using AST parsing
|
257
|
+
*/
|
258
|
+
function extractPluginVersionFromCatalogAst(sourceText, pluginName) {
|
259
|
+
try {
|
260
|
+
const ast = (0, toml_eslint_parser_1.parseTOML)(sourceText);
|
261
|
+
const pluginsTable = findPluginsTable(ast);
|
262
|
+
if (!pluginsTable) {
|
263
|
+
return null;
|
264
|
+
}
|
265
|
+
const pluginConfig = findPluginConfig(pluginsTable, pluginName);
|
266
|
+
if (!pluginConfig) {
|
267
|
+
return null;
|
268
|
+
}
|
269
|
+
const { keyValue, format } = pluginConfig;
|
270
|
+
if (format === 'simple') {
|
271
|
+
// Extract from simple format: "plugin:version"
|
272
|
+
const value = keyValue.value;
|
273
|
+
const stringValue = value.value;
|
274
|
+
return stringValue.split(':')[1] || null;
|
275
|
+
}
|
276
|
+
else if (format === 'object') {
|
277
|
+
// Extract from object format
|
278
|
+
const inlineTable = keyValue.value;
|
279
|
+
// First, try to find direct version
|
280
|
+
const versionKeyValue = findKeyValueInTable(inlineTable, 'version');
|
281
|
+
if (versionKeyValue) {
|
282
|
+
return getStringValue(versionKeyValue.value);
|
283
|
+
}
|
284
|
+
// Check for version.ref pattern - look for either quoted or unquoted key
|
285
|
+
let versionRefKeyValue = findKeyValueInTable(inlineTable, 'version.ref');
|
286
|
+
if (!versionRefKeyValue) {
|
287
|
+
// Try with quotes since TOML inline tables may require quoted keys for dotted keys
|
288
|
+
versionRefKeyValue = findKeyValueInTable(inlineTable, '"version.ref"');
|
289
|
+
}
|
290
|
+
if (versionRefKeyValue) {
|
291
|
+
const refValue = getStringValue(versionRefKeyValue.value);
|
292
|
+
if (refValue) {
|
293
|
+
const versionsTable = findVersionsTable(ast);
|
294
|
+
if (versionsTable) {
|
295
|
+
const referencedVersion = findKeyValueInTable(versionsTable, refValue);
|
296
|
+
if (referencedVersion) {
|
297
|
+
return getStringValue(referencedVersion.value);
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}
|
303
|
+
return null;
|
304
|
+
}
|
305
|
+
catch (error) {
|
306
|
+
console.error('Error parsing TOML with AST:', error);
|
307
|
+
return null;
|
308
|
+
}
|
309
|
+
}
|
310
|
+
/**
|
311
|
+
* Updates Nx plugin version in all catalog files using AST-based approach
|
312
|
+
*/
|
313
|
+
async function updateNxPluginVersionInCatalogsAst(tree, expectedVersion) {
|
314
|
+
const catalogFiles = await findVersionCatalogFiles(tree);
|
315
|
+
let updated = false;
|
316
|
+
for (const catalogPath of catalogFiles) {
|
317
|
+
if (!tree.exists(catalogPath)) {
|
318
|
+
continue;
|
319
|
+
}
|
320
|
+
const content = tree.read(catalogPath, 'utf-8');
|
321
|
+
if (!content) {
|
322
|
+
continue;
|
323
|
+
}
|
324
|
+
const currentVersion = extractPluginVersionFromCatalogAst(content, versions_1.gradleProjectGraphPluginName);
|
325
|
+
if (currentVersion && currentVersion !== expectedVersion) {
|
326
|
+
const updatedContent = updatePluginVersionInCatalogAst(content, versions_1.gradleProjectGraphPluginName, expectedVersion);
|
327
|
+
if (updatedContent) {
|
328
|
+
tree.write(catalogPath, updatedContent);
|
329
|
+
updated = true;
|
330
|
+
}
|
331
|
+
}
|
332
|
+
}
|
333
|
+
return updated;
|
334
|
+
}
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { Tree } from '@nx/devkit';
|
2
|
-
import { TomlTable } from 'smol-toml';
|
3
|
-
export declare function findVersionCatalogFiles(tree: Tree): Promise<string[]>;
|
4
|
-
export declare function updatePluginVersionInCatalog(catalogContent: TomlTable, pluginName: string, newVersion: string): string;
|
5
|
-
export declare function extractPluginVersionFromCatalog(catalogContent: TomlTable, pluginName: string): string | null;
|
6
|
-
export declare function updateNxPluginVersionInCatalogs(tree: Tree, expectedVersion: string): Promise<boolean>;
|
7
|
-
//# sourceMappingURL=version-catalog-utils.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"version-catalog-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/gradle/src/utils/version-catalog-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAa,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAW3E;AAED,wBAAgB,4BAA4B,CAC1C,cAAc,EAAE,SAAS,EACzB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,MAAM,CA8CR;AAED,wBAAgB,+BAA+B,CAC7C,cAAc,EAAE,SAAS,EACzB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CAwCf;AAED,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,IAAI,EACV,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAoClB"}
|
@@ -1,128 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.findVersionCatalogFiles = findVersionCatalogFiles;
|
4
|
-
exports.updatePluginVersionInCatalog = updatePluginVersionInCatalog;
|
5
|
-
exports.extractPluginVersionFromCatalog = extractPluginVersionFromCatalog;
|
6
|
-
exports.updateNxPluginVersionInCatalogs = updateNxPluginVersionInCatalogs;
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
8
|
-
const TOML = require("smol-toml");
|
9
|
-
const versions_1 = require("./versions");
|
10
|
-
async function findVersionCatalogFiles(tree) {
|
11
|
-
const versionCatalogPaths = [];
|
12
|
-
const globFiles = await (0, devkit_1.globAsync)(tree, ['**/gradle/*.versions.toml']);
|
13
|
-
for (const filePath of globFiles) {
|
14
|
-
if (!versionCatalogPaths.includes(filePath)) {
|
15
|
-
versionCatalogPaths.push(filePath);
|
16
|
-
}
|
17
|
-
}
|
18
|
-
return versionCatalogPaths;
|
19
|
-
}
|
20
|
-
function updatePluginVersionInCatalog(catalogContent, pluginName, newVersion) {
|
21
|
-
if (catalogContent.plugins) {
|
22
|
-
for (const [pluginAlias, pluginConfig] of Object.entries(catalogContent.plugins)) {
|
23
|
-
if (typeof pluginConfig === 'string') {
|
24
|
-
// Handle simple format: plugin = "id:version"
|
25
|
-
if (pluginConfig.startsWith(`${pluginName}:`)) {
|
26
|
-
catalogContent.plugins[pluginAlias] = `${pluginName}:${newVersion}`;
|
27
|
-
break;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
else if (typeof pluginConfig === 'object' && pluginConfig !== null) {
|
31
|
-
// Handle object format: { id = "plugin.name", version = "1.0.0" }
|
32
|
-
const config = pluginConfig;
|
33
|
-
if (config.id === pluginName) {
|
34
|
-
if (config.version && typeof config.version === 'string') {
|
35
|
-
// Direct version
|
36
|
-
config.version = newVersion;
|
37
|
-
}
|
38
|
-
else if (config.version &&
|
39
|
-
typeof config.version === 'object' &&
|
40
|
-
config.version.ref &&
|
41
|
-
catalogContent.versions) {
|
42
|
-
// Version reference in object form: version = { ref = "nx-version" }
|
43
|
-
const versionRef = config.version.ref;
|
44
|
-
if (catalogContent.versions[versionRef]) {
|
45
|
-
catalogContent.versions[versionRef] = newVersion;
|
46
|
-
}
|
47
|
-
}
|
48
|
-
else if (config['version.ref'] && catalogContent.versions) {
|
49
|
-
let versionRef = config['version.ref'];
|
50
|
-
// Handle the case where version.ref might be an object with ref property
|
51
|
-
if (typeof versionRef === 'object' && versionRef.ref) {
|
52
|
-
versionRef = versionRef.ref;
|
53
|
-
}
|
54
|
-
if (catalogContent.versions[versionRef]) {
|
55
|
-
catalogContent.versions[versionRef] = newVersion;
|
56
|
-
}
|
57
|
-
}
|
58
|
-
break;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
return TOML.stringify(catalogContent);
|
64
|
-
}
|
65
|
-
function extractPluginVersionFromCatalog(catalogContent, pluginName) {
|
66
|
-
if (!catalogContent.plugins) {
|
67
|
-
return null;
|
68
|
-
}
|
69
|
-
for (const pluginConfig of Object.values(catalogContent.plugins)) {
|
70
|
-
if (typeof pluginConfig === 'string') {
|
71
|
-
// Handle simple format: plugin = "id:version"
|
72
|
-
if (pluginConfig.startsWith(`${pluginName}:`)) {
|
73
|
-
return pluginConfig.split(':')[1];
|
74
|
-
}
|
75
|
-
}
|
76
|
-
else if (typeof pluginConfig === 'object' && pluginConfig !== null) {
|
77
|
-
// Handle object format: { id = "plugin.name", version = "1.0.0" }
|
78
|
-
const config = pluginConfig;
|
79
|
-
if (config.id === pluginName) {
|
80
|
-
if (config.version && typeof config.version === 'string') {
|
81
|
-
// Direct version
|
82
|
-
return config.version;
|
83
|
-
}
|
84
|
-
else if (config.version &&
|
85
|
-
typeof config.version === 'object' &&
|
86
|
-
config.version.ref &&
|
87
|
-
catalogContent.versions) {
|
88
|
-
// Version reference in object form: version = { ref = "nx-version" }
|
89
|
-
return catalogContent.versions[config.version.ref] || null;
|
90
|
-
}
|
91
|
-
else if (config['version.ref'] && catalogContent.versions) {
|
92
|
-
// Version reference - look up the referenced version
|
93
|
-
let versionRef = config['version.ref'];
|
94
|
-
// Handle the case where version.ref might be an object with ref property
|
95
|
-
if (typeof versionRef === 'object' && versionRef.ref) {
|
96
|
-
versionRef = versionRef.ref;
|
97
|
-
}
|
98
|
-
return catalogContent.versions[versionRef] || null;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
return null;
|
104
|
-
}
|
105
|
-
async function updateNxPluginVersionInCatalogs(tree, expectedVersion) {
|
106
|
-
const catalogFiles = await findVersionCatalogFiles(tree);
|
107
|
-
let updated = false;
|
108
|
-
for (const catalogPath of catalogFiles) {
|
109
|
-
if (!tree.exists(catalogPath)) {
|
110
|
-
continue;
|
111
|
-
}
|
112
|
-
const content = tree.read(catalogPath, 'utf-8');
|
113
|
-
if (!content) {
|
114
|
-
continue;
|
115
|
-
}
|
116
|
-
const parsedToml = TOML.parse(content);
|
117
|
-
if (!parsedToml.plugins) {
|
118
|
-
continue;
|
119
|
-
}
|
120
|
-
const currentVersion = extractPluginVersionFromCatalog(parsedToml, versions_1.gradleProjectGraphPluginName);
|
121
|
-
if (currentVersion && currentVersion !== expectedVersion) {
|
122
|
-
const updatedContent = updatePluginVersionInCatalog(parsedToml, versions_1.gradleProjectGraphPluginName, expectedVersion);
|
123
|
-
tree.write(catalogPath, updatedContent);
|
124
|
-
updated = true;
|
125
|
-
}
|
126
|
-
}
|
127
|
-
return updated;
|
128
|
-
}
|