@codemoreira/esad 2.0.1-1 → 2.0.1-2

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": "@codemoreira/esad",
3
- "version": "2.0.1-1",
3
+ "version": "2.0.1-2",
4
4
  "description": "Easy Super App Development - Zero-Config CLI and DevTools for React Native Module Federation",
5
5
  "main": "src/plugin/index.js",
6
6
  "types": "./src/plugin/index.d.ts",
@@ -4,6 +4,7 @@ const path = require('path');
4
4
  const fs = require('fs-extra');
5
5
 
6
6
  const runProcess = (cmd, args, cwd = process.cwd()) => {
7
+ let childRef;
7
8
  const promise = new Promise((resolve, reject) => {
8
9
  let finished = false;
9
10
  let started = false;
@@ -15,47 +16,45 @@ const runProcess = (cmd, args, cwd = process.cwd()) => {
15
16
  };
16
17
 
17
18
  const isWin = process.platform === 'win32';
18
- const localBinPath = path.join(cwd, 'node_modules', '.bin', isWin ? `${cmd}.cmd` : cmd);
19
+ const localBin = isWin ? `${cmd}.cmd` : cmd;
20
+ const localBinPath = path.join(cwd, 'node_modules', '.bin', localBin);
19
21
 
20
22
  let command = cmd;
21
23
  let finalArgs = args;
22
24
  let useNativeSpawn = false;
23
25
 
24
26
  if (fs.existsSync(localBinPath)) {
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
27
+ // 1. Priority: Local node_modules/.bin (fastest & consistent)
28
+ command = isWin ? `node_modules\\.bin\\${localBin}` : `./node_modules/.bin/${localBin}`;
29
+ useNativeSpawn = isWin;
27
30
  } else {
28
- command = isWin ? 'npx.cmd' : 'npx';
29
- finalArgs = [cmd, ...args];
31
+ // 2. Fallback: System Path (git, npm, npx, etc)
32
+ // cross-spawn handles .cmd/.exe resolution automatically
33
+ command = cmd;
34
+ finalArgs = args;
35
+ useNativeSpawn = false;
30
36
  }
31
37
 
32
38
  console.log(`[ESAD] Resolved Command: ${command} (CWD: ${cwd})`);
33
39
 
34
- // Mark as started after a short delay
35
40
  setTimeout(() => { started = true; }, 2000);
36
41
 
37
42
  const spawnFn = useNativeSpawn ? nativeSpawn : spawn;
38
- const child = spawnFn(command, finalArgs, {
43
+ childRef = spawnFn(command, finalArgs, {
39
44
  stdio: 'inherit',
40
45
  cwd,
41
46
  shell: true
42
47
  });
43
48
 
44
- // Attach child to promise for control
45
- promise.child = child;
46
- promise.kill = (signal) => child.kill(signal);
47
-
48
- child.on('error', err => {
49
+ childRef.on('error', err => {
49
50
  if (started && err.code === 'ENOENT') {
50
51
  console.warn(`[ESAD] Warning: Late ENOENT ignored for ${cmd}.`);
51
52
  return;
52
53
  }
53
-
54
- console.error(`[ESAD] Process Error: ${err.code} - ${err.message}`);
55
- finalize(reject, new Error(`Failed to start ${cmd}: ${err.message}`));
54
+ finalize(reject, err);
56
55
  });
57
56
 
58
- child.on('close', code => {
57
+ childRef.on('close', code => {
59
58
  if (code !== 0) {
60
59
  finalize(reject, new Error(`Process ${cmd} exited with code ${code}`));
61
60
  } else {
@@ -64,6 +63,9 @@ const runProcess = (cmd, args, cwd = process.cwd()) => {
64
63
  });
65
64
  });
66
65
 
66
+ promise.child = childRef;
67
+ promise.kill = (signal) => childRef && childRef.kill(signal);
68
+
67
69
  return promise;
68
70
  };
69
71