mirror of
https://github.com/got-feedBack/feedBack-desktop.git
synced 2026-10-02 19:32:38 +00:00
Phase A wiring (plan §6.8/§8/§9): - lease-bridge.ts: holder identity derived from the IPC sender (compound identity — enforced wc id + attributed tag), webContents destroy → death invalidation, main-frame navigation → reload grace window, capture demand drives startAudio/stopAudio, detection demand drives setNoteDetectionEnabled. - audio-bridge.ts: audio:leases:* channels; raw startAudio/stopAudio now resume/suspend demands (user authority, §8.3); raw detection disarm is ignored while a demand holder still needs it armed (fixes 6.3's last-disarmer-kills-concurrent-consumer); log-once legacy telemetry. - preload: audio.leases.* (acquire/release/takeover/getHolder/ acquireDemand/releaseDemand/snapshot/onEvent). - contract snapshots regenerated deliberately (7 IPC channels, 1 preload key). - tests: lease-bridge suite (9) incl. death matrix destroy/reload paths; _load-ts gains a .ts require hook for cross-module TS imports. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
49 lines
1.7 KiB
JavaScript
49 lines
1.7 KiB
JavaScript
// Shared helper: compile a TypeScript module on the fly and load it as CommonJS,
|
|
// matching the transpile-on-load pattern used by the other node:test suites
|
|
// (see audio-effects-executor.test.js). Lets us unit-test the pure config-*.ts
|
|
// modules without a build step or an electron runtime.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const Module = require('node:module');
|
|
const ts = require('typescript');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
|
|
// Let a loaded .ts module require sibling .ts modules (e.g. lease-bridge.ts
|
|
// → ./lease-registry). Registering the extension also makes Node's resolver
|
|
// consider .ts files for extension-less requires.
|
|
if (!Module._extensions['.ts']) {
|
|
Module._extensions['.ts'] = (mod, filename) => {
|
|
const source = fs.readFileSync(filename, 'utf8');
|
|
const compiled = ts.transpileModule(source, {
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
target: ts.ScriptTarget.ES2022,
|
|
esModuleInterop: true,
|
|
},
|
|
fileName: filename,
|
|
}).outputText;
|
|
mod._compile(compiled, filename);
|
|
};
|
|
}
|
|
|
|
function loadTs(relPath) {
|
|
const file = path.join(ROOT, relPath);
|
|
const source = fs.readFileSync(file, 'utf8');
|
|
const compiled = ts.transpileModule(source, {
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
target: ts.ScriptTarget.ES2022,
|
|
esModuleInterop: true,
|
|
},
|
|
fileName: file,
|
|
}).outputText;
|
|
const mod = new Module(file, module);
|
|
mod.filename = file;
|
|
mod.paths = Module._nodeModulePaths(path.dirname(file));
|
|
mod._compile(compiled, file);
|
|
return mod.exports;
|
|
}
|
|
|
|
module.exports = { loadTs, ROOT };
|