@@ -64,40 +64,40 @@ export async function injectShims(outDir, main, antiCrash, polyfillRequire) {
6464 const tail = '\n})();' ;
6565 const requireScript = polyfillRequire
6666 ? [
67- '// --- CommandKit require() polyfill ---' ,
68- ' if (typeof require === "undefined") {' ,
69- ' const { createRequire } = await import("node:module");' ,
70- ' const __require = createRequire(import.meta.url);' ,
71- ' Object.defineProperty(globalThis, "require", {' ,
72- ' value: (id) => {' ,
73- ' return __require(id);' ,
74- ' },' ,
75- ' configurable: true,' ,
76- ' enumerable: false,' ,
77- ' writable: true,' ,
78- ' });' ,
79- ' }' ,
80- '// --- CommandKit require() polyfill ---' ,
81- ] . join ( '\n' )
67+ '// --- CommandKit require() polyfill ---' ,
68+ ' if (typeof require === "undefined") {' ,
69+ ' const { createRequire } = await import("node:module");' ,
70+ ' const __require = createRequire(import.meta.url);' ,
71+ ' Object.defineProperty(globalThis, "require", {' ,
72+ ' value: (id) => {' ,
73+ ' return __require(id);' ,
74+ ' },' ,
75+ ' configurable: true,' ,
76+ ' enumerable: false,' ,
77+ ' writable: true,' ,
78+ ' });' ,
79+ ' }' ,
80+ '// --- CommandKit require() polyfill ---' ,
81+ ] . join ( '\n' )
8282 : '' ;
8383
8484 const antiCrashScript = antiCrash
8585 ? [
86- '// --- CommandKit Anti-Crash Monitor ---' ,
87- " // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process" ,
88- ' // instead of using it as a means to resume operation.' ,
89- ' // But it exists here due to compatibility reasons with discord bot ecosystem.' ,
90- " const p = (t) => `\\x1b[33m${t}\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';" ,
91- ' if (!process.eventNames().includes(e1)) // skip if it is already handled' ,
92- ' process.on(e1, (e) => {' ,
93- ' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));' ,
94- ' })' ,
95- ' if (!process.eventNames().includes(e2)) // skip if it is already handled' ,
96- ' process.on(e2, (r) => {' ,
97- ' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));' ,
98- ' });' ,
99- '// --- CommandKit Anti-Crash Monitor ---' ,
100- ] . join ( '\n' )
86+ '// --- CommandKit Anti-Crash Monitor ---' ,
87+ " // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process" ,
88+ ' // instead of using it as a means to resume operation.' ,
89+ ' // But it exists here due to compatibility reasons with discord bot ecosystem.' ,
90+ " const p = (t) => `\\x1b[33m${t}\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';" ,
91+ ' if (!process.eventNames().includes(e1)) // skip if it is already handled' ,
92+ ' process.on(e1, (e) => {' ,
93+ ' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));' ,
94+ ' })' ,
95+ ' if (!process.eventNames().includes(e2)) // skip if it is already handled' ,
96+ ' process.on(e2, (r) => {' ,
97+ ' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));' ,
98+ ' });' ,
99+ '// --- CommandKit Anti-Crash Monitor ---' ,
100+ ] . join ( '\n' )
101101 : '' ;
102102
103103 const contents = await readFile ( path , 'utf-8' ) ;
0 commit comments