[TGUI] Added prettierx

This commit is contained in:
Casey
2022-06-25 17:57:28 -04:00
committed by CHOMPStation2
parent 0c9b70b451
commit da183d8607
441 changed files with 16329 additions and 22443 deletions

View File

@@ -18,7 +18,7 @@ const logger = createLogger('retrace');
const { SourceMapConsumer } = SourceMap;
const sourceMaps = [];
export const loadSourceMaps = async bundleDir => {
export const loadSourceMaps = async (bundleDir) => {
// Destroy and garbage collect consumers
while (sourceMaps.length !== 0) {
const { consumer } = sourceMaps.shift();
@@ -29,30 +29,28 @@ export const loadSourceMaps = async bundleDir => {
for (let path of paths) {
try {
const file = basename(path).replace('.map', '');
const consumer = await new SourceMapConsumer(
JSON.parse(fs.readFileSync(path, 'utf8')));
const consumer = await new SourceMapConsumer(JSON.parse(fs.readFileSync(path, 'utf8')));
sourceMaps.push({ file, consumer });
}
catch (err) {
} catch (err) {
logger.error(err);
}
}
logger.log(`loaded ${sourceMaps.length} source maps`);
};
export const retrace = stack => {
export const retrace = (stack) => {
if (typeof stack !== 'string') {
logger.log('ERROR: Stack is not a string!', stack);
return stack;
}
const header = stack.split(/\n\s.*at/)[0];
const mappedStack = parseStackTrace(stack)
.map(frame => {
.map((frame) => {
if (!frame.file) {
return frame;
}
// Find the correct source map
const sourceMap = sourceMaps.find(sourceMap => {
const sourceMap = sourceMaps.find((sourceMap) => {
return frame.file.includes(sourceMap.file);
});
if (!sourceMap) {
@@ -72,15 +70,13 @@ export const retrace = stack => {
column: mappedFrame.column,
};
})
.map(frame => {
.map((frame) => {
// Stringify the frame
const { file, methodName, lineNumber } = frame;
if (!file) {
return ` at ${methodName}`;
}
const compactPath = file
.replace(/^webpack:\/\/\/?/, './')
.replace(/.*node_modules\//, '');
const compactPath = file.replace(/^webpack:\/\/\/?/, './').replace(/.*node_modules\//, '');
return ` at ${methodName} (${compactPath}:${lineNumber})`;
})
.join('\n');