@nx/gradle 23.2.0-beta.7 → 23.2.0-beta.9

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.
@@ -205,14 +205,15 @@ async function addNxProjectGraphPluginToBuildGradle(gradleFilePath, buildGradleC
205
205
  if (!hasPluginViaAlias) {
206
206
  const applyPluginPattern = versionCatalogPluginAccessor
207
207
  ? new RegExp(`\\s*plugin\\(${versionCatalogPluginAccessor.replace(/\./g, '\\.')}\\)`)
208
- : new RegExp(`\\s*plugin\\(["']${versions_1.gradleProjectGraphPluginName}["']\\)`);
208
+ : // Both DSL forms, so a re-run doesn't append a duplicate apply.
209
+ new RegExp(`\\s*plugin\\s*[:(]\\s*["']${versions_1.gradleProjectGraphPluginName.replace(/\./g, '\\.')}["']`);
209
210
  if (buildGradleContent.includes('allprojects {')) {
210
211
  if (!applyPluginPattern.test(buildGradleContent)) {
211
212
  const applyPlugin = versionCatalogPluginAccessor
212
213
  ? `plugin(${versionCatalogPluginAccessor})`
213
214
  : isKotlinDsl
214
215
  ? `plugin("${versions_1.gradleProjectGraphPluginName}")`
215
- : `plugin "${versions_1.gradleProjectGraphPluginName}"`;
216
+ : `plugin: "${versions_1.gradleProjectGraphPluginName}"`;
216
217
  buildGradleContent = buildGradleContent.replace(/allprojects\s*\{/, `allprojects {\n apply ${applyPlugin}`);
217
218
  }
218
219
  }
@@ -1,5 +1,5 @@
1
1
  import { NxJsonConfiguration } from '@nx/devkit';
2
- import { ExecFileOptions } from 'node:child_process';
2
+ import { SpawnOptions } from 'node:child_process';
3
3
  export declare const fileSeparator: string;
4
4
  export declare const newLineSeparator: string;
5
5
  /**
@@ -14,7 +14,7 @@ export declare function getGradleExecFile(): string;
14
14
  * @param execOptions exec options
15
15
  * @returns promise with the stdout buffer
16
16
  */
17
- export declare function execGradleAsync(gradleBinaryPath: string, args: ReadonlyArray<string>, execOptions?: ExecFileOptions): Promise<Buffer>;
17
+ export declare function execGradleAsync(gradleBinaryPath: string, args: ReadonlyArray<string>, execOptions?: Omit<SpawnOptions, 'shell'>): Promise<Buffer>;
18
18
  export declare function getCustomGradleExecutableDirectoryFromPlugin(nxJson: NxJsonConfiguration): string | undefined;
19
19
  /**
20
20
  * This function recursively finds the nearest gradlew file in the workspace
@@ -7,12 +7,9 @@ exports.getCustomGradleExecutableDirectoryFromPlugin = getCustomGradleExecutable
7
7
  exports.findGradlewFile = findGradlewFile;
8
8
  exports.findGradlewUsingFilePathTraversal = findGradlewUsingFilePathTraversal;
9
9
  exports.findGradlewUsingCustomExecutableDirectory = findGradlewUsingCustomExecutableDirectory;
10
- const tslib_1 = require("tslib");
11
10
  const devkit_1 = require("@nx/devkit");
12
- const node_child_process_1 = require("node:child_process");
13
11
  const node_fs_1 = require("node:fs");
14
12
  const node_path_1 = require("node:path");
15
- const tree_kill_1 = tslib_1.__importDefault(require("tree-kill"));
16
13
  const internal_1 = require("@nx/devkit/internal");
17
14
  exports.fileSeparator = process.platform.startsWith('win')
18
15
  ? 'file:///'
@@ -35,33 +32,39 @@ function getGradleExecFile() {
35
32
  * @returns promise with the stdout buffer
36
33
  */
37
34
  function execGradleAsync(gradleBinaryPath, args, execOptions = {}) {
38
- // Extract signal so we can handle cancellation with tree-kill
35
+ // Extract signal so we can handle cancellation with a process-tree kill
39
36
  // instead of Node's default which only kills the immediate child.
40
37
  const { signal, ...restOptions } = execOptions;
41
38
  return new Promise((res, rej) => {
42
- const cp = (0, node_child_process_1.execFile)(gradleBinaryPath, args, {
39
+ // Without the filter, empty args reach gradle as literal empty arguments.
40
+ const cp = (0, internal_1.safeSpawn)(gradleBinaryPath, args.filter(Boolean), {
43
41
  cwd: (0, node_path_1.dirname)(gradleBinaryPath),
44
- shell: true,
45
- windowsHide: true,
46
42
  env: process.env,
47
- maxBuffer: internal_1.LARGE_BUFFER,
48
43
  ...restOptions,
49
- }, undefined);
50
- // Use tree-kill on abort to kill the entire process tree
51
- // (cmd.exe gradlew.bat java.exe), not just the shell.
44
+ });
45
+ let stdout = Buffer.from('');
46
+ // On abort, kill the entire process tree (gradlew spawns java) and settle
47
+ // immediately — a wedged JVM that outlives the kill signal would otherwise
48
+ // keep this promise pending and the abort error would never surface.
52
49
  const onAbort = () => {
53
50
  if (cp.pid) {
54
- (0, tree_kill_1.default)(cp.pid);
51
+ (0, internal_1.killProcessTreeGraceful)(cp.pid).catch(() => { });
55
52
  }
53
+ rej(stdout);
56
54
  };
57
55
  signal?.addEventListener('abort', onAbort, { once: true });
58
- let stdout = Buffer.from('');
59
56
  cp.stdout?.on('data', (data) => {
60
57
  stdout += data;
61
58
  });
62
59
  cp.stderr?.on('data', (data) => {
63
60
  stdout += data;
64
61
  });
62
+ // Without a shell the child is gradlew itself, so spawn can fail outright —
63
+ // Node then emits `error` and never `exit`.
64
+ cp.on('error', (err) => {
65
+ signal?.removeEventListener('abort', onAbort);
66
+ rej(err);
67
+ });
65
68
  cp.on('exit', (code, s) => {
66
69
  signal?.removeEventListener('abort', onAbort);
67
70
  if (code === null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/gradle",
3
- "version": "23.2.0-beta.7",
3
+ "version": "23.2.0-beta.9",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -76,12 +76,11 @@
76
76
  },
77
77
  "dependencies": {
78
78
  "toml-eslint-parser": "^0.10.0",
79
- "tree-kill": "^1.2.2",
80
79
  "tslib": "^2.3.0",
81
- "@nx/devkit": "23.2.0-beta.7"
80
+ "@nx/devkit": "23.2.0-beta.9"
82
81
  },
83
82
  "devDependencies": {
84
- "nx": "23.2.0-beta.7"
83
+ "nx": "23.2.0-beta.9"
85
84
  },
86
85
  "publishConfig": {
87
86
  "access": "public"