pi-bridge 0.1.1 → 0.1.3
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/bin/pii.js +24 -28
- package/package.json +1 -1
package/bin/pii.js
CHANGED
|
@@ -4,15 +4,11 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* pii — pi-bridge entry point installed as a global binary.
|
|
6
6
|
*
|
|
7
|
-
* Locates the
|
|
8
|
-
*
|
|
7
|
+
* Locates the pi CLI via `npm root -g` (cross-platform), then respawns
|
|
8
|
+
* Node with --require preload.js so the bridge is active before pi loads.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* 2. Derive basedir from the wrapper path
|
|
13
|
-
* 3. Find the actual CLI JS at basedir/node_modules/@mariozechner/pi-coding-agent/dist/cli.js
|
|
14
|
-
* 4. Use basedir/node.exe if present (pi ships its own Node on some installs),
|
|
15
|
-
* otherwise fall back to the current Node binary
|
|
10
|
+
* On Windows, also checks for a node.exe bundled alongside the pi wrapper
|
|
11
|
+
* (some installs ship their own Node binary) and prefers it if present.
|
|
16
12
|
*/
|
|
17
13
|
|
|
18
14
|
const { spawnSync, execFileSync } = require('child_process');
|
|
@@ -22,24 +18,13 @@ const os = require('os');
|
|
|
22
18
|
|
|
23
19
|
const preload = path.join(__dirname, '..', 'src', 'local', 'preload.js');
|
|
24
20
|
|
|
25
|
-
const PI_CLI_REL = path.join('node_modules', '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
|
|
26
|
-
|
|
27
|
-
function getWrapperPath() {
|
|
28
|
-
if (os.platform() === 'win32') {
|
|
29
|
-
return execFileSync(
|
|
30
|
-
'powershell',
|
|
31
|
-
['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
|
|
32
|
-
{ encoding: 'utf8' }
|
|
33
|
-
).trim();
|
|
34
|
-
}
|
|
35
|
-
return execFileSync('which', ['pi'], { encoding: 'utf8' }).trim();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
21
|
function findPiCli() {
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
// npm root -g gives the exact global node_modules dir on all platforms.
|
|
23
|
+
// On Windows the npm executable is npm.cmd — use that explicitly.
|
|
24
|
+
const npmBin = os.platform() === 'win32' ? 'npm.cmd' : 'npm';
|
|
25
|
+
const npmRoot = execFileSync(npmBin, ['root', '-g'], { encoding: 'utf8' }).trim();
|
|
26
|
+
const cli = path.join(npmRoot, '@mariozechner', 'pi-coding-agent', 'dist', 'cli.js');
|
|
41
27
|
|
|
42
|
-
const cli = path.join(basedir, PI_CLI_REL);
|
|
43
28
|
if (!fs.existsSync(cli)) {
|
|
44
29
|
throw new Error(
|
|
45
30
|
'Could not find pi CLI at ' + cli + '\n' +
|
|
@@ -47,11 +32,22 @@ function findPiCli() {
|
|
|
47
32
|
);
|
|
48
33
|
}
|
|
49
34
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
// On Windows, prefer the node.exe bundled alongside the pi wrapper if present
|
|
36
|
+
if (os.platform() === 'win32') {
|
|
37
|
+
try {
|
|
38
|
+
const wrapper = execFileSync(
|
|
39
|
+
'powershell',
|
|
40
|
+
['-NoProfile', '-Command', '(Get-Command pi -ErrorAction Stop).Source'],
|
|
41
|
+
{ encoding: 'utf8' }
|
|
42
|
+
).trim();
|
|
43
|
+
const localNode = path.join(path.dirname(wrapper), 'node.exe');
|
|
44
|
+
if (fs.existsSync(localNode)) {
|
|
45
|
+
return { cli, nodeExe: localNode };
|
|
46
|
+
}
|
|
47
|
+
} catch (_) {}
|
|
48
|
+
}
|
|
53
49
|
|
|
54
|
-
return { cli, nodeExe };
|
|
50
|
+
return { cli, nodeExe: process.execPath };
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
let cli, nodeExe;
|