@nx/gradle 19.2.0-canary.20240530-316dcb9 → 19.2.0-canary.20240531-2cb7ecb
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
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/gradle",
|
3
|
-
"version": "19.2.0-canary.
|
3
|
+
"version": "19.2.0-canary.20240531-2cb7ecb",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Gradle allows Gradle tasks to be run through Nx",
|
6
6
|
"repository": {
|
@@ -34,7 +34,7 @@
|
|
34
34
|
"migrations": "./migrations.json"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@nx/devkit": "19.2.0-canary.
|
37
|
+
"@nx/devkit": "19.2.0-canary.20240531-2cb7ecb"
|
38
38
|
},
|
39
39
|
"publishConfig": {
|
40
40
|
"access": "public"
|
@@ -5,7 +5,6 @@ const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
6
6
|
const node_path_1 = require("node:path");
|
7
7
|
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
8
|
-
const nodes_1 = require("./nodes");
|
9
8
|
const createDependencies = async (_, context) => {
|
10
9
|
const gradleFiles = findGradleFiles(context.filesToProcess);
|
11
10
|
if (gradleFiles.length === 0) {
|
@@ -13,7 +12,7 @@ const createDependencies = async (_, context) => {
|
|
13
12
|
}
|
14
13
|
let dependencies = [];
|
15
14
|
const gradleDependenciesStart = performance.mark('gradleDependencies:start');
|
16
|
-
const { gradleFileToGradleProjectMap, gradleProjectToProjectName, buildFileToDepsMap, } = (0, get_gradle_report_1.
|
15
|
+
const { gradleFileToGradleProjectMap, gradleProjectToProjectName, buildFileToDepsMap, } = (0, get_gradle_report_1.getCurrentGradleReport)();
|
17
16
|
for (const gradleFile of gradleFiles) {
|
18
17
|
const gradleProject = gradleFileToGradleProjectMap.get(gradleFile);
|
19
18
|
const projectName = gradleProjectToProjectName.get(gradleProject);
|
@@ -24,10 +23,6 @@ const createDependencies = async (_, context) => {
|
|
24
23
|
}
|
25
24
|
const gradleDependenciesEnd = performance.mark('gradleDependencies:end');
|
26
25
|
performance.measure('gradleDependencies', gradleDependenciesStart.name, gradleDependenciesEnd.name);
|
27
|
-
(0, nodes_1.writeTargetsToCache)();
|
28
|
-
if (dependencies.length) {
|
29
|
-
(0, get_gradle_report_1.invalidateGradleReportCache)();
|
30
|
-
}
|
31
26
|
return dependencies;
|
32
27
|
};
|
33
28
|
exports.createDependencies = createDependencies;
|
@@ -45,7 +40,7 @@ function findGradleFiles(fileMap) {
|
|
45
40
|
}
|
46
41
|
function processGradleDependencies(depsFile, gradleProjectToProjectName, sourceProjectName, gradleFile, context) {
|
47
42
|
const dependencies = new Set();
|
48
|
-
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(
|
43
|
+
const lines = (0, node_fs_1.readFileSync)(depsFile).toString().split(get_gradle_report_1.newLineSeparator);
|
49
44
|
let inDeps = false;
|
50
45
|
for (const line of lines) {
|
51
46
|
if (line.startsWith('implementationDependenciesMetadata') ||
|
package/src/plugin/nodes.d.ts
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
-
import { CreateNodes } from '@nx/devkit';
|
1
|
+
import { CreateNodes, CreateNodesV2, ProjectConfiguration, TargetConfiguration, CreateNodesFunction } from '@nx/devkit';
|
2
|
+
import { GradleReport } from '../utils/get-gradle-report';
|
2
3
|
export interface GradlePluginOptions {
|
3
4
|
testTargetName?: string;
|
4
5
|
classesTargetName?: string;
|
5
6
|
buildTargetName?: string;
|
6
7
|
[taskTargetName: string]: string | undefined;
|
7
8
|
}
|
8
|
-
|
9
|
+
type GradleTargets = Record<string, {
|
10
|
+
name: string;
|
11
|
+
targets: Record<string, TargetConfiguration>;
|
12
|
+
metadata: ProjectConfiguration['metadata'];
|
13
|
+
}>;
|
14
|
+
export declare function writeTargetsToCache(cachePath: string, results: GradleTargets): void;
|
15
|
+
export declare const createNodesV2: CreateNodesV2<GradlePluginOptions>;
|
16
|
+
export declare const makeCreateNodes: (gradleReport: GradleReport, targetsCache: GradleTargets) => CreateNodesFunction;
|
17
|
+
/**
|
18
|
+
* @deprecated `{@link createNodesV2} is replacing this. Update your plugin to export its own `createNodesV2` function that wraps this one instead.`
|
19
|
+
*/
|
9
20
|
export declare const createNodes: CreateNodes<GradlePluginOptions>;
|
21
|
+
export {};
|
package/src/plugin/nodes.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createNodes = exports.writeTargetsToCache = void 0;
|
3
|
+
exports.createNodes = exports.makeCreateNodes = exports.createNodesV2 = exports.writeTargetsToCache = void 0;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
6
6
|
const node_fs_1 = require("node:fs");
|
@@ -8,45 +8,67 @@ const node_path_1 = require("node:path");
|
|
8
8
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
9
9
|
const exec_gradle_1 = require("../utils/exec-gradle");
|
10
10
|
const get_gradle_report_1 = require("../utils/get-gradle-report");
|
11
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
11
12
|
const cacheableTaskType = new Set(['Build', 'Verification']);
|
12
13
|
const dependsOnMap = {
|
13
14
|
build: ['^build', 'classes'],
|
14
15
|
test: ['classes'],
|
15
16
|
classes: ['^classes'],
|
16
17
|
};
|
17
|
-
|
18
|
-
const targetsCache = readTargetsCache();
|
19
|
-
function readTargetsCache() {
|
18
|
+
function readTargetsCache(cachePath) {
|
20
19
|
return (0, node_fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
21
20
|
}
|
22
|
-
function writeTargetsToCache() {
|
23
|
-
|
24
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
25
|
-
...oldCache,
|
26
|
-
...targetsCache,
|
27
|
-
});
|
21
|
+
function writeTargetsToCache(cachePath, results) {
|
22
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
28
23
|
}
|
29
24
|
exports.writeTargetsToCache = writeTargetsToCache;
|
30
|
-
exports.
|
31
|
-
|
32
|
-
(
|
33
|
-
const
|
34
|
-
const
|
35
|
-
targetsCache
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
exports.createNodesV2 = [
|
26
|
+
get_gradle_report_1.gradleConfigGlob,
|
27
|
+
async (configFiles, options, context) => {
|
28
|
+
const optionsHash = (0, file_hasher_1.hashObject)(options);
|
29
|
+
const cachePath = (0, node_path_1.join)(cache_directory_1.projectGraphCacheDirectory, `gradle-${optionsHash}.hash`);
|
30
|
+
const targetsCache = readTargetsCache(cachePath);
|
31
|
+
(0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot);
|
32
|
+
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
33
|
+
try {
|
34
|
+
return await (0, devkit_1.createNodesFromFiles)((0, exports.makeCreateNodes)(gradleReport, targetsCache), configFiles, options, context);
|
39
35
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
finally {
|
37
|
+
writeTargetsToCache(cachePath, targetsCache);
|
38
|
+
}
|
39
|
+
},
|
40
|
+
];
|
41
|
+
const makeCreateNodes = (gradleReport, targetsCache) => (gradleFilePath, options, context) => {
|
42
|
+
const projectRoot = (0, node_path_1.dirname)(gradleFilePath);
|
43
|
+
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options ?? {}, context);
|
44
|
+
targetsCache[hash] ??= createGradleProject(gradleReport, gradleFilePath, options, context);
|
45
|
+
const project = targetsCache[hash];
|
46
|
+
if (!project) {
|
47
|
+
return {};
|
48
|
+
}
|
49
|
+
return {
|
50
|
+
projects: {
|
51
|
+
[projectRoot]: project,
|
52
|
+
},
|
53
|
+
};
|
54
|
+
};
|
55
|
+
exports.makeCreateNodes = makeCreateNodes;
|
56
|
+
/**
|
57
|
+
* @deprecated `{@link createNodesV2} is replacing this. Update your plugin to export its own `createNodesV2` function that wraps this one instead.`
|
58
|
+
*/
|
59
|
+
exports.createNodes = [
|
60
|
+
get_gradle_report_1.gradleConfigGlob,
|
61
|
+
(configFile, options, context) => {
|
62
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will error.');
|
63
|
+
(0, get_gradle_report_1.populateGradleReport)(context.workspaceRoot);
|
64
|
+
const gradleReport = (0, get_gradle_report_1.getCurrentGradleReport)();
|
65
|
+
const internalCreateNodes = (0, exports.makeCreateNodes)(gradleReport, {});
|
66
|
+
return internalCreateNodes(configFile, options, context);
|
45
67
|
},
|
46
68
|
];
|
47
|
-
function createGradleProject(gradleFilePath, options, context) {
|
69
|
+
function createGradleProject(gradleReport, gradleFilePath, options, context) {
|
48
70
|
try {
|
49
|
-
const { gradleProjectToTasksTypeMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } =
|
71
|
+
const { gradleProjectToTasksTypeMap, gradleFileToOutputDirsMap, gradleFileToGradleProjectMap, gradleProjectToProjectName, } = gradleReport;
|
50
72
|
const gradleProject = gradleFileToGradleProjectMap.get(gradleFilePath);
|
51
73
|
const projectName = gradleProjectToProjectName.get(gradleProject);
|
52
74
|
if (!projectName) {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
export declare const fileSeparator: string;
|
2
|
+
export declare const newLineSeparator: string;
|
2
3
|
export interface GradleReport {
|
3
4
|
gradleFileToGradleProjectMap: Map<string, string>;
|
4
5
|
buildFileToDepsMap: Map<string, string>;
|
@@ -6,6 +7,7 @@ export interface GradleReport {
|
|
6
7
|
gradleProjectToTasksTypeMap: Map<string, Map<string, string>>;
|
7
8
|
gradleProjectToProjectName: Map<string, string>;
|
8
9
|
}
|
9
|
-
export declare
|
10
|
-
export declare function
|
10
|
+
export declare const gradleConfigGlob = "**/build.{gradle.kts,gradle}";
|
11
|
+
export declare function getCurrentGradleReport(): GradleReport;
|
12
|
+
export declare function populateGradleReport(workspaceRoot: string): void;
|
11
13
|
export declare function processProjectReports(projectReportLines: string[]): GradleReport;
|
@@ -1,35 +1,45 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.processProjectReports = exports.
|
3
|
+
exports.processProjectReports = exports.populateGradleReport = exports.getCurrentGradleReport = exports.gradleConfigGlob = exports.newLineSeparator = exports.fileSeparator = void 0;
|
4
4
|
const node_fs_1 = require("node:fs");
|
5
5
|
const node_path_1 = require("node:path");
|
6
6
|
const devkit_1 = require("@nx/devkit");
|
7
7
|
const exec_gradle_1 = require("./exec-gradle");
|
8
|
+
const workspace_context_1 = require("nx/src/utils/workspace-context");
|
8
9
|
exports.fileSeparator = process.platform.startsWith('win')
|
9
10
|
? 'file:///'
|
10
11
|
: 'file://';
|
11
|
-
|
12
|
+
exports.newLineSeparator = process.platform.startsWith('win')
|
13
|
+
? '\r\n'
|
14
|
+
: '\n';
|
12
15
|
let gradleReportCache;
|
13
|
-
|
14
|
-
|
16
|
+
let gradleCurrentConfigHash;
|
17
|
+
exports.gradleConfigGlob = '**/build.{gradle.kts,gradle}';
|
18
|
+
function getCurrentGradleReport() {
|
19
|
+
if (!gradleReportCache) {
|
20
|
+
throw new Error('Expected cached gradle report. Please open an issue at https://github.com/nrwl/nx/issues/new/choose');
|
21
|
+
}
|
22
|
+
return gradleReportCache;
|
15
23
|
}
|
16
|
-
exports.
|
17
|
-
function
|
18
|
-
|
19
|
-
|
24
|
+
exports.getCurrentGradleReport = getCurrentGradleReport;
|
25
|
+
function populateGradleReport(workspaceRoot) {
|
26
|
+
const gradleConfigHash = (0, workspace_context_1.hashWithWorkspaceContext)(workspaceRoot, [
|
27
|
+
exports.gradleConfigGlob,
|
28
|
+
]);
|
29
|
+
if (gradleReportCache && gradleConfigHash === gradleCurrentConfigHash) {
|
30
|
+
return;
|
20
31
|
}
|
21
32
|
const gradleProjectReportStart = performance.mark('gradleProjectReport:start');
|
22
33
|
const projectReportLines = (0, exec_gradle_1.execGradle)(['projectReport'], {
|
23
|
-
cwd:
|
34
|
+
cwd: workspaceRoot,
|
24
35
|
})
|
25
36
|
.toString()
|
26
|
-
.split(newLineSeparator);
|
37
|
+
.split(exports.newLineSeparator);
|
27
38
|
const gradleProjectReportEnd = performance.mark('gradleProjectReport:end');
|
28
39
|
performance.measure('gradleProjectReport', gradleProjectReportStart.name, gradleProjectReportEnd.name);
|
29
40
|
gradleReportCache = processProjectReports(projectReportLines);
|
30
|
-
return gradleReportCache;
|
31
41
|
}
|
32
|
-
exports.
|
42
|
+
exports.populateGradleReport = populateGradleReport;
|
33
43
|
function processProjectReports(projectReportLines) {
|
34
44
|
/**
|
35
45
|
* Map of Gradle File path to Gradle Project Name
|
@@ -75,7 +85,7 @@ function processProjectReports(projectReportLines) {
|
|
75
85
|
}
|
76
86
|
const [_, file] = projectReportLines[index].split(exports.fileSeparator);
|
77
87
|
const propertyReportLines = (0, node_fs_1.existsSync)(file)
|
78
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(newLineSeparator)
|
88
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exports.newLineSeparator)
|
79
89
|
: [];
|
80
90
|
let projectName, absBuildFilePath, absBuildDirPath;
|
81
91
|
const outputDirMap = new Map();
|
@@ -117,7 +127,7 @@ function processProjectReports(projectReportLines) {
|
|
117
127
|
const [_, file] = projectReportLines[index].split(exports.fileSeparator);
|
118
128
|
const taskTypeMap = new Map();
|
119
129
|
const tasksFileLines = (0, node_fs_1.existsSync)(file)
|
120
|
-
? (0, node_fs_1.readFileSync)(file).toString().split(newLineSeparator)
|
130
|
+
? (0, node_fs_1.readFileSync)(file).toString().split(exports.newLineSeparator)
|
121
131
|
: [];
|
122
132
|
let i = 0;
|
123
133
|
while (i < tasksFileLines.length) {
|