@codemoreira/esad 1.4.6-33 → 1.4.6-35
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 +1 -1
- package/src/cli/utils/process.js +27 -13
package/package.json
CHANGED
package/src/cli/utils/process.js
CHANGED
|
@@ -1,47 +1,61 @@
|
|
|
1
1
|
const { spawn } = require('cross-spawn');
|
|
2
|
+
const nativeSpawn = require('child_process').spawn;
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const fs = require('fs-extra');
|
|
4
5
|
|
|
5
|
-
/**
|
|
6
|
-
* Helper to spawn commands synchronously
|
|
7
|
-
* @param {string} cmd
|
|
8
|
-
* @param {string[]} args
|
|
9
|
-
* @param {string} cwd
|
|
10
|
-
* @returns {Promise<void>}
|
|
11
|
-
*/
|
|
12
6
|
const runProcess = (cmd, args, cwd = process.cwd()) => {
|
|
13
7
|
return new Promise((resolve, reject) => {
|
|
14
8
|
let finished = false;
|
|
9
|
+
let started = false;
|
|
10
|
+
|
|
15
11
|
const finalize = (fn, arg) => {
|
|
16
12
|
if (finished) return;
|
|
17
13
|
finished = true;
|
|
18
14
|
fn(arg);
|
|
19
15
|
};
|
|
20
16
|
|
|
21
|
-
// Try to find a local binary in node_modules/.bin first
|
|
22
17
|
const isWin = process.platform === 'win32';
|
|
23
18
|
const localBinPath = path.join(cwd, 'node_modules', '.bin', isWin ? `${cmd}.cmd` : cmd);
|
|
24
19
|
|
|
25
20
|
let command = cmd;
|
|
26
21
|
let finalArgs = args;
|
|
22
|
+
let useNativeSpawn = false;
|
|
27
23
|
|
|
28
24
|
if (fs.existsSync(localBinPath)) {
|
|
29
|
-
command =
|
|
25
|
+
command = isWin ? `node_modules\\.bin\\${cmd}.cmd` : `./node_modules/.bin/${cmd}`;
|
|
26
|
+
useNativeSpawn = isWin; // Use native spawn on Windows for local binaries to avoid cross-spawn issues
|
|
30
27
|
} else {
|
|
31
|
-
// Fallback to npx
|
|
32
28
|
command = isWin ? 'npx.cmd' : 'npx';
|
|
33
29
|
finalArgs = [cmd, ...args];
|
|
34
30
|
}
|
|
31
|
+
|
|
32
|
+
console.log(`[ESAD] Resolved Command: ${command} (CWD: ${cwd})`);
|
|
33
|
+
|
|
34
|
+
// Mark as started after a short delay
|
|
35
|
+
setTimeout(() => { started = true; }, 2000);
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
+
const spawnFn = useNativeSpawn ? nativeSpawn : spawn;
|
|
38
|
+
const child = spawnFn(command, finalArgs, {
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
cwd,
|
|
41
|
+
shell: true
|
|
42
|
+
});
|
|
37
43
|
|
|
38
44
|
child.on('error', err => {
|
|
39
|
-
|
|
45
|
+
// If the process already "started" (ran for > 2s), we ignore early-spawn errors
|
|
46
|
+
// as they are likely shell artifacts from the process exiting.
|
|
47
|
+
if (started && err.code === 'ENOENT') {
|
|
48
|
+
console.warn(`[ESAD] Warning: Late ENOENT ignored for ${cmd}.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.error(`[ESAD] Process Error: ${err.code} - ${err.message}`);
|
|
53
|
+
finalize(reject, new Error(`Failed to start ${cmd}: ${err.message}`));
|
|
40
54
|
});
|
|
41
55
|
|
|
42
56
|
child.on('close', code => {
|
|
43
57
|
if (code !== 0) {
|
|
44
|
-
finalize(reject, new Error(`
|
|
58
|
+
finalize(reject, new Error(`Process ${cmd} exited with code ${code}`));
|
|
45
59
|
} else {
|
|
46
60
|
finalize(resolve);
|
|
47
61
|
}
|