11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst os = require('os'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/; 51cb0ef41Sopenharmony_ciconst pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; 61cb0ef41Sopenharmony_ciconst homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir(); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cimodule.exports = (stack, options) => { 91cb0ef41Sopenharmony_ci options = Object.assign({pretty: false}, options); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci return stack.replace(/\\/g, '/') 121cb0ef41Sopenharmony_ci .split('\n') 131cb0ef41Sopenharmony_ci .filter(line => { 141cb0ef41Sopenharmony_ci const pathMatches = line.match(extractPathRegex); 151cb0ef41Sopenharmony_ci if (pathMatches === null || !pathMatches[1]) { 161cb0ef41Sopenharmony_ci return true; 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci const match = pathMatches[1]; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci // Electron 221cb0ef41Sopenharmony_ci if ( 231cb0ef41Sopenharmony_ci match.includes('.app/Contents/Resources/electron.asar') || 241cb0ef41Sopenharmony_ci match.includes('.app/Contents/Resources/default_app.asar') 251cb0ef41Sopenharmony_ci ) { 261cb0ef41Sopenharmony_ci return false; 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci return !pathRegex.test(match); 301cb0ef41Sopenharmony_ci }) 311cb0ef41Sopenharmony_ci .filter(line => line.trim() !== '') 321cb0ef41Sopenharmony_ci .map(line => { 331cb0ef41Sopenharmony_ci if (options.pretty) { 341cb0ef41Sopenharmony_ci return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~'))); 351cb0ef41Sopenharmony_ci } 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci return line; 381cb0ef41Sopenharmony_ci }) 391cb0ef41Sopenharmony_ci .join('\n'); 401cb0ef41Sopenharmony_ci}; 41