@conflict/beta
Advanced tools
Comparing version 0.9.42 to 0.9.43
{ | ||
"name": "@conflict/beta", | ||
"version": "0.9.42", | ||
"version": "0.9.43", | ||
"description": "The first and only UI framework for Discord bots", | ||
@@ -5,0 +5,0 @@ "main": "exports.js", |
@@ -15,3 +15,2 @@ // dispatch.js | ||
global.__ConflictViewParser = View.createElement; | ||
import { getFile, cleanLines } from './utils.js' | ||
global.__ConflictEnvironment = 'vercel'; | ||
@@ -38,2 +37,44 @@ | ||
export function getFile (error) { | ||
let output = 'Unable to find file location'; | ||
try { | ||
let fileLine = error.stack.split('\n')[1]; | ||
let stackTrace = (fileLine.includes('(') && fileLine.includes(')')) ? fileLine.split('(')[1].split(')')[0] : fileLine.substring(fileLine.indexOf('at') + 3); | ||
let lastColon = stackTrace.lastIndexOf(':'); | ||
let col = stackTrace.substring(lastColon + 1); | ||
let filePath = stackTrace.substring(0, lastColon); | ||
lastColon = filePath.lastIndexOf(':'); | ||
let line = +filePath.substring(lastColon + 1); | ||
filePath = filePath.substring(0, lastColon); | ||
if (filePath.startsWith('file://')) filePath = filePath.substring(7); | ||
const fileData = fs.readFileSync(filePath, 'utf8'); | ||
let snippet = fileData.split('\n').slice(line - 4, line + 2).join('\n'); | ||
let lines = snippet.split('\n'); | ||
if (lines.length < 5) { | ||
snippet = snippet; | ||
} else { | ||
lines = [ | ||
'// ' + path.basename(filePath) + ':' + (line - 3), | ||
lines[0], | ||
lines[1], | ||
lines[2], | ||
lines[3], | ||
'//' + ' '.repeat(col - 3) + '^ ' + error.stack.split('\n')[0] + ' (:' + line + ':' + col + ')', | ||
lines[4], | ||
lines[5], | ||
lines[6] | ||
]; | ||
snippet = lines.join('\n'); | ||
} | ||
output = "```js\n" + snippet + "```"; | ||
} catch (err) {} | ||
return output; | ||
} | ||
export function cleanLines (input, lines) { | ||
return input.split('\n').splice(0, input.split('\n').length - lines).join('\n'); | ||
} | ||
function status (...args) { | ||
@@ -40,0 +81,0 @@ if (args.length === 0) return { ___status: true, status: 200, payload: args[0] }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94856
2407