diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js index 64746d174f66c3f16b10af60217133c5f81cdd59..a3f55965b256bfd2053008b75c06140f27829a8b 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.cjs.js @@ -20,7 +20,7 @@ typeof window !== 'undefined' && lastOf = (x) => x[x.length - 1], nixSlashes$1 = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes$1(process.cwd()) + '/'; /* ------------------------------------------------------------------------ */ class StackTracey { - constructor(input, offset) { + constructor(input, uniPlatform, offset) { this.itemsHeader = []; this.isMP = false; const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser; @@ -35,7 +35,7 @@ class StackTracey { } /* new StackTracey (string) */ if (typeof input === 'string') { - this.isMP = input.indexOf('MiniProgramError') !== -1; + this.isMP = uniPlatform === 'mp-weixin'; input = this.rawParse(input) .slice(offset) .map((x) => this.extractEntryMetadata(x)); @@ -86,13 +86,12 @@ class StackTracey { let result = fullPath; if (isBrowser) result = result.replace(pathRoot, ''); - const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/(.*)/); + const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/); const externalDomain = externalDomainMatch ? externalDomainMatch[2] : undefined; result = externalDomainMatch ? externalDomainMatch[3] : result; - if (!isBrowser) - result = nodeRequire('path').relative(pathRoot, result); + // if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result) return [ nixSlashes$1(result).replace(/^.*\:\/\/?\/?/, ''), externalDomain, @@ -288,14 +287,20 @@ function isThirdParty(relativePath) { } function getConsumer(content) { return new Promise((resolve, reject) => { - if (sourceMap.SourceMapConsumer.with) { - sourceMap.SourceMapConsumer.with(content, null, (consumer) => { + try { + if (sourceMap.SourceMapConsumer.with) { + sourceMap.SourceMapConsumer.with(content, null, (consumer) => { + resolve(consumer); + }); + } + else { + // @ts-ignore + const consumer = sourceMap.SourceMapConsumer(content); resolve(consumer); - }); + } } - else { - // @ts-ignore - resolve(sourceMap.SourceMapConsumer(content)); + catch (error) { + reject(); } }); } @@ -308,8 +313,16 @@ function getSourceMapContent(sourcemapUrl) { uni.request({ url: sourcemapUrl, success: (res) => { - sourcemapCatch[sourcemapUrl] = res.data; - resolve(sourcemapCatch[sourcemapUrl]); + if (res.statusCode === 200) { + sourcemapCatch[sourcemapUrl] = res.data; + resolve(sourcemapCatch[sourcemapUrl]); + } + else { + resolve((sourcemapCatch[sourcemapUrl] = '')); + } + }, + fail() { + resolve((sourcemapCatch[sourcemapUrl] = '')); }, }); } @@ -350,7 +363,7 @@ function joinItem(item) { return `${a}${b}${c}`; } function uniStracktraceyPreset(opts) { - const { base, sourceRoot, splitThirdParty } = opts; + const { base, sourceRoot, splitThirdParty, uniPlatform } = opts; let stack; return { /** @@ -373,7 +386,7 @@ function uniStracktraceyPreset(opts) { let baseAfter = ''; if (stack.isMP) { if (fileRelative.indexOf('app-service.js') !== -1) { - baseAfter = (base.match(/\w$/) ? '/' : '') + 'weixin'; + baseAfter = (base.match(/\w$/) ? '/' : '') + '__WEIXIN__'; if (fileRelative === fileName) { baseAfter += '/__APP__'; } @@ -392,7 +405,7 @@ function uniStracktraceyPreset(opts) { return Promise.resolve(getSourceMapContent(sourcemapUrl)); }, parseStacktrace(stacktrace) { - stack = new StackTracey$1(stacktrace); + stack = new StackTracey$1(stacktrace, uniPlatform); return stack; }, asTableStacktrace({ maxColumnWidths, stacktrace, stack }) { @@ -424,6 +437,12 @@ function uniStracktraceyPreset(opts) { return userError + '\n' + thirdParty; } else { + if (splitThirdParty) { + return { + userError: errorName, + thirdParty: '', + }; + } return errorName; } }, diff --git a/packages/uni-stacktracey/dist/uni-stacktracey.es.js b/packages/uni-stacktracey/dist/uni-stacktracey.es.js index a93b236973016ed22be27519dadd74c6d40eafa5..0061779c2161d911d3b47bb4b0fe61ef9d87f6b2 100644 --- a/packages/uni-stacktracey/dist/uni-stacktracey.es.js +++ b/packages/uni-stacktracey/dist/uni-stacktracey.es.js @@ -12,7 +12,7 @@ typeof window !== 'undefined' && lastOf = (x) => x[x.length - 1], nixSlashes$1 = (x) => x.replace(/\\/g, '/'), pathRoot = isBrowser ? window.location.href : nixSlashes$1(process.cwd()) + '/'; /* ------------------------------------------------------------------------ */ class StackTracey { - constructor(input, offset) { + constructor(input, uniPlatform, offset) { this.itemsHeader = []; this.isMP = false; const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser; @@ -27,7 +27,7 @@ class StackTracey { } /* new StackTracey (string) */ if (typeof input === 'string') { - this.isMP = input.indexOf('MiniProgramError') !== -1; + this.isMP = uniPlatform === 'mp-weixin'; input = this.rawParse(input) .slice(offset) .map((x) => this.extractEntryMetadata(x)); @@ -78,13 +78,12 @@ class StackTracey { let result = fullPath; if (isBrowser) result = result.replace(pathRoot, ''); - const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/(.*)/); + const externalDomainMatch = result.match(/^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/); const externalDomain = externalDomainMatch ? externalDomainMatch[2] : undefined; result = externalDomainMatch ? externalDomainMatch[3] : result; - if (!isBrowser) - result = nodeRequire('path').relative(pathRoot, result); + // if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result) return [ nixSlashes$1(result).replace(/^.*\:\/\/?\/?/, ''), externalDomain, @@ -290,14 +289,20 @@ function isThirdParty(relativePath) { } function getConsumer(content) { return new Promise((resolve, reject) => { - if (SourceMapConsumer.with) { - SourceMapConsumer.with(content, null, (consumer) => { + try { + if (SourceMapConsumer.with) { + SourceMapConsumer.with(content, null, (consumer) => { + resolve(consumer); + }); + } + else { + // @ts-ignore + const consumer = SourceMapConsumer(content); resolve(consumer); - }); + } } - else { - // @ts-ignore - resolve(SourceMapConsumer(content)); + catch (error) { + reject(); } }); } @@ -310,8 +315,16 @@ function getSourceMapContent(sourcemapUrl) { uni.request({ url: sourcemapUrl, success: (res) => { - sourcemapCatch[sourcemapUrl] = res.data; - resolve(sourcemapCatch[sourcemapUrl]); + if (res.statusCode === 200) { + sourcemapCatch[sourcemapUrl] = res.data; + resolve(sourcemapCatch[sourcemapUrl]); + } + else { + resolve((sourcemapCatch[sourcemapUrl] = '')); + } + }, + fail() { + resolve((sourcemapCatch[sourcemapUrl] = '')); }, }); } @@ -352,7 +365,7 @@ function joinItem(item) { return `${a}${b}${c}`; } function uniStracktraceyPreset(opts) { - const { base, sourceRoot, splitThirdParty } = opts; + const { base, sourceRoot, splitThirdParty, uniPlatform } = opts; let stack; return { /** @@ -375,7 +388,7 @@ function uniStracktraceyPreset(opts) { let baseAfter = ''; if (stack.isMP) { if (fileRelative.indexOf('app-service.js') !== -1) { - baseAfter = (base.match(/\w$/) ? '/' : '') + 'weixin'; + baseAfter = (base.match(/\w$/) ? '/' : '') + '__WEIXIN__'; if (fileRelative === fileName) { baseAfter += '/__APP__'; } @@ -394,7 +407,7 @@ function uniStracktraceyPreset(opts) { return Promise.resolve(getSourceMapContent(sourcemapUrl)); }, parseStacktrace(stacktrace) { - stack = new StackTracey$1(stacktrace); + stack = new StackTracey$1(stacktrace, uniPlatform); return stack; }, asTableStacktrace({ maxColumnWidths, stacktrace, stack }) { @@ -426,6 +439,12 @@ function uniStracktraceyPreset(opts) { return userError + '\n' + thirdParty; } else { + if (splitThirdParty) { + return { + userError: errorName, + thirdParty: '', + }; + } return errorName; } }, diff --git a/packages/uni-stacktracey/src/index.ts b/packages/uni-stacktracey/src/index.ts index 8265778637fd8e03a5badfd622288203e2506ff7..4f59b113f2e6f57b17aa8761b49ceecd0201ee78 100644 --- a/packages/uni-stacktracey/src/index.ts +++ b/packages/uni-stacktracey/src/index.ts @@ -197,13 +197,18 @@ function getConsumer( content: string ): Promise { return new Promise((resolve, reject) => { - if (SourceMapConsumer.with) { - SourceMapConsumer.with(content, null, (consumer) => { + try { + if (SourceMapConsumer.with) { + SourceMapConsumer.with(content, null, (consumer) => { + resolve(consumer) + }) + } else { + // @ts-ignore + const consumer = SourceMapConsumer(content) resolve(consumer) - }) - } else { - // @ts-ignore - resolve(SourceMapConsumer(content)) + } + } catch (error) { + reject() } }) } @@ -218,8 +223,15 @@ function getSourceMapContent(sourcemapUrl: string) { uni.request({ url: sourcemapUrl, success: (res) => { - sourcemapCatch[sourcemapUrl] = res.data as string - resolve(sourcemapCatch[sourcemapUrl]) + if (res.statusCode === 200) { + sourcemapCatch[sourcemapUrl] = res.data as string + resolve(sourcemapCatch[sourcemapUrl]) + } else { + resolve((sourcemapCatch[sourcemapUrl] = '')) + } + }, + fail() { + resolve((sourcemapCatch[sourcemapUrl] = '')) }, }) } else { @@ -275,6 +287,7 @@ interface UniStracktraceyPresetOptions { base: string sourceRoot: string splitThirdParty?: boolean + uniPlatform?: string } function joinItem(item: string[]) { @@ -287,7 +300,7 @@ function joinItem(item: string[]) { export function uniStracktraceyPreset( opts: UniStracktraceyPresetOptions ): StacktraceyPreset { - const { base, sourceRoot, splitThirdParty } = opts + const { base, sourceRoot, splitThirdParty, uniPlatform } = opts let stack: StackTracey @@ -311,7 +324,7 @@ export function uniStracktraceyPreset( let baseAfter = '' if (stack.isMP) { if (fileRelative.indexOf('app-service.js') !== -1) { - baseAfter = (base.match(/\w$/) ? '/' : '') + 'weixin' + baseAfter = (base.match(/\w$/) ? '/' : '') + '__WEIXIN__' if (fileRelative === fileName) { baseAfter += '/__APP__' } @@ -329,7 +342,7 @@ export function uniStracktraceyPreset( return Promise.resolve(getSourceMapContent(sourcemapUrl)) }, parseStacktrace(stacktrace) { - stack = new StackTracey(stacktrace) + stack = new StackTracey(stacktrace, uniPlatform) return stack }, asTableStacktrace({ maxColumnWidths, stacktrace, stack }) { @@ -365,6 +378,12 @@ export function uniStracktraceyPreset( return userError + '\n' + thirdParty } else { + if (splitThirdParty) { + return { + userError: errorName, + thirdParty: '', + } + } return errorName } }, diff --git a/packages/uni-stacktracey/src/stacktracey.ts b/packages/uni-stacktracey/src/stacktracey.ts index ac35fd63c8245b4c11c76bda974e66c9354f48a0..81b53330c7eb16fda8c288f24b37167655aef2d0 100644 --- a/packages/uni-stacktracey/src/stacktracey.ts +++ b/packages/uni-stacktracey/src/stacktracey.ts @@ -33,7 +33,11 @@ class StackTracey { itemsHeader: string[] = [] isMP: boolean = false - constructor(input: string | Error | any, offset?: number) { + constructor( + input: string | Error | any, + uniPlatform?: string, + offset?: number + ) { const originalInput = input, isParseableSyntaxError = input && input instanceof SyntaxError && !isBrowser @@ -54,7 +58,7 @@ class StackTracey { /* new StackTracey (string) */ if (typeof input === 'string') { - this.isMP = input.indexOf('MiniProgramError') !== -1 + this.isMP = uniPlatform === 'mp-weixin' input = (this.rawParse(input) as EntryMetadata[]) .slice(offset) .map((x: EntryMetadata) => this.extractEntryMetadata(x)) @@ -117,14 +121,14 @@ class StackTracey { if (isBrowser) result = result.replace(pathRoot, '') const externalDomainMatch = result.match( - /^(http|https)\:\/\/?([^\/]+)\/(.*)/ + /^(http|https)\:\/\/?([^\/]+)\/{1,}(.*)/ ) const externalDomain = externalDomainMatch ? externalDomainMatch[2] : undefined result = externalDomainMatch ? externalDomainMatch[3] : result - if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result) + // if (!isBrowser) result = nodeRequire!('path').relative(pathRoot, result) return [ nixSlashes(result).replace(/^.*\:\/\/?\/?/, ''), // cut webpack:/// and webpack:/ things