why-is-node-still-running
Version:
Find out exactly why Node is still running.
52 lines • 5.65 kB
JavaScript
module.exports=(()=>{const e={},r=[null];function t(t,n,o){e[t]={dependencies:n,factory:o},r[0]=t}t("require",["exports"],(e=>{Object.defineProperty(e,"__cjsModule",{value:!0}),Object.defineProperty(e,"default",{value:e=>o(e)})})),
/*!
* Copyright 2012 the V8 project authors. All rights reserved. Redistribution
* and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
t("lib/format",["require","exports"],(function(e,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.formatStackTrace=void 0,r.formatStackTrace=function(e,r){const t=[];try{t.push(e.toString())}catch(e){try{t.push("<error: "+e+">")}catch(e){t.push("<error>")}}for(const e of r){let r;try{r=e.toString()}catch(e){try{r="<error: "+e+">"}catch(e){r="<error>"}}t.push(" at "+r)}return t.join("\n")}})),
/*! https://github.com/defunctzombie/node-stackback/blob/master/index.js */
t("lib/stackback",["require","exports","lib/format"],(function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.stackback=void 0,r.stackback=function(e){const r=Error.prepareStackTrace;return Error.prepareStackTrace=function(e,n){return Object.defineProperty(e,"_sb_callsites",{value:n}),(r||t.formatStackTrace)(e,n)},e.stack,e._sb_callsites?(Error.prepareStackTrace=r,e._sb_callsites):[]}})),
/*!
* why-is-node-still-running
*
* Find out exactly why Node is still running.
*
* Copyright (c) 2020-present, cheap glitch
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
t("index",["require","exports","path","fs","async_hooks","lib/stackback"],(function(e,r,t,n,o,c){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.whyIsNodeStillRunning=void 0;const s=new Map,i=o.createHook({init(e,r,t,n){if("TIMERWRAP"==r||"PROMISE"==r)return;const o=new Error,i=c.stackback(o);s.set(e,{type:r,stacks:i,resource:n})},destroy(e){s.delete(e)}});i.enable(),r.whyIsNodeStillRunning=function(e=console){i.disable();const r=[...s.values()].filter((e=>"Timeout"!=e.type||"function"!=typeof e.resource.hasRef||e.resource.hasRef()));e.error(`There are ${r.length} handle(s) keeping the process running:`),r.forEach((r=>function(e,r){const o=r.stacks.slice(1).filter((e=>{const r=e.getFileName();return r&&r.includes(t.sep)&&0!=r.indexOf("internal"+t.sep)}));if(e.error("\n"+r.type),!o[0])return void e.error("(unknown stack trace)");const c=" ".repeat(Math.max(...o.map((e=>(e.getFileName()+":"+e.getLineNumber()).length))));for(const r of o){const t=r.getFileName()+":"+r.getLineNumber();if(n.existsSync(r.getFileName())){const o=n.readFileSync(r.getFileName(),"utf8").split(/\n|\r\n/);e.error(t+c.slice(t.length)+" - "+o[r.getLineNumber()-1].trim())}else e.error(t+c.slice(t.length))}}(e,r)))}}));const n={};function o(r){if(n[r])return n[r];if("exports"===r)return{};const t=function(r){return e[r]?e[r]:e[r+"/index"]?e[r+"/index"]:{dependencies:["exports"],factory:e=>{try{Object.defineProperty(e,"__cjsModule",{value:!0}),Object.defineProperty(e,"default",{value:require(r)})}catch(e){throw Error(['module "',r,'" not found.'].join(""))}}}}(r);n[r]={};const c=t.dependencies.map((e=>o(e)));t.factory(...c);const s=c[t.dependencies.indexOf("exports")];return n[r]=s.__cjsModule?s.default:s,n[r]}if(null!==r[0])return o(r[0])})();