refactor(native-host): modularize host.js and holesail-manager.js
CI / Build & Test (push) Successful in 2m46s

Split host.js (435 lines) into host/{paths,logger,startup,message-router}.js.
Split holesail-manager.js (698 lines) into holesail-manager/{state,settings,
connections,port-allocator,servers,virtual-hosts,service-tunnels,index}.js.

Top-level host.js and holesail-manager.js become thin shims so index.mjs
requires no changes. Deleted dev scratch file test-cp.mjs.

Updated CI with 12 new node --check lines for all sub-modules.
Updated docs/ARCHITECTURE.md with per-file tables for host/ and
holesail-manager/ sub-modules.

No functionality changed. No new dependencies.
This commit is contained in:
Raven Scott
2026-02-28 23:15:08 -05:00
parent 82ab44c4b1
commit 15caac7032
17 changed files with 1274 additions and 1136 deletions
+53
View File
@@ -0,0 +1,53 @@
/**
* Settings management — in-memory settings with persistence via saveStateSync.
* Depends on: state.js (SETTINGS_DEFAULTS, saveStateSync via the index snapshot callback)
*/
const { SETTINGS_DEFAULTS } = require('./state.js');
let currentSettings = { ...SETTINGS_DEFAULTS };
let runtimeProxyPort = SETTINGS_DEFAULTS.proxyPort;
let _saveState = null; // injected by index.js
function init(saveStateFn) {
_saveState = saveStateFn;
}
function applyLoaded(loaded) {
currentSettings = { ...SETTINGS_DEFAULTS, ...loaded };
if (currentSettings.proxyPort) runtimeProxyPort = currentSettings.proxyPort;
}
function getSettings() {
return { ...currentSettings };
}
function updateSettings(patch) {
if (!patch || typeof patch !== 'object') return { requiresRestart: false };
let requiresRestart = false;
if (typeof patch.proxyPort === 'number' && patch.proxyPort > 0 && patch.proxyPort < 65536) {
if (patch.proxyPort !== currentSettings.proxyPort) requiresRestart = true;
currentSettings.proxyPort = patch.proxyPort;
runtimeProxyPort = patch.proxyPort;
}
if (typeof patch.connectProxyPort === 'number' && patch.connectProxyPort > 0 && patch.connectProxyPort < 65536) {
if (patch.connectProxyPort !== currentSettings.connectProxyPort) requiresRestart = true;
currentSettings.connectProxyPort = patch.connectProxyPort;
}
if (typeof patch.readyTimeoutMs === 'number') currentSettings.readyTimeoutMs = patch.readyTimeoutMs;
if (typeof patch.notifyOnDisconnect === 'boolean') currentSettings.notifyOnDisconnect = patch.notifyOnDisconnect;
if (typeof patch.debug === 'boolean') currentSettings.debug = patch.debug;
if (typeof patch.disableOnFileUrls === 'boolean') currentSettings.disableOnFileUrls = patch.disableOnFileUrls;
if (typeof patch.backupRetention === 'number') currentSettings.backupRetention = patch.backupRetention;
if (_saveState) _saveState();
return { requiresRestart };
}
function getProxyPort() { return runtimeProxyPort; }
function setProxyPort(port) {
if (typeof port === 'number' && port > 0 && port < 65536) runtimeProxyPort = port;
}
function getReadyTimeoutMs() { return currentSettings.readyTimeoutMs; }
module.exports = { init, applyLoaded, getSettings, updateSettings, getProxyPort, setProxyPort, getReadyTimeoutMs };