livedesk 0.1.252 → 0.1.253

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.
Files changed (2) hide show
  1. package/bin/livedesk.js +22 -4
  2. package/package.json +1 -1
package/bin/livedesk.js CHANGED
@@ -223,7 +223,19 @@ async function stopProcessesOnPorts(ports) {
223
223
  '$ErrorActionPreference = "SilentlyContinue";',
224
224
  `$ports = @(${uniquePorts.join(',')});`,
225
225
  `$currentNodePid = ${process.pid};`,
226
- " $hubProcessPattern = '(?i)(?:livedesk|@livedesk).*hub[\\\\/].*server\\.js';",
226
+ ' $liveDeskProcessPattern = "(?i)(?:livedesk|@livedesk)";',
227
+ ' $hubServerProcessPattern = "(?i)(?:hub[\\\\/].*server\\.js|server\\.js)";',
228
+ 'function Get-ProcessCommandChain($proc) {',
229
+ ' $chain = @();',
230
+ ' $current = $proc;',
231
+ ' for ($depth = 0; $current -and $depth -lt 8; $depth++) {',
232
+ ' $chain += [string]$current.CommandLine;',
233
+ ' $parentId = [int]$current.ParentProcessId;',
234
+ ' if ($parentId -le 0) { break }',
235
+ ' $current = Get-CimInstance Win32_Process -Filter "ProcessId = $parentId" -ErrorAction SilentlyContinue;',
236
+ ' }',
237
+ ' return ($chain -join " ");',
238
+ '}',
227
239
  'function Get-ListenConnections($port) {',
228
240
  ' $connections = @(Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue);',
229
241
  ' if ($connections.Count -gt 0) { return $connections }',
@@ -242,12 +254,18 @@ async function stopProcessesOnPorts(ports) {
242
254
  ' $proc = Get-CimInstance Win32_Process -Filter "ProcessId = $owner" -ErrorAction SilentlyContinue;',
243
255
  ' $processName = if ($proc) { [string]$proc.Name } else { "" };',
244
256
  ' $commandLine = if ($proc) { [string]$proc.CommandLine } else { "" };',
245
- ' $knownLiveDesk = $commandLine -match "(?i)(?:livedesk|@livedesk).*hub[\\\\/].*server\\.js";',
257
+ ' $commandChain = if ($proc) { Get-ProcessCommandChain $proc } else { "" };',
258
+ ' $knownLiveDesk = ($processName -match "(?i)^node(?:\\.exe)?$") -and ($commandChain -match $liveDeskProcessPattern) -and ($commandChain -match $hubServerProcessPattern);',
246
259
  ' [pscustomobject]@{ Port = [int]$port; Pid = $owner; ProcessName = $processName; CommandLine = $commandLine; KnownLiveDesk = [bool]$knownLiveDesk; Action = "preserved"; PortAvailable = $false; ProcessGone = $false }',
247
260
  ' }',
248
261
  '}',
249
262
  '$records = @($records | Sort-Object Port,Pid -Unique);',
250
- '$hubProcesses = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessId -and $_.ProcessId -ne $currentNodePid -and ([string]$_.Name) -ieq "node.exe" -and ([string]$_.CommandLine) -match $hubProcessPattern });',
263
+ '$hubProcesses = @(Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object { $_.ProcessId -and $_.ProcessId -ne $currentNodePid -and ([string]$_.Name) -ieq "node.exe" } | ForEach-Object {',
264
+ ' $commandChain = Get-ProcessCommandChain $_;',
265
+ ' if (($commandChain -match $liveDeskProcessPattern) -and ($commandChain -match $hubServerProcessPattern)) {',
266
+ ' [pscustomobject]@{ ProcessId = [int]$_.ProcessId; ParentProcessId = [int]$_.ParentProcessId; Name = [string]$_.Name; CommandLine = [string]$_.CommandLine; CommandChain = $commandChain }',
267
+ ' }',
268
+ '});',
251
269
  'foreach ($proc in $hubProcesses) {',
252
270
  ' if (-not (@($records | Where-Object { $_.Pid -eq [int]$proc.ProcessId }).Count)) {',
253
271
  ' $records += [pscustomobject]@{ Port = 0; Pid = [int]$proc.ProcessId; ProcessName = [string]$proc.Name; CommandLine = [string]$proc.CommandLine; KnownLiveDesk = $true; Action = "preserved"; PortAvailable = $false; ProcessGone = $false }',
@@ -291,7 +309,7 @@ async function stopProcessesOnPorts(ports) {
291
309
  }
292
310
  const blocked = records.filter(record => record?.PortAvailable !== true || (record?.Port === 0 && record?.ProcessGone !== true));
293
311
  if (blocked.length > 0) {
294
- const summary = blocked.map(record => `${record.Pid}:${record.ProcessName || 'unknown'}@${record.Port}[port-free=${record.PortAvailable === true},process-gone=${record.ProcessGone === true}]`).join(', ');
312
+ const summary = blocked.map(record => `${record.Pid}:${record.ProcessName || 'unknown'}@${record.Port}[port-free=${record.PortAvailable === true},process-gone=${record.ProcessGone === true},cmd=${String(record.CommandLine || 'unavailable').replace(/\s+/g, ' ').slice(0, 240)}]`).join(', ');
295
313
  throw new Error(`LiveDesk Hub startup cleanup could not release port/process owner(s): ${summary}. LiveDesk keeps the configured port fixed; stop that process or choose an explicit --port/--remote-port value.`);
296
314
  }
297
315
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.252",
3
+ "version": "0.1.253",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {