@nx/gradle 23.1.0-beta.6 → 23.1.0-beta.7

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.
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const has_gradle_plugin_1 = require("../../utils/has-gradle-plugin");
6
+ const gradle_project_graph_plugin_utils_1 = require("../../generators/init/gradle-project-graph-plugin-utils");
7
+ const version_catalog_ast_utils_1 = require("../../utils/version-catalog-ast-utils");
8
+ /* Change the plugin version to 0.1.24
9
+ */
10
+ async function update(tree) {
11
+ const nxJson = (0, devkit_1.readNxJson)(tree);
12
+ if (!nxJson) {
13
+ return;
14
+ }
15
+ if (!(0, has_gradle_plugin_1.hasGradlePlugin)(tree)) {
16
+ return;
17
+ }
18
+ const gradlePluginVersionToUpdate = '0.1.24';
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
+ // Then update in build.gradle(.kts) files
22
+ await (0, gradle_project_graph_plugin_utils_1.addNxProjectGraphPlugin)(tree, gradlePluginVersionToUpdate);
23
+ }
@@ -0,0 +1,21 @@
1
+ #### Change dev.nx.gradle.project-graph to version 0.1.24
2
+
3
+ Change dev.nx.gradle.project-graph to version 0.1.24 in build file
4
+
5
+ #### Sample Code Changes
6
+
7
+ ##### Before
8
+
9
+ ```text title="build.gradle"
10
+ plugins {
11
+ id "dev.nx.gradle.project-graph" version "0.1.23"
12
+ }
13
+ ```
14
+
15
+ ##### After
16
+
17
+ ```text title="build.gradle"
18
+ plugins {
19
+ id "dev.nx.gradle.project-graph" version "0.1.24"
20
+ }
21
+ ```
@@ -15,20 +15,20 @@ const createDependencies = async (options, context) => {
15
15
  const dependencies = [];
16
16
  dependenciesFromReport.forEach((dependencyFromPlugin) => {
17
17
  try {
18
- const source = (0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.source) || '.';
19
- const sourceProjectName = Object.values(context.projects).find((project) => source === project.root)?.name ?? dependencyFromPlugin.source;
20
- const target = (0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.target) || '.';
21
- const targetProjectName = Object.values(context.projects).find((project) => target === project.root)?.name ?? dependencyFromPlugin.target;
18
+ // Report paths are workspace-relative with `/` separators
19
+ const sourceProjectName = Object.values(context.projects).find((project) => dependencyFromPlugin.source === project.root)?.name ?? dependencyFromPlugin.source;
20
+ const targetProjectName = Object.values(context.projects).find((project) => dependencyFromPlugin.target === project.root)?.name ?? dependencyFromPlugin.target;
21
+ const sourceFile = dependencyFromPlugin.sourceFile;
22
22
  if (!sourceProjectName ||
23
23
  !targetProjectName ||
24
- !(0, node_fs_1.existsSync)(dependencyFromPlugin.sourceFile)) {
24
+ !(0, node_fs_1.existsSync)((0, node_path_1.join)(devkit_1.workspaceRoot, sourceFile))) {
25
25
  return;
26
26
  }
27
27
  const dependency = {
28
28
  source: sourceProjectName,
29
29
  target: targetProjectName,
30
30
  type: devkit_1.DependencyType.static,
31
- sourceFile: (0, devkit_1.normalizePath)((0, node_path_1.relative)(devkit_1.workspaceRoot, dependencyFromPlugin.sourceFile)),
31
+ sourceFile,
32
32
  };
33
33
  (0, devkit_1.validateDependency)(dependency, context);
34
34
  dependencies.push(dependency);
@@ -88,9 +88,10 @@ exports.createNodes = [
88
88
  const gradleFilePath = allBuildFiles[i];
89
89
  const projectRoot = buildFileProjectRoots[i];
90
90
  const hash = buildFileHashes[i];
91
- // Get project from cache or nodes
91
+ // Get project from cache or nodes (report keys are workspace-relative
92
+ // with `/` separators)
92
93
  if (!pluginCache.has(hash)) {
93
- const nodeProject = nodes[projectRoot] ?? nodes[(0, node_path_1.join)(devkit_1.workspaceRoot, projectRoot)];
94
+ const nodeProject = nodes[(0, devkit_1.normalizePath)(projectRoot)];
94
95
  if (nodeProject) {
95
96
  pluginCache.set(hash, nodeProject);
96
97
  }
@@ -10,6 +10,8 @@ export interface ProjectGraphReport {
10
10
  }
11
11
  export interface ProjectGraphReportCache extends ProjectGraphReport {
12
12
  hash: string;
13
+ /** The @nx/gradle version that wrote the cache. */
14
+ pluginVersion?: string;
13
15
  }
14
16
  export declare function writeProjectGraphReportToCache(cachePath: string, results: ProjectGraphReport, hash: string): void;
15
17
  export declare function getCurrentProjectGraphReport(): ProjectGraphReport;
@@ -10,6 +10,7 @@ const node_path_1 = require("node:path");
10
10
  const devkit_1 = require("@nx/devkit");
11
11
  const workspace_context_1 = require("nx/src/utils/workspace-context");
12
12
  const split_config_files_1 = require("../../utils/split-config-files");
13
+ const versions_1 = require("../../utils/versions");
13
14
  const cache_directory_1 = require("nx/src/utils/cache-directory");
14
15
  const get_project_graph_lines_1 = require("./get-project-graph-lines");
15
16
  const gradle_plugin_options_1 = require("./gradle-plugin-options");
@@ -18,7 +19,12 @@ function readProjectGraphReportCache(cachePath, hash) {
18
19
  const projectGraphReportCache = (0, node_fs_1.existsSync)(cachePath)
19
20
  ? (0, devkit_1.readJsonFile)(cachePath)
20
21
  : undefined;
21
- if (!projectGraphReportCache || projectGraphReportCache.hash !== hash) {
22
+ if (!projectGraphReportCache ||
23
+ projectGraphReportCache.hash !== hash ||
24
+ // Reports written by other @nx/gradle versions may use a different format
25
+ // (e.g. absolute machine paths before 0.1.24) — regenerate instead of
26
+ // trusting them, including when restored from another machine's cache.
27
+ projectGraphReportCache.pluginVersion !== versions_1.nxVersion) {
22
28
  return;
23
29
  }
24
30
  return projectGraphReportCache;
@@ -26,6 +32,7 @@ function readProjectGraphReportCache(cachePath, hash) {
26
32
  function writeProjectGraphReportToCache(cachePath, results, hash) {
27
33
  let projectGraphReportJson = {
28
34
  hash,
35
+ pluginVersion: versions_1.nxVersion,
29
36
  ...results,
30
37
  };
31
38
  try {
@@ -97,6 +104,12 @@ async function populateProjectGraph(workspaceRoot, gradlewFiles, options) {
97
104
  const gradleProjectGraphReportEnd = performance.mark('gradleProjectGraphReport:end');
98
105
  performance.measure('gradleProjectGraphReport', gradleProjectGraphReportStart.name, gradleProjectGraphReportEnd.name);
99
106
  projectGraphReportCache = processNxProjectGraph(projectGraphLines);
107
+ // An empty report can be legitimate (e.g. no project produced nodes), but
108
+ // don't cache it so a transiently-degraded run cannot pin the workspace to
109
+ // a graph without gradle projects.
110
+ if (Object.keys(projectGraphReportCache.nodes).length === 0) {
111
+ return;
112
+ }
100
113
  writeProjectGraphReportToCache(projectGraphReportCachePath, projectGraphReportCache, gradleConfigHash);
101
114
  }
102
115
  function processNxProjectGraph(projectGraphLines) {
@@ -111,11 +124,17 @@ function processNxProjectGraph(projectGraphLines) {
111
124
  const line = projectGraphLines[index].trim();
112
125
  if (line.startsWith('> Task ') && line.endsWith(':nxProjectGraph')) {
113
126
  index++; // Skip the task line before searching for the JSON file path
127
+ // The task prints its report file path; stop searching at the next task
128
+ // header (e.g. the path was never printed) or the end of the output.
114
129
  while (index < projectGraphLines.length &&
115
- !projectGraphLines[index].trim().endsWith('.json')) {
130
+ !projectGraphLines[index].trim().endsWith('.json') &&
131
+ !projectGraphLines[index].trim().startsWith('> Task ')) {
116
132
  index++;
117
133
  }
118
- const file = projectGraphLines[index];
134
+ const file = projectGraphLines[index]?.trim();
135
+ if (!file?.endsWith('.json')) {
136
+ continue;
137
+ }
119
138
  const projectGraphReportJson = (0, devkit_1.readJsonFile)(file);
120
139
  projectGraphReportForAllProjects.nodes = {
121
140
  ...projectGraphReportForAllProjects.nodes,
@@ -16,7 +16,19 @@ exports.GRADLE_TEST_FILES = [
16
16
  '**/src/test/groovy/**/*Tests.groovy',
17
17
  ];
18
18
  exports.gradleConfigGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`));
19
- exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...Array.from(exports.GRADLE_BUILD_FILES), ...Array.from(exports.GRADLEW_FILES), ...Array.from(exports.GRADLE_BUILD_FILES).map((file) => `**/${file}`), ...Array.from(exports.GRADLEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES, exports.GRADLE_VERSION_CATALOG_GLOB);
19
+ // Files that influence Gradle's configuration phase and therefore the project
20
+ // graph report: any *.gradle(.kts) script (build, settings, script plugins),
21
+ // gradle.properties, the wrapper pin, and buildSrc build logic.
22
+ const GRADLE_CONFIG_FILE_PATTERNS = [
23
+ '*.gradle',
24
+ '*.gradle.kts',
25
+ 'gradle.properties',
26
+ 'gradle/wrapper/gradle-wrapper.properties',
27
+ 'buildSrc/**/*.kt',
28
+ 'buildSrc/**/*.java',
29
+ 'buildSrc/**/*.groovy',
30
+ ];
31
+ exports.gradleConfigAndTestGlob = (0, globs_1.combineGlobPatterns)(...GRADLE_CONFIG_FILE_PATTERNS, ...GRADLE_CONFIG_FILE_PATTERNS.map((pattern) => `**/${pattern}`), ...Array.from(exports.GRADLEW_FILES), ...Array.from(exports.GRADLEW_FILES).map((file) => `**/${file}`), ...exports.GRADLE_TEST_FILES, exports.GRADLE_VERSION_CATALOG_GLOB);
20
32
  /**
21
33
  * This function split config files into build files, settings files, test files and project roots
22
34
  * @param files list of files to split
@@ -1,3 +1,3 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const gradleProjectGraphPluginName = "dev.nx.gradle.project-graph";
3
- export declare const gradleProjectGraphVersion = "0.1.23";
3
+ export declare const gradleProjectGraphVersion = "0.1.24";
@@ -4,4 +4,4 @@ exports.gradleProjectGraphVersion = exports.gradleProjectGraphPluginName = expor
4
4
  const path_1 = require("path");
5
5
  exports.nxVersion = require((0, path_1.join)('@nx/gradle', 'package.json')).version;
6
6
  exports.gradleProjectGraphPluginName = 'dev.nx.gradle.project-graph';
7
- exports.gradleProjectGraphVersion = '0.1.23';
7
+ exports.gradleProjectGraphVersion = '0.1.24';
package/migrations.json CHANGED
@@ -173,6 +173,13 @@
173
173
  "description": "Change dev.nx.gradle.project-graph to version 0.1.23 in build file",
174
174
  "factory": "./dist/src/migrations/23-1-0/change-plugin-version-0-1-23",
175
175
  "documentation": "./dist/src/migrations/23-1-0/change-plugin-version-0-1-23.md"
176
+ },
177
+ "change-plugin-version-0-1-24": {
178
+ "version": "23.1.0-beta.7",
179
+ "cli": "nx",
180
+ "description": "Change dev.nx.gradle.project-graph to version 0.1.24 in build file",
181
+ "factory": "./dist/src/migrations/23-1-0/change-plugin-version-0-1-24",
182
+ "documentation": "./dist/src/migrations/23-1-0/change-plugin-version-0-1-24.md"
176
183
  }
177
184
  },
178
185
  "packageJsonUpdates": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "23.1.0-beta.6",
3
+ "version": "23.1.0-beta.7",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -78,10 +78,10 @@
78
78
  "toml-eslint-parser": "^0.10.0",
79
79
  "tree-kill": "^1.2.2",
80
80
  "tslib": "^2.3.0",
81
- "@nx/devkit": "23.1.0-beta.6"
81
+ "@nx/devkit": "23.1.0-beta.7"
82
82
  },
83
83
  "devDependencies": {
84
- "nx": "23.1.0-beta.6"
84
+ "nx": "23.1.0-beta.7"
85
85
  },
86
86
  "publishConfig": {
87
87
  "access": "public"