{"version":3,"file":"module.mjs","names":[],"sources":["../../../src/nitro-v3/module.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { Nitro } from 'nitro/types'\nimport type { NitroModuleOptions } from '../nitro'\n\nexport type { NitroModuleOptions }\n\nconst _dir = dirname(fileURLToPath(import.meta.url))\n\nexport default function mxllog(options?: NitroModuleOptions) {\n  return {\n    name: '@safaricom-mxl/log',\n    setup(nitro: Nitro) {\n      // Push the plugin (no extension — Nitro's bundler resolves it)\n      nitro.options.plugins = nitro.options.plugins || []\n      nitro.options.plugins.push(resolve(_dir, 'plugin'))\n\n      // explicitly tell nitro to bundle mxllog's files to correctly resolve nitro dependencies\n      if (!nitro.options.noExternals) {\n        nitro.options.noExternals = ['@safaricom-mxl/log']\n      } else if (Array.isArray(nitro.options.noExternals)) {\n        nitro.options.noExternals.push('@safaricom-mxl/log')\n      }\n      \n\n      // Set error handler only if not already configured by user\n      if (!nitro.options.errorHandler) {\n        nitro.options.errorHandler = [resolve(_dir, 'errorHandler')]\n      } else if (Array.isArray(nitro.options.errorHandler)) {\n        nitro.options.errorHandler.unshift(resolve(_dir, 'errorHandler'))\n      } else if (typeof nitro.options.errorHandler === 'string') {\n        nitro.options.errorHandler = [resolve(_dir, 'errorHandler'), nitro.options.errorHandler]\n      }\n\n      // Inject config into runtimeConfig — works in production where the\n      // plugin is bundled through Nitro's builder and the virtual\n      // runtime-config module resolves correctly.\n      nitro.options.runtimeConfig = nitro.options.runtimeConfig || {}\n      nitro.options.runtimeConfig.mxllog = options || {}\n\n      // In dev mode, Nitro loads plugins externally (not bundled), so the\n      // virtual runtime-config module is unreachable and useRuntimeConfig()\n      // returns a stub without our values. process.env is inherited by the\n      // Worker Threads that run the dev server, making it a reliable bridge.\n      // The plugin reads: useRuntimeConfig().mxllog ?? process.env.__EVLOG_CONFIG\n      process.env.__EVLOG_CONFIG = JSON.stringify(options || {})\n    },\n  }\n}\n"],"mappings":";;;AAOA,MAAM,OAAO,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEpD,SAAwB,OAAO,SAA8B;AAC3D,QAAO;EACL,MAAM;EACN,MAAM,OAAc;AAElB,SAAM,QAAQ,UAAU,MAAM,QAAQ,WAAW,EAAE;AACnD,SAAM,QAAQ,QAAQ,KAAK,QAAQ,MAAM,SAAS,CAAC;AAGnD,OAAI,CAAC,MAAM,QAAQ,YACjB,OAAM,QAAQ,cAAc,CAAC,qBAAqB;YACzC,MAAM,QAAQ,MAAM,QAAQ,YAAY,CACjD,OAAM,QAAQ,YAAY,KAAK,qBAAqB;AAKtD,OAAI,CAAC,MAAM,QAAQ,aACjB,OAAM,QAAQ,eAAe,CAAC,QAAQ,MAAM,eAAe,CAAC;YACnD,MAAM,QAAQ,MAAM,QAAQ,aAAa,CAClD,OAAM,QAAQ,aAAa,QAAQ,QAAQ,MAAM,eAAe,CAAC;YACxD,OAAO,MAAM,QAAQ,iBAAiB,SAC/C,OAAM,QAAQ,eAAe,CAAC,QAAQ,MAAM,eAAe,EAAE,MAAM,QAAQ,aAAa;AAM1F,SAAM,QAAQ,gBAAgB,MAAM,QAAQ,iBAAiB,EAAE;AAC/D,SAAM,QAAQ,cAAc,SAAS,WAAW,EAAE;AAOlD,WAAQ,IAAI,iBAAiB,KAAK,UAAU,WAAW,EAAE,CAAC;;EAE7D"}