pi-bridge 0.2.8 → 0.2.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.
- package/README.md +2 -3
- package/package.json +1 -1
- package/src/local/fake-dir.js +6 -18
- package/src/local/fs-patch.js +7 -2
- package/src/local/preload.js +1 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ pii (bin/pii.js)
|
|
|
52
52
|
│ → prints PORT:TOKEN:PID to stdout
|
|
53
53
|
├─ SSH port forward localhost:PORT
|
|
54
54
|
├─ create fake local dir:
|
|
55
|
-
│
|
|
55
|
+
│ /tmp/pi-bridge/root/projects/my-app
|
|
56
56
|
├─ process.chdir(fakeLocalCwd)
|
|
57
57
|
├─ strip --ssh from process.argv
|
|
58
58
|
├─ patch fs.* (sync + promises) remote/index.js
|
|
@@ -67,7 +67,6 @@ pi loads — unaware of bridge restricts to remoteCwd
|
|
|
67
67
|
→ git branch in footer ✓
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
The fake local directory lives under `<home>/.pi-bridge/<remote>/` (not the OS temp directory) so it survives reboots and pi can always resume sessions correctly. On Windows this is `%USERPROFILE%\.pi-bridge\`; on macOS/Linux it is `~/.pi-bridge/`.
|
|
71
70
|
|
|
72
71
|
## What Gets Patched
|
|
73
72
|
|
|
@@ -121,7 +120,7 @@ Host myserver
|
|
|
121
120
|
```
|
|
122
121
|
|
|
123
122
|
**Files show as empty / ENOENT**
|
|
124
|
-
The fake local directory (
|
|
123
|
+
The fake local directory (`/tmp/pi-bridge/…`) is intentionally empty — all reads go to the remote. If you see ENOENT, the bridge may not have started correctly. Check that Node.js is available on the remote (`node --version`).
|
|
125
124
|
|
|
126
125
|
**Branch name not updating**
|
|
127
126
|
The footer polls `.git` every second. Switching branches from outside a pi session is reflected within ~1s. If the branch is stuck, restart `pii`.
|
package/package.json
CHANGED
package/src/local/fake-dir.js
CHANGED
|
@@ -8,33 +8,21 @@ const path = require('path');
|
|
|
8
8
|
// filesystem rather than being redirected through the SSH bridge.
|
|
9
9
|
const origRmSync = fs.rmSync.bind(fs);
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Sanitise an SSH target string (user@host or alias) into a safe dir name.
|
|
13
|
-
*/
|
|
14
|
-
function sanitizeRemote(remote) {
|
|
15
|
-
return remote.replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
/**
|
|
19
12
|
* Create the fake local directory skeleton for the given remote path.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* directory so it survives reboots — this prevents pi's session-cwd check
|
|
23
|
-
* from failing when it tries to resume a previous session whose cwd points
|
|
24
|
-
* at a directory that was cleaned up between runs.
|
|
13
|
+
* The structure mirrors the remote path so that path-mapper can convert
|
|
14
|
+
* between fake local paths and remote paths deterministically.
|
|
25
15
|
*
|
|
26
16
|
* Example:
|
|
27
|
-
* remote = 'myserver'
|
|
28
17
|
* remoteCwd = '/root/project-x'
|
|
29
|
-
* fakeRoot = '
|
|
30
|
-
* fakeLocalCwd = '
|
|
18
|
+
* fakeRoot = '/tmp/pi-bridge'
|
|
19
|
+
* fakeLocalCwd = '/tmp/pi-bridge/root/project-x'
|
|
31
20
|
*
|
|
32
|
-
* @param {string} remote - SSH target, e.g. 'user@host' or alias
|
|
33
21
|
* @param {string} remoteCwd - Absolute remote path, e.g. '/root/project-x'
|
|
34
22
|
* @returns {{ fakeRoot: string, fakeLocalCwd: string }}
|
|
35
23
|
*/
|
|
36
|
-
function createFakeDir(
|
|
37
|
-
const fakeRootRaw = path.join(os.
|
|
24
|
+
function createFakeDir(remoteCwd) {
|
|
25
|
+
const fakeRootRaw = path.join(os.tmpdir(), 'pi-bridge');
|
|
38
26
|
|
|
39
27
|
// Build the local mirror path from the remote path segments
|
|
40
28
|
const segments = remoteCwd.split('/').filter(Boolean);
|
package/src/local/fs-patch.js
CHANGED
|
@@ -192,10 +192,15 @@ function patchFs(fakeRoot, port, token) {
|
|
|
192
192
|
if (process.platform === 'win32' && isBashPath(s)) return true;
|
|
193
193
|
if (!s || !isFakePath(s, fakeRoot)) return orig.existsSync(p);
|
|
194
194
|
try {
|
|
195
|
-
|
|
195
|
+
const remoteExists = httpGet(port, token, '/exists?path=' + encodeURIComponent(rpath(s))).trim() === '1';
|
|
196
|
+
// Also check locally: the fake dir root always exists on disk (pi-bridge
|
|
197
|
+
// creates it in preload). This lets pi's session-cwd check pass even when
|
|
198
|
+
// Node.js 24's ESM existsSync bypasses our patch and the remote check
|
|
199
|
+
// returns an unexpected result for the project root directory.
|
|
200
|
+
return remoteExists || orig.existsSync(p);
|
|
196
201
|
} catch (e) {
|
|
197
202
|
if (e.message && (e.message.includes('403') || e.message.includes('ENOENT'))) return false;
|
|
198
|
-
|
|
203
|
+
return orig.existsSync(p);
|
|
199
204
|
}
|
|
200
205
|
};
|
|
201
206
|
|
package/src/local/preload.js
CHANGED
|
@@ -57,7 +57,7 @@ try {
|
|
|
57
57
|
const { port, token, sessionId, remotePid } = config;
|
|
58
58
|
|
|
59
59
|
// --- Step 3: Create fake local directory ---
|
|
60
|
-
const { fakeRoot, fakeLocalCwd } = createFakeDir(
|
|
60
|
+
const { fakeRoot, fakeLocalCwd } = createFakeDir(remoteCwd);
|
|
61
61
|
|
|
62
62
|
// --- Step 4: Change working directory to fake local cwd ---
|
|
63
63
|
process.chdir(fakeLocalCwd);
|