- Build: explicitly write tt-native package.json into the bundle in
CI / Build & Test (push) Successful in 3m47s
CI / Build & Test (push) Successful in 3m47s
patchBundle so the runtime never gets empty content for that key (fixes "Unexpected end of JSON input" in Module._extensions..json when the host is started by the extension on Windows). - State: treat empty or whitespace-only state.json (and legacy persist file) as missing and return default state instead of throwing in JSON.parse. - State: add ensureStorageDir() and call it from message-router after setStoragePath so the storage directory exists on fresh install before any state is loaded or saved.
This commit is contained in:
@@ -65,6 +65,10 @@ function setStoragePath(baseDir) {
|
||||
stateModule.setStoragePath(baseDir);
|
||||
}
|
||||
|
||||
function ensureStorageDir() {
|
||||
stateModule.ensureStorageDir();
|
||||
}
|
||||
|
||||
// ── Restore persisted state ───────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
@@ -108,6 +112,7 @@ module.exports = {
|
||||
setEventEmitter,
|
||||
// Storage
|
||||
setStoragePath,
|
||||
ensureStorageDir,
|
||||
// Settings
|
||||
getSettings: settingsModule.getSettings,
|
||||
updateSettings: settingsModule.updateSettings,
|
||||
|
||||
@@ -47,6 +47,16 @@ function getStatePath() {
|
||||
return stateFilePath;
|
||||
}
|
||||
|
||||
/** Create the storage directory if it does not exist (e.g. fresh install on Windows). */
|
||||
function ensureStorageDir() {
|
||||
const dir = path.dirname(getStatePath());
|
||||
try {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
} catch (e) {
|
||||
if (process.stderr) process.stderr.write('[holesail-manager] could not create storage dir: ' + e.message + '\n');
|
||||
}
|
||||
}
|
||||
|
||||
function getLegacyPersistPath() {
|
||||
const dir = path.dirname(getStatePath());
|
||||
return path.join(dir, LEGACY_PERSIST_FILENAME);
|
||||
@@ -82,6 +92,8 @@ function loadState() {
|
||||
|
||||
try {
|
||||
const raw = fs.readFileSync(file, 'utf8');
|
||||
const trimmed = raw && typeof raw === 'string' ? raw.trim() : '';
|
||||
if (!trimmed) return buildDefaultState();
|
||||
const data = JSON.parse(raw);
|
||||
if (!data || typeof data !== 'object') return buildDefaultState();
|
||||
const out = {
|
||||
@@ -110,6 +122,8 @@ function loadState() {
|
||||
const legacyFile = getLegacyPersistPath();
|
||||
try {
|
||||
const raw = fs.readFileSync(legacyFile, 'utf8');
|
||||
const trimmed = raw && typeof raw === 'string' ? raw.trim() : '';
|
||||
if (!trimmed) return buildDefaultState();
|
||||
const data = JSON.parse(raw);
|
||||
if (process.stderr) process.stderr.write('[holesail-manager] migrating from ' + legacyFile + ' to ' + file + '\n');
|
||||
const out = {
|
||||
@@ -134,4 +148,4 @@ function loadState() {
|
||||
return buildDefaultState();
|
||||
}
|
||||
|
||||
module.exports = { SETTINGS_DEFAULTS, setStoragePath, loadState, saveStateSync, buildDefaultState };
|
||||
module.exports = { SETTINGS_DEFAULTS, setStoragePath, loadState, saveStateSync, buildDefaultState, ensureStorageDir };
|
||||
|
||||
@@ -12,6 +12,7 @@ const { initStartup, getProxiesReadyPromise, getTunnelsRestoredPromise, setTunne
|
||||
|
||||
const holesailManager = require('../holesail-manager/index.js');
|
||||
holesailManager.setStoragePath(STORAGE_PATH);
|
||||
holesailManager.ensureStorageDir();
|
||||
|
||||
const certificateAuthority = require('../managers/certificate-authority.js');
|
||||
const httpsProxy = require('../proxy/https-proxy.js');
|
||||
|
||||
@@ -180,6 +180,13 @@ function patchBundle(bundle, hosts) {
|
||||
}
|
||||
}
|
||||
)
|
||||
// Ensure tt-native package.json has content in the bundle. On Windows the runtime
|
||||
// can end up reading empty content for this key (path/bundle handling), causing
|
||||
// "Unexpected end of JSON input" when the .json loader runs. Explicitly write it.
|
||||
const pkgPath = path.join(NATIVE_HOST_DIR, 'node_modules', 'tt-native', 'package.json')
|
||||
if (fs.existsSync(pkgPath)) {
|
||||
bundle.write(ttNativePkgKey, fs.readFileSync(pkgPath))
|
||||
}
|
||||
console.log(' Patched tt-native binding (host-specific resolutions)')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user