UNPKG

2.61 kBSource Map (JSON)View Raw
1{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":";AAAA;;;;GAIG;AACH,SAAgB,SAAS;IACvB,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC;AAC7G,CAAC;AAFD,8BAEC;AAED;;;;GAIG;AACH,iHAAiH;AACjH,SAAgB,cAAc,CAAC,GAAQ,EAAE,OAAe;IACtD,sEAAsE;IACtE,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAHD,wCAGC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CAAI,UAAkB;IAC9C,IAAI,GAAkB,CAAC;IAEvB,IAAI;QACF,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;KAC1C;IAAC,OAAO,CAAC,EAAE;QACV,WAAW;KACZ;IAED,IAAI;QACM,IAAA,2CAAG,CAAuC;QAClD,GAAG,GAAG,cAAc,CAAC,MAAM,EAAK,GAAG,EAAE,sBAAiB,UAAY,CAAM,CAAC;KAC1E;IAAC,OAAO,CAAC,EAAE;QACV,WAAW;KACZ;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAjBD,gCAiBC","sourcesContent":["/**\n * Checks whether we're in the Node.js or Browser environment\n *\n * @returns Answer to given question\n */\nexport function isNodeEnv(): boolean {\n return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';\n}\n\n/**\n * Requires a module which is protected against bundler minification.\n *\n * @param request The module path to resolve\n */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\nexport function dynamicRequire(mod: any, request: string): any {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return mod.require(request);\n}\n\n/**\n * Helper for dynamically loading module that should work with linked dependencies.\n * The problem is that we _should_ be using `require(require.resolve(moduleName, { paths: [cwd()] }))`\n * However it's _not possible_ to do that with Webpack, as it has to know all the dependencies during\n * build time. `require.resolve` is also not available in any other way, so we cannot create,\n * a fake helper like we do with `dynamicRequire`.\n *\n * We always prefer to use local package, thus the value is not returned early from each `try/catch` block.\n * That is to mimic the behavior of `require.resolve` exactly.\n *\n * @param moduleName module name to require\n * @returns possibly required module\n */\nexport function loadModule<T>(moduleName: string): T | undefined {\n let mod: T | undefined;\n\n try {\n mod = dynamicRequire(module, moduleName);\n } catch (e) {\n // no-empty\n }\n\n try {\n const { cwd } = dynamicRequire(module, 'process');\n mod = dynamicRequire(module, `${cwd()}/node_modules/${moduleName}`) as T;\n } catch (e) {\n // no-empty\n }\n\n return mod;\n}\n"]}
\No newline at end of file