@kaspernj/api-maker 1.0.187 → 1.0.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.187",
19
+ "version": "1.0.190",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -50,6 +50,7 @@
50
50
  "qs": ">= 6.9.3",
51
51
  "replaceall": ">= 0.1.6",
52
52
  "strftime": ">= 0.10.0",
53
+ "uniqunize": "^1.0.1",
53
54
  "wake-event": ">= 0.0.1"
54
55
  },
55
56
  "peerDependencies": {
@@ -1,8 +1,12 @@
1
+ const {digg} = require("diggerize")
1
2
  const SourceMapsLoader = require("./source-maps-loader.cjs")
2
3
 
3
4
  module.exports = class ErrorLogger {
4
5
  constructor () {
6
+ this.debug = true
7
+ this.errorOccurred = false
5
8
  this.errors = []
9
+ this.isHandlingError = false
6
10
  this.sourceMapsLoader = new SourceMapsLoader()
7
11
  this.sourceMapsLoader.loadSourceMapsForScriptTags((script) => {
8
12
  const src = script.getAttribute("src")
@@ -23,8 +27,22 @@ module.exports = class ErrorLogger {
23
27
  return this.errors
24
28
  }
25
29
 
30
+ hasErrorOccurred() {
31
+ return digg(this, "errorOccurred")
32
+ }
33
+
34
+ isLoadingSourceMaps() {
35
+ return digg(this, "sourceMapsLoader", "isLoadingSourceMaps")
36
+ }
37
+
38
+ isWorkingOnError() {
39
+ return digg(this, "isHandlingError") || this.isLoadingSourceMaps()
40
+ }
41
+
26
42
  connectOnError () {
27
43
  global.addEventListener("error", (event) => {
44
+ this.errorOccurred = true
45
+
28
46
  if (!this.isHandlingError) {
29
47
  this.isHandlingError = true
30
48
  this.onError(event).finally(() => {
@@ -36,6 +54,8 @@ module.exports = class ErrorLogger {
36
54
 
37
55
  connectUnhandledRejection () {
38
56
  global.addEventListener("unhandledrejection", (event) => {
57
+ this.errorOccurred = true
58
+
39
59
  if (!this.isHandlingError) {
40
60
  this.isHandlingError = true
41
61
  this.onUnhandledRejection(event).finally(() => {
@@ -46,7 +66,8 @@ module.exports = class ErrorLogger {
46
66
  }
47
67
 
48
68
  async onError (event) {
49
- await this.sourceMapsLoader.loadSourceMaps()
69
+ this.errorOccurred = true
70
+ await this.sourceMapsLoader.loadSourceMaps(event.error)
50
71
 
51
72
  if (event.error && event.error.stack) {
52
73
  const backtrace = this.sourceMapsLoader.parseStackTrace(event.error.stack)
@@ -66,7 +87,7 @@ module.exports = class ErrorLogger {
66
87
  }
67
88
 
68
89
  async onUnhandledRejection (event) {
69
- await this.sourceMapsLoader.loadSourceMaps()
90
+ await this.sourceMapsLoader.loadSourceMaps(event.reason)
70
91
 
71
92
  if (event.reason.stack) {
72
93
  const backtrace = this.sourceMapsLoader.parseStackTrace(event.reason.stack)
@@ -74,7 +95,7 @@ module.exports = class ErrorLogger {
74
95
  this.errors.push({
75
96
  errorClass: "UnhandledRejection",
76
97
  message: event.reason.message || "Unhandled promise rejection",
77
- backtrace: backtrace
98
+ backtrace
78
99
  })
79
100
  } else {
80
101
  this.errors.push({
package/src/link.jsx CHANGED
@@ -14,7 +14,7 @@ export default class Link extends React.PureComponent {
14
14
 
15
15
  if (onClick) onClick(e, ...restArgs)
16
16
 
17
- if (!e.defaultPrevented) {
17
+ if (!e.defaultPrevented && !e.ctrlKey && !e.metaKey) {
18
18
  e.preventDefault()
19
19
 
20
20
  const history = global.apiMakerConfigGlobal?.history
@@ -1,5 +1,6 @@
1
1
  const stackTraceParser = require("stacktrace-parser")
2
2
  const {SourceMapConsumer} = require("source-map")
3
+ const uniqunize = require("uniqunize")
3
4
 
4
5
  // Sometimes this needs to be called and sometimes not
5
6
  if (SourceMapConsumer.initialize) {
@@ -10,6 +11,8 @@ if (SourceMapConsumer.initialize) {
10
11
 
11
12
  module.exports = class SourceMapsLoader {
12
13
  constructor () {
14
+ this.debug = false
15
+ this.isLoadingSourceMaps = false
13
16
  this.sourceMaps = []
14
17
  this.srcLoaded = {}
15
18
  }
@@ -22,22 +25,61 @@ module.exports = class SourceMapsLoader {
22
25
  this.sourceMapForSourceCallback = callback
23
26
  }
24
27
 
25
- async loadSourceMaps () {
28
+ getSources(error) {
29
+ let sources = this.getSourcesFromScripts()
30
+
31
+ if (error) sources = sources.concat(this.getSourcesFromError(error))
32
+
33
+ return uniqunize(sources)
34
+ }
35
+
36
+ async loadSourceMaps (error) {
37
+ this.isLoadingSourceMaps = true
38
+
39
+ try {
40
+ const promises = []
41
+ const sources = this.getSources(error)
42
+
43
+ for(const src of sources) {
44
+ if (src && !this.srcLoaded[src]) {
45
+ this.srcLoaded[src] = true
46
+
47
+ const promise = this.loadSourceMapForSource(src)
48
+ promises.push(promise)
49
+ }
50
+ }
51
+
52
+ await Promise.all(promises)
53
+ } finally {
54
+ this.isLoadingSourceMaps = false
55
+ }
56
+ }
57
+
58
+ getSourcesFromError(error) {
59
+ const stack = stackTraceParser.parse(error.stack)
60
+ const sources = []
61
+
62
+ for (const trace of stack) {
63
+ sources.push(trace.file)
64
+ }
65
+
66
+ return sources
67
+ }
68
+
69
+ getSourcesFromScripts() {
26
70
  const scripts = document.querySelectorAll("script")
27
- const promises = []
71
+ const sources = []
28
72
 
29
73
  for (const script of scripts) {
30
74
  const src = this.loadSourceMapsForScriptTagsCallback(script)
31
75
 
32
- if (src && !this.srcLoaded[src]) {
76
+ if (src) {
33
77
  this.srcLoaded[src] = true
34
-
35
- const promise = this.loadSourceMapForSource(src)
36
- promises.push(promise)
78
+ sources.push(src)
37
79
  }
38
80
  }
39
81
 
40
- await Promise.all(promises)
82
+ return sources
41
83
  }
42
84
 
43
85
  async loadSourceMapForSource (src) {
@@ -90,6 +132,7 @@ module.exports = class SourceMapsLoader {
90
132
 
91
133
  for (const trace of stack) {
92
134
  const sourceMapData = this.sourceMaps.find((sourceMapData) => sourceMapData.originalUrl == trace.file)
135
+
93
136
  let filePath, fileString, original
94
137
 
95
138
  if (sourceMapData) {
@@ -100,7 +143,7 @@ module.exports = class SourceMapsLoader {
100
143
  }
101
144
 
102
145
  if (original && original.source) {
103
- filePath = original.source.replace(/^webpack:\/\/\//, "")
146
+ filePath = original.source.replace(/^webpack:\/\/(app|)\//, "")
104
147
  fileString = `${filePath}:${original.line}`
105
148
 
106
149
  if (original.column) {