UNPKG

@posthog/nextjs-config

Version:

NextJS configuration helper for Posthog 🦔

112 lines (111 loc) • 4.21 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.n = (module)=>{ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module; __webpack_require__.d(getter, { a: getter }); return getter; }; })(); (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { buildLocalBinaryPaths: ()=>buildLocalBinaryPaths, resolveBinaryPath: ()=>resolveBinaryPath, callPosthogCli: ()=>callPosthogCli }); const external_path_namespaceObject = require("path"); var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject); const external_fs_namespaceObject = require("fs"); var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject); const external_child_process_namespaceObject = require("child_process"); function resolveBinaryPath(envPath, cwd, binName) { const envLocations = envPath.split(external_path_default().delimiter); const localLocations = buildLocalBinaryPaths(cwd); const directories = [ ...new Set([ ...envLocations, ...localLocations ]) ]; for (const directory of directories){ const binaryPath = external_path_default().join(directory, binName); if (external_fs_default().existsSync(binaryPath)) return binaryPath; } throw new Error(`Binary ${binName} not found`); } const buildLocalBinaryPaths = (cwd)=>{ const localPaths = getLocalPaths(external_path_default().resolve(cwd)).map((localPath)=>external_path_default().join(localPath, 'node_modules/.bin')); return localPaths; }; const getLocalPaths = (startPath)=>{ const paths = []; let currentPath = startPath; while(true){ paths.push(currentPath); const parentPath = external_path_default().resolve(currentPath, '..'); if (parentPath === currentPath) break; currentPath = parentPath; } return paths; }; async function callPosthogCli(args, env, verbose) { let binaryLocation; try { var _process_env_PATH; binaryLocation = resolveBinaryPath(null != (_process_env_PATH = process.env.PATH) ? _process_env_PATH : '', __dirname, 'posthog-cli'); } catch (e) { throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`); } if (verbose) console.log('running posthog-cli from ', binaryLocation); const child = (0, external_child_process_namespaceObject.spawn)(binaryLocation, [ ...args ], { stdio: verbose ? 'inherit' : 'ignore', env, cwd: process.cwd() }); await new Promise((resolve, reject)=>{ child.on('close', (code)=>{ if (0 === code) resolve(); else reject(new Error(`Command failed with code ${code}`)); }); child.on('error', (error)=>{ reject(error); }); }); } exports.buildLocalBinaryPaths = __webpack_exports__.buildLocalBinaryPaths; exports.callPosthogCli = __webpack_exports__.callPosthogCli; exports.resolveBinaryPath = __webpack_exports__.resolveBinaryPath; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "buildLocalBinaryPaths", "callPosthogCli", "resolveBinaryPath" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true });