@nx/gradle 21.4.0-beta.11 → 21.4.0-beta.12

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/migrations.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "factory": "./src/migrations/21-3-11/change-plugin-version-0-1-4"
50
50
  },
51
51
  "change-plugin-version-0-1-5": {
52
- "version": "21.4.0-beta.8",
52
+ "version": "21.4.0-beta.12",
53
53
  "cli": "nx",
54
54
  "description": "Change dev.nx.gradle.project-graph to version 0.1.5 in build file",
55
55
  "factory": "./src/migrations/21-4-0/change-plugin-version-0-1-5"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "21.4.0-beta.11",
3
+ "version": "21.4.0-beta.12",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
6
6
  "repository": {
@@ -35,8 +35,9 @@
35
35
  "migrations": "./migrations.json"
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "21.4.0-beta.11",
39
- "nx": "21.4.0-beta.11"
38
+ "@nx/devkit": "21.4.0-beta.12",
39
+ "nx": "21.4.0-beta.12",
40
+ "smol-toml": "^1.4.1"
40
41
  },
41
42
  "publishConfig": {
42
43
  "access": "public"
@@ -1 +1 @@
1
- {"version":3,"file":"change-plugin-version-0-1-5.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/migrations/21-4-0/change-plugin-version-0-1-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAM9C,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,iBAS9C"}
1
+ {"version":3,"file":"change-plugin-version-0-1-5.d.ts","sourceRoot":"","sources":["../../../../../../packages/gradle/src/migrations/21-4-0/change-plugin-version-0-1-5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,YAAY,CAAC;AAO9C,wBAA8B,MAAM,CAAC,IAAI,EAAE,IAAI,iBAgB9C"}
@@ -4,6 +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 version_catalog_utils_1 = require("../../utils/version-catalog-utils");
7
8
  /* Change the plugin version to 0.1.5
8
9
  */
9
10
  async function update(tree) {
@@ -14,5 +15,9 @@ async function update(tree) {
14
15
  if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
15
16
  return;
16
17
  }
17
- await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, '0.1.5');
18
+ const gradlePluginVersionToUpdate = '0.1.5';
19
+ // Update version in version catalogs first
20
+ await (0, version_catalog_utils_1.updateNxPluginVersionInCatalogs)(tree, gradlePluginVersionToUpdate);
21
+ // Then update in build.gradle(.kts) files
22
+ await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, gradlePluginVersionToUpdate);
18
23
  }
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,128 @@
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
+ }