Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@supertenant/core / src / util / applicationUnderMonitoring.js
Size: Mime:
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const fs=require("fs"),path=require("path");let logger;logger=require("../logger").getLogger("util/applicationUnderMonitoring",newLogger=>{logger=newLogger});let parsedMainPackageJson,mainPackageJsonPath,nodeModulesPath,appInstalledIntoNodeModules=!1;function isAppInstalledIntoNodeModules(){return appInstalledIntoNodeModules}function getMainPackageJsonStartingAtMainModule(cb){return getMainPackageJsonStartingAtDirectory(null,cb)}function getMainPackageJsonStartingAtDirectory(startDirectory,cb){if(void 0!==parsedMainPackageJson)return process.nextTick(cb,null,parsedMainPackageJson);getMainPackageJsonPathStartingAtDirectory(startDirectory,(err,packageJsonPath)=>err?process.nextTick(cb,err,null):null==packageJsonPath?process.nextTick(cb):void fs.readFile(packageJsonPath,{encoding:"utf8"},(readFileErr,contents)=>{if(readFileErr)return cb(readFileErr,null);try{parsedMainPackageJson=JSON.parse(contents)}catch(e){return logger.warn("Main package.json file %s cannot be parsed: %s",packageJsonPath,e),cb(e,null)}return cb(null,parsedMainPackageJson)}))}function getMainPackageJsonPathStartingAtMainModule(cb){return getMainPackageJsonPathStartingAtDirectory(null,cb)}function getMainPackageJsonPathStartingAtDirectory(startDirectory,cb){if(void 0!==mainPackageJsonPath)return process.nextTick(cb,null,mainPackageJsonPath);if(!startDirectory){let mainModule=require.main;if(!mainModule){if(!(process._preload_modules&&0<process._preload_modules.length||process.execArgv&&0<process.execArgv.length&&-1!==process.execArgv[0].indexOf("--experimental-loader")&&-1!==process.execArgv[0].indexOf("esm-loader.mjs")))return process.nextTick(cb);mainModule={filename:process.argv[1]}}startDirectory=path.dirname(mainModule.filename)}searchForPackageJsonInDirectoryTreeUpwards(startDirectory,(err,main)=>err?cb(err,null):(mainPackageJsonPath=main,cb(null,mainPackageJsonPath)))}function getMainPackageJson(startDirectory,cb){return"function"==typeof startDirectory?getMainPackageJsonStartingAtMainModule(startDirectory):getMainPackageJsonStartingAtDirectory(startDirectory,cb)}function getMainPackageJsonPath(startDirectory,cb){return"function"==typeof startDirectory?getMainPackageJsonPathStartingAtMainModule(startDirectory):getMainPackageJsonPathStartingAtDirectory(startDirectory,cb)}function searchForPackageJsonInDirectoryTreeUpwards(dir,cb){const pathToCheck=path.join(dir,"package.json");fs.stat(pathToCheck,(err,stats)=>{return err?"ENOENT"===err.code?searchInParentDir(dir,searchForPackageJsonInDirectoryTreeUpwards,cb):process.nextTick(cb,err,null):(appInstalledIntoNodeModules=0<=dir.indexOf("node_modules"))?process.nextTick(cb,null,pathToCheck):stats.isFile()?(err=path.join(dir,"node_modules"),void fs.stat(err,(statErr,potentialNodeModulesDirStats)=>statErr?"ENOENT"===statErr.code?searchInParentDir(dir,searchForPackageJsonInDirectoryTreeUpwards,cb):process.nextTick(cb,statErr,null):potentialNodeModulesDirStats.isDirectory()?process.nextTick(cb,null,pathToCheck):searchInParentDir(dir,searchForPackageJsonInDirectoryTreeUpwards,cb))):searchInParentDir(dir,searchForPackageJsonInDirectoryTreeUpwards,cb)})}function findNodeModulesFolder(cb){var mainModule;return void 0!==nodeModulesPath?process.nextTick(cb,null,nodeModulesPath):(mainModule=require.main)?void searchForNodeModulesInDirectoryTreeUpwards(path.dirname(mainModule.filename),(err,nodeModulesPath_)=>err?cb(err,null):(nodeModulesPath=nodeModulesPath_,cb(null,nodeModulesPath))):process.nextTick(cb)}function searchForNodeModulesInDirectoryTreeUpwards(dir,cb){const pathToCheck=path.join(dir,"node_modules");fs.stat(pathToCheck,(err,stats)=>err?"ENOENT"===err.code?searchInParentDir(dir,searchForNodeModulesInDirectoryTreeUpwards,cb):process.nextTick(cb,err,null):stats.isDirectory()?process.nextTick(cb,null,pathToCheck):searchInParentDir(dir,searchForNodeModulesInDirectoryTreeUpwards,cb))}function searchInParentDir(dir,onParentDir,cb){var parentDir=path.resolve(dir,"..");return dir===parentDir?process.nextTick(cb,null,null):onParentDir(parentDir,cb)}module.exports={isAppInstalledIntoNodeModules:isAppInstalledIntoNodeModules,getMainPackageJsonStartingAtMainModule:getMainPackageJsonStartingAtMainModule,getMainPackageJsonStartingAtDirectory:getMainPackageJsonStartingAtDirectory,getMainPackageJsonPathStartingAtMainModule:getMainPackageJsonPathStartingAtMainModule,getMainPackageJsonPathStartingAtDirectory:getMainPackageJsonPathStartingAtDirectory,findNodeModulesFolder:findNodeModulesFolder,getMainPackageJson:getMainPackageJson,getMainPackageJsonPath:getMainPackageJsonPath};