termify-agent 1.0.50 → 1.0.51

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": "termify-agent",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "Termify Agent CLI - Connect your local terminal to Termify",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { execSync } from 'child_process';
18
- import { createWriteStream, mkdirSync, chmodSync, existsSync, unlinkSync, copyFileSync, rmSync, readFileSync, readlinkSync, writeFileSync, symlinkSync, lstatSync } from 'fs';
18
+ import { createWriteStream, mkdirSync, chmodSync, existsSync, unlinkSync, copyFileSync, rmSync, readFileSync, readlinkSync, writeFileSync, symlinkSync, lstatSync, readdirSync } from 'fs';
19
19
  import { isAbsolute, join, dirname, resolve } from 'path';
20
20
  import { homedir, platform, arch } from 'os';
21
21
  import { get } from 'https';
@@ -75,6 +75,36 @@ function resolveNodePtyDir() {
75
75
  }
76
76
  }
77
77
 
78
+ /**
79
+ * Clean up node-pty build artifacts that npm can't remove from staging dirs.
80
+ * node-gyp creates .target.mk, Makefile, config.gypi etc. that may be owned
81
+ * by root (when postinstall runs with elevated privileges), causing EACCES
82
+ * errors during npm's post-install cleanup. We remove these build artifacts
83
+ * since node-pty only needs build/Release/pty.node at runtime.
84
+ */
85
+ function cleanNodePtyBuildArtifacts(dir) {
86
+ if (!dir || !existsSync(dir)) return;
87
+ try {
88
+ // Remove node-addon-api build artifacts (*.target.mk, *.Makefile)
89
+ const nodeAddonApiDir = join(dir, 'node-addon-api');
90
+ if (existsSync(nodeAddonApiDir)) {
91
+ rmSync(nodeAddonApiDir, { recursive: true, force: true });
92
+ }
93
+ // Remove build directory artifacts except Release/*.node binaries
94
+ const buildDir = join(dir, 'build');
95
+ if (existsSync(buildDir)) {
96
+ const keepPatterns = ['Release'];
97
+ for (const entry of readdirSync(buildDir)) {
98
+ if (!keepPatterns.includes(entry)) {
99
+ rmSync(join(buildDir, entry), { recursive: true, force: true });
100
+ }
101
+ }
102
+ }
103
+ } catch {
104
+ // Best effort — if this fails, npm will just show cleanup warnings
105
+ }
106
+ }
107
+
78
108
  /**
79
109
  * Step 1: Rebuild node-pty with improved error handling
80
110
  * For Node.js v24+, prebuilds may not be compatible, so we compile from source
@@ -90,6 +120,7 @@ function rebuildNodePty() {
90
120
  // Fast path: already works (cached or live test)
91
121
  if (testNodePty()) {
92
122
  console.log('[termify-agent] node-pty is working.');
123
+ cleanNodePtyBuildArtifacts(nodePtyDir);
93
124
  return true;
94
125
  }
95
126
 
@@ -111,6 +142,7 @@ function rebuildNodePty() {
111
142
 
112
143
  if (testNodePty()) {
113
144
  console.log('[termify-agent] node-pty rebuilt successfully.');
145
+ cleanNodePtyBuildArtifacts(nodePtyDir);
114
146
  return true;
115
147
  }
116
148
  } catch (err) {
@@ -132,6 +164,7 @@ function rebuildNodePty() {
132
164
 
133
165
  if (testNodePty()) {
134
166
  console.log('[termify-agent] node-pty rebuilt successfully from module directory.');
167
+ cleanNodePtyBuildArtifacts(nodePtyDir);
135
168
  return true;
136
169
  }
137
170
  } catch (err) {
@@ -151,6 +184,7 @@ function rebuildNodePty() {
151
184
 
152
185
  if (testNodePty()) {
153
186
  console.log('[termify-agent] node-pty compiled from source successfully.');
187
+ cleanNodePtyBuildArtifacts(nodePtyDir);
154
188
  return true;
155
189
  }
156
190
  } catch (err) {
@@ -184,12 +218,16 @@ function rebuildNodePty() {
184
218
 
185
219
  if (testNodePty()) {
186
220
  console.log('[termify-agent] node-pty reinstalled and compiled successfully.');
221
+ cleanNodePtyBuildArtifacts(reinstalledNodePtyDir);
187
222
  return true;
188
223
  }
189
224
  } catch (err2) {
190
225
  // Continue to error message
191
226
  }
192
227
 
228
+ // Fix permissions even on failure so npm can clean up staging directory
229
+ cleanNodePtyBuildArtifacts(nodePtyDir);
230
+
193
231
  console.error('[termify-agent] CRITICAL: node-pty installation failed.');
194
232
  console.error('[termify-agent] Terminal features will NOT work.');
195
233
  console.error('[termify-agent] ');