UNPKG

signalk-server

Version:

An implementation of a [Signal K](http://signalk.org) server for boats.

82 lines 3.53 kB
"use strict"; /* * BaconJS backward-compatibility shim * * The server uses BaconJS 3.x which has breaking API changes from 1.x/0.7.x. * Plugins may bundle their own older BaconJS, causing version mismatches when * they operate on Bacon.Bus objects from the server's StreamBundle. * * The critical incompatibility: BaconJS 3.x Event objects use boolean * properties (event.isEnd), while 1.x uses methods (event.isEnd()). When a * plugin's 1.x code subscribes to a server 3.x Bus, it receives 3.x Events * and crashes with "TypeError: e.isEnd is not a function". * * This module solves the problem by: * 1. Hooking Node's module resolution so ALL require('baconjs') calls in the * process return the server's 3.x version — eliminating version mismatches * 2. Patching 3.x to restore the .map('.property') string shorthand that * existed in 1.x (used by plugins like signalk-to-nmea2000) * * This module MUST be imported before any other module that uses BaconJS. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const module_1 = __importDefault(require("module")); const Bacon = __importStar(require("baconjs")); const serverBaconPath = require.resolve('baconjs'); const ModuleInternal = module_1.default; const origResolveFilename = ModuleInternal._resolveFilename; ModuleInternal._resolveFilename = function (request, parent, isMain, options) { if (request === 'baconjs') { return serverBaconPath; } return origResolveFilename.call(this, request, parent, isMain, options); }; function patchMapShorthand(proto) { const origMap = proto.map; proto.map = function (f) { if (typeof f === 'string' && f.startsWith('.')) { const prop = f.substring(1); return origMap.call(this, (v) => v !== null && v !== undefined ? v[prop] : undefined); } return origMap.call(this, f); }; } patchMapShorthand(Bacon.EventStream.prototype); patchMapShorthand(Bacon.Property.prototype); //# sourceMappingURL=baconjs-compat.js.map