// scripts/navigator-patch.cjs // // Workaround for Node 22 + @webex/internal-media-core. // // The bot framework transitively depends on `@webex/internal-media-core`, whose // pre-compiled CJS bundle does `commonjsGlobal.navigator = { ... }` at import time. // Node 22+ exposes `globalThis.navigator` as a non-writable property, so that // assignment throws: // // TypeError: Cannot set property navigator of # which has only a getter // // `--require` runs synchronously before any ESM resolution, which is the only // hook early enough to fix the descriptor before the framework loads. // // We make the property writable + configurable, preserving any existing value // so anything that reads from it later still works. 'use strict'; // ----------------------------------------------------------------------------- // Node version guard. // // Sendi runs .ts files directly via Node's native type-stripping loader, // which is unflagged from Node 22.18. On older Nodes you get: // TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" // Fail loudly with an actionable message instead. // ----------------------------------------------------------------------------- (function checkNodeVersion() { const [maj, min] = process.versions.node.split('.').map(Number); const ok = maj > 22 || (maj === 22 && min >= 18); if (!ok) { // eslint-disable-next-line no-console console.error( '\n[sendi] Unsupported Node.js version: ' + process.versions.node + '\n' + ' Sendi requires Node >= 22.18 (native .ts stripping).\n' + ' Fix with `nvm use` (a .nvmrc is checked in) or install Node 22.18+.\n' + ' Current node binary: ' + process.execPath + '\n', ); process.exit(1); } })(); try { const desc = Object.getOwnPropertyDescriptor(globalThis, 'navigator'); if (desc && desc.writable !== true) { const current = 'value' in desc ? desc.value : (desc.get ? desc.get() : undefined); Object.defineProperty(globalThis, 'navigator', { value: current, writable: true, configurable: true, }); } } catch (err) { // If the patch can't apply, log loudly so the bot startup failure is at // least traceable; the framework import will then fail with the original error. // eslint-disable-next-line no-console console.warn('[navigator-patch] failed to make globalThis.navigator writable:', err && err.message); }