@jsenv/plugin-supervisor 1.3.4 → 1.3.6

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.
@@ -9,6 +9,7 @@ window.__supervisor__ = (() => {
9
9
  reloadSupervisedScript: notImplemented,
10
10
  getDocumentExecutionResult: notImplemented
11
11
  };
12
+ const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
12
13
  const executionResults = {};
13
14
  let documentExecutionStartTime;
14
15
  try {
@@ -205,7 +206,7 @@ window.__supervisor__ = (() => {
205
206
  error
206
207
  };
207
208
  };
208
- const isWebkitOrSafari = typeof window.webkitConvertPointFromNodeToPage === "function";
209
+
209
210
  // https://twitter.com/damienmaillard/status/1554752482273787906
210
211
  const prepareJsModuleExecutionWithDynamicImport = src => {
211
212
  const urlObject = new URL(src, window.location);
@@ -456,15 +457,25 @@ window.__supervisor__ = (() => {
456
457
  } = {}) => {
457
458
  const exception = {
458
459
  reason,
460
+ isException: true,
459
461
  isError: false,
460
462
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
461
463
  reportedBy,
462
464
  code: null,
465
+ name: null,
463
466
  message: null,
464
- stack: null,
465
- stackFormatIsV8: null,
467
+ stack: "",
468
+ // the stack v8 format
466
469
  stackSourcemapped: null,
467
- originalStack: null,
470
+ stackOriginal: "",
471
+ // the stack from runtime, not normalized to v8
472
+ stackTrace: "",
473
+ // the stack trace (without error name and message)
474
+ withServerUrls: {
475
+ message: "",
476
+ stackTrace: "",
477
+ stack: ""
478
+ },
468
479
  meta: null,
469
480
  site: {
470
481
  isInline: null,
@@ -489,19 +500,20 @@ window.__supervisor__ = (() => {
489
500
  }
490
501
  if (reason instanceof Error) {
491
502
  const error = reason;
492
- let message = error.message;
493
503
  exception.isError = true;
494
- if (Error.captureStackTrace) {
504
+ exception.name = error.name || "Error";
505
+ exception.message = error.message || "";
506
+ if (Error.captureStackTrace &&
507
+ // captureStackTrace exists on webkit but error.stack is not v8
508
+ !isWebkitOrSafari) {
495
509
  // stackTrace formatted by V8
496
- exception.message = message;
497
- exception.stack = getErrorStackWithoutErrorMessage(error);
498
- exception.stackFormatIsV8 = true;
499
510
  exception.stackSourcemapped = true;
500
- } else {
501
- exception.message = message;
502
- exception.stack = error.stack ? " ".concat(error.stack) : null;
503
- exception.stackFormatIsV8 = false;
511
+ exception.stack = error.stack;
512
+ exception.stackTrace = getErrorStackTrace(error);
513
+ } else if (error.stack) {
504
514
  exception.stackSourcemapped = false;
515
+ exception.stackTrace = error.stack;
516
+ exception.stack = stringifyStack(exception);
505
517
  }
506
518
  if (error.reportedBy) {
507
519
  exception.reportedBy = error.reportedBy;
@@ -513,21 +525,21 @@ window.__supervisor__ = (() => {
513
525
  }
514
526
  {
515
527
  // chrome
516
- if (message.includes("does not provide an export named")) {
528
+ if (error.message.includes("does not provide an export named")) {
517
529
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
518
530
  return;
519
531
  }
520
532
  // firefox
521
- if (message.startsWith("import not found:") || message.startsWith("ambiguous indirect export:")) {
533
+ if (error.message.startsWith("import not found:") || error.message.startsWith("ambiguous indirect export:")) {
522
534
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
523
535
  return;
524
536
  }
525
537
  // safari
526
- if (message.startsWith("import binding name")) {
538
+ if (error.message.startsWith("import binding name")) {
527
539
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
528
540
  return;
529
541
  }
530
- if (message.includes("Importing a module script failed")) {
542
+ if (error.message.includes("Importing a module script failed")) {
531
543
  exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
532
544
  return;
533
545
  }
@@ -559,18 +571,6 @@ window.__supervisor__ = (() => {
559
571
  };
560
572
  writeBasicProperties();
561
573
 
562
- // first create a version of the stack with file://
563
- // (and use it to locate exception url+line+column)
564
- if (exception.stack) {
565
- exception.originalStack = exception.stack;
566
- exception.stack = replaceUrls(exception.originalStack, serverUrlSite => {
567
- const fileUrlSite = resolveUrlSite(serverUrlSite);
568
- if (exception.site.url === null) {
569
- Object.assign(exception.site, fileUrlSite);
570
- }
571
- return stringifyUrlSite(fileUrlSite);
572
- });
573
- }
574
574
  // then if it fails, use url+line+column passed
575
575
  if (exception.site.url === null && url) {
576
576
  if (typeof line === "string") {
@@ -590,20 +590,49 @@ window.__supervisor__ = (() => {
590
590
  }
591
591
  Object.assign(exception.site, fileUrlSite);
592
592
  }
593
- exception.text = stringifyMessageAndStack(exception);
593
+ exception.withServerUrls.message = exception.message;
594
+ exception.withServerUrls.stackTrace = exception.stackTrace;
595
+ exception.withServerUrls.stack = exception.stack;
596
+ exception.message = exception.message ? replaceUrls(exception.message, serverUrlSite => {
597
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
598
+ return stringifyUrlSite(fileUrlSite);
599
+ }) : "";
600
+ exception.stackTrace = exception.stackTrace ? replaceUrls(exception.stackTrace, serverUrlSite => {
601
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
602
+ if (exception.site.url === null) {
603
+ Object.assign(exception.site, fileUrlSite);
604
+ }
605
+ return stringifyUrlSite(fileUrlSite);
606
+ }) : "";
607
+ exception.stack = stringifyStack({
608
+ name: exception.name,
609
+ message: exception.message,
610
+ stackTrace: exception.stackTrace
611
+ });
612
+ exception.text = stringifyStack({
613
+ name: exception.name,
614
+ message: exception.message,
615
+ stackTrace: exception.stackTrace
616
+ });
594
617
  return exception;
595
618
  };
596
- const stringifyMessageAndStack = ({
619
+ const stringifyStack = ({
620
+ name,
597
621
  message,
598
- stack
622
+ stackTrace
599
623
  }) => {
600
- if (message && stack) {
601
- return "".concat(message, "\n").concat(stack);
624
+ let stack;
625
+ if (name && message) {
626
+ stack = "".concat(name, ": ").concat(message);
627
+ } else if (message) {
628
+ stack = message;
629
+ } else {
630
+ stack = "";
602
631
  }
603
- if (stack) {
604
- return stack;
632
+ if (stackTrace) {
633
+ stack += "\n".concat(stackTrace);
605
634
  }
606
- return message;
635
+ return stack;
607
636
  };
608
637
  const stringifyUrlSite = ({
609
638
  url,
@@ -653,7 +682,7 @@ window.__supervisor__ = (() => {
653
682
  column
654
683
  };
655
684
  };
656
- const getErrorStackWithoutErrorMessage = error => {
685
+ const getErrorStackTrace = error => {
657
686
  let stack = error.stack;
658
687
  if (!stack) return "";
659
688
  const messageInStack = "".concat(error.name, ": ").concat(error.message);
@@ -667,7 +696,12 @@ window.__supervisor__ = (() => {
667
696
  return stack;
668
697
  };
669
698
  const resolveFileUrl = url => {
670
- let urlObject = new URL(url, window.origin);
699
+ let urlObject;
700
+ try {
701
+ urlObject = new URL(url, window.origin);
702
+ } catch (e) {
703
+ return url;
704
+ }
671
705
  if (urlObject.origin === window.origin) {
672
706
  urlObject = new URL("".concat(urlObject.pathname.slice(1)).concat(urlObject.search), rootDirectoryUrl);
673
707
  }
@@ -771,9 +805,10 @@ window.__supervisor__ = (() => {
771
805
  });
772
806
  return textWithHtmlLinks;
773
807
  };
774
- errorParts.text = stringifyMessageAndStack({
808
+ errorParts.text = stringifyStack({
809
+ name: exceptionInfo.name,
775
810
  message: exceptionInfo.message ? generateClickableText(exceptionInfo.message) : "",
776
- stack: exceptionInfo.stack ? generateClickableText(exceptionInfo.stack) : ""
811
+ stackTrace: exceptionInfo.stackTrace ? generateClickableText(exceptionInfo.stackTrace) : ""
777
812
  });
778
813
  if (exceptionInfo.site.url) {
779
814
  errorParts.errorDetailsPromise = (async () => {
@@ -790,12 +825,14 @@ window.__supervisor__ = (() => {
790
825
  if (!causeInfo) {
791
826
  return null;
792
827
  }
793
- const causeText = causeInfo.code === "NOT_FOUND" ? stringifyMessageAndStack({
828
+ const causeText = causeInfo.code === "NOT_FOUND" ? stringifyStack({
829
+ name: causeInfo.name,
794
830
  message: generateClickableText(causeInfo.reason),
795
- stack: generateClickableText(causeInfo.codeFrame)
796
- }) : stringifyMessageAndStack({
831
+ stackTrace: generateClickableText(causeInfo.codeFrame)
832
+ }) : stringifyStack({
833
+ name: causeInfo.name,
797
834
  message: generateClickableText(causeInfo.stack),
798
- stack: generateClickableText(causeInfo.codeFrame)
835
+ stackTrace: generateClickableText(causeInfo.codeFrame)
799
836
  });
800
837
  return {
801
838
  cause: causeText
@@ -1018,6 +1018,7 @@ const jsenvPluginSupervisor = ({
1018
1018
  const causeInfo = getErrorCauseInfo();
1019
1019
  const body = JSON.stringify(causeInfo ? {
1020
1020
  code: causeInfo.code,
1021
+ name: causeInfo.name,
1021
1022
  message: causeInfo.message,
1022
1023
  reason: causeInfo.reason,
1023
1024
  stack: errorBaseUrl ? "stack mocked for snapshot" : causeInfo.stack,
@@ -1042,9 +1043,11 @@ const jsenvPluginSupervisor = ({
1042
1043
  body: "Missing file in url"
1043
1044
  };
1044
1045
  }
1046
+ const fileUrl = new URL(file, serveInfo.rootDirectoryUrl);
1047
+ const filePath = fileURLToPath(fileUrl);
1045
1048
  const require = createRequire(import.meta.url);
1046
1049
  const launch = require("launch-editor");
1047
- launch(fileURLToPath(file), () => {
1050
+ launch(filePath, () => {
1048
1051
  // ignore error for now
1049
1052
  });
1050
1053
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,10 +26,10 @@
26
26
  "/dist/"
27
27
  ],
28
28
  "dependencies": {
29
- "@jsenv/ast": "5.1.4",
29
+ "@jsenv/ast": "5.2.0",
30
30
  "@jsenv/urls": "2.2.1",
31
31
  "@jsenv/sourcemap": "1.2.3",
32
- "launch-editor": "2.6.0"
32
+ "launch-editor": "2.6.1"
33
33
  },
34
34
  "scripts": {
35
35
  "eslint": "npx eslint . --ext=.js,.mjs,.cjs,.html",
@@ -9,6 +9,8 @@ window.__supervisor__ = (() => {
9
9
  reloadSupervisedScript: notImplemented,
10
10
  getDocumentExecutionResult: notImplemented,
11
11
  };
12
+ const isWebkitOrSafari =
13
+ typeof window.webkitConvertPointFromNodeToPage === "function";
12
14
 
13
15
  const executionResults = {};
14
16
  let documentExecutionStartTime;
@@ -192,8 +194,6 @@ window.__supervisor__ = (() => {
192
194
  executions[src] = { isInline: true, start, end, error };
193
195
  };
194
196
 
195
- const isWebkitOrSafari =
196
- typeof window.webkitConvertPointFromNodeToPage === "function";
197
197
  // https://twitter.com/damienmaillard/status/1554752482273787906
198
198
  const prepareJsModuleExecutionWithDynamicImport = (src) => {
199
199
  const urlObject = new URL(src, window.location);
@@ -425,14 +425,21 @@ window.__supervisor__ = (() => {
425
425
  ) => {
426
426
  const exception = {
427
427
  reason,
428
+ isException: true,
428
429
  isError: false, // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw
429
430
  reportedBy,
430
431
  code: null,
432
+ name: null,
431
433
  message: null,
432
- stack: null,
433
- stackFormatIsV8: null,
434
+ stack: "", // the stack v8 format
434
435
  stackSourcemapped: null,
435
- originalStack: null,
436
+ stackOriginal: "", // the stack from runtime, not normalized to v8
437
+ stackTrace: "", // the stack trace (without error name and message)
438
+ withServerUrls: {
439
+ message: "",
440
+ stackTrace: "",
441
+ stack: "",
442
+ },
436
443
  meta: null,
437
444
  site: {
438
445
  isInline: null,
@@ -458,20 +465,24 @@ window.__supervisor__ = (() => {
458
465
  }
459
466
  if (reason instanceof Error) {
460
467
  const error = reason;
461
- let message = error.message;
462
468
  exception.isError = true;
463
- if (Error.captureStackTrace) {
469
+ exception.name = error.name || "Error";
470
+ exception.message = error.message || "";
471
+ if (
472
+ Error.captureStackTrace &&
473
+ // captureStackTrace exists on webkit but error.stack is not v8
474
+ !isWebkitOrSafari
475
+ ) {
464
476
  // stackTrace formatted by V8
465
- exception.message = message;
466
- exception.stack = getErrorStackWithoutErrorMessage(error);
467
- exception.stackFormatIsV8 = true;
468
477
  exception.stackSourcemapped = true;
469
- } else {
470
- exception.message = message;
471
- exception.stack = error.stack ? ` ${error.stack}` : null;
472
- exception.stackFormatIsV8 = false;
478
+ exception.stack = error.stack;
479
+ exception.stackTrace = getErrorStackTrace(error);
480
+ } else if (error.stack) {
473
481
  exception.stackSourcemapped = false;
482
+ exception.stackTrace = error.stack;
483
+ exception.stack = stringifyStack(exception);
474
484
  }
485
+
475
486
  if (error.reportedBy) {
476
487
  exception.reportedBy = error.reportedBy;
477
488
  }
@@ -480,24 +491,24 @@ window.__supervisor__ = (() => {
480
491
  }
481
492
  export_missing: {
482
493
  // chrome
483
- if (message.includes("does not provide an export named")) {
494
+ if (error.message.includes("does not provide an export named")) {
484
495
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
485
496
  return;
486
497
  }
487
498
  // firefox
488
499
  if (
489
- message.startsWith("import not found:") ||
490
- message.startsWith("ambiguous indirect export:")
500
+ error.message.startsWith("import not found:") ||
501
+ error.message.startsWith("ambiguous indirect export:")
491
502
  ) {
492
503
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
493
504
  return;
494
505
  }
495
506
  // safari
496
- if (message.startsWith("import binding name")) {
507
+ if (error.message.startsWith("import binding name")) {
497
508
  exception.code = DYNAMIC_IMPORT_EXPORT_MISSING;
498
509
  return;
499
510
  }
500
- if (message.includes("Importing a module script failed")) {
511
+ if (error.message.includes("Importing a module script failed")) {
501
512
  exception.code = DYNAMIC_IMPORT_FETCH_ERROR;
502
513
  return;
503
514
  }
@@ -527,21 +538,6 @@ window.__supervisor__ = (() => {
527
538
  };
528
539
  writeBasicProperties();
529
540
 
530
- // first create a version of the stack with file://
531
- // (and use it to locate exception url+line+column)
532
- if (exception.stack) {
533
- exception.originalStack = exception.stack;
534
- exception.stack = replaceUrls(
535
- exception.originalStack,
536
- (serverUrlSite) => {
537
- const fileUrlSite = resolveUrlSite(serverUrlSite);
538
- if (exception.site.url === null) {
539
- Object.assign(exception.site, fileUrlSite);
540
- }
541
- return stringifyUrlSite(fileUrlSite);
542
- },
543
- );
544
- }
545
541
  // then if it fails, use url+line+column passed
546
542
  if (exception.site.url === null && url) {
547
543
  if (typeof line === "string") {
@@ -560,18 +556,51 @@ window.__supervisor__ = (() => {
560
556
  }
561
557
  Object.assign(exception.site, fileUrlSite);
562
558
  }
563
- exception.text = stringifyMessageAndStack(exception);
559
+
560
+ exception.withServerUrls.message = exception.message;
561
+ exception.withServerUrls.stackTrace = exception.stackTrace;
562
+ exception.withServerUrls.stack = exception.stack;
563
+ exception.message = exception.message
564
+ ? replaceUrls(exception.message, (serverUrlSite) => {
565
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
566
+ return stringifyUrlSite(fileUrlSite);
567
+ })
568
+ : "";
569
+ exception.stackTrace = exception.stackTrace
570
+ ? replaceUrls(exception.stackTrace, (serverUrlSite) => {
571
+ const fileUrlSite = resolveUrlSite(serverUrlSite);
572
+ if (exception.site.url === null) {
573
+ Object.assign(exception.site, fileUrlSite);
574
+ }
575
+ return stringifyUrlSite(fileUrlSite);
576
+ })
577
+ : "";
578
+ exception.stack = stringifyStack({
579
+ name: exception.name,
580
+ message: exception.message,
581
+ stackTrace: exception.stackTrace,
582
+ });
583
+ exception.text = stringifyStack({
584
+ name: exception.name,
585
+ message: exception.message,
586
+ stackTrace: exception.stackTrace,
587
+ });
564
588
  return exception;
565
589
  };
566
590
 
567
- const stringifyMessageAndStack = ({ message, stack }) => {
568
- if (message && stack) {
569
- return `${message}\n${stack}`;
591
+ const stringifyStack = ({ name, message, stackTrace }) => {
592
+ let stack;
593
+ if (name && message) {
594
+ stack = `${name}: ${message}`;
595
+ } else if (message) {
596
+ stack = message;
597
+ } else {
598
+ stack = "";
570
599
  }
571
- if (stack) {
572
- return stack;
600
+ if (stackTrace) {
601
+ stack += `\n${stackTrace}`;
573
602
  }
574
- return message;
603
+ return stack;
575
604
  };
576
605
 
577
606
  const stringifyUrlSite = ({ url, line, column }) => {
@@ -618,7 +647,7 @@ window.__supervisor__ = (() => {
618
647
  };
619
648
  };
620
649
 
621
- const getErrorStackWithoutErrorMessage = (error) => {
650
+ const getErrorStackTrace = (error) => {
622
651
  let stack = error.stack;
623
652
  if (!stack) return "";
624
653
  const messageInStack = `${error.name}: ${error.message}`;
@@ -633,7 +662,12 @@ window.__supervisor__ = (() => {
633
662
  };
634
663
 
635
664
  const resolveFileUrl = (url) => {
636
- let urlObject = new URL(url, window.origin);
665
+ let urlObject;
666
+ try {
667
+ urlObject = new URL(url, window.origin);
668
+ } catch (e) {
669
+ return url;
670
+ }
637
671
  if (urlObject.origin === window.origin) {
638
672
  urlObject = new URL(
639
673
  `${urlObject.pathname.slice(1)}${urlObject.search}`,
@@ -745,12 +779,13 @@ window.__supervisor__ = (() => {
745
779
  return textWithHtmlLinks;
746
780
  };
747
781
 
748
- errorParts.text = stringifyMessageAndStack({
782
+ errorParts.text = stringifyStack({
783
+ name: exceptionInfo.name,
749
784
  message: exceptionInfo.message
750
785
  ? generateClickableText(exceptionInfo.message)
751
786
  : "",
752
- stack: exceptionInfo.stack
753
- ? generateClickableText(exceptionInfo.stack)
787
+ stackTrace: exceptionInfo.stackTrace
788
+ ? generateClickableText(exceptionInfo.stackTrace)
754
789
  : "",
755
790
  });
756
791
  if (exceptionInfo.site.url) {
@@ -779,13 +814,15 @@ window.__supervisor__ = (() => {
779
814
  }
780
815
  const causeText =
781
816
  causeInfo.code === "NOT_FOUND"
782
- ? stringifyMessageAndStack({
817
+ ? stringifyStack({
818
+ name: causeInfo.name,
783
819
  message: generateClickableText(causeInfo.reason),
784
- stack: generateClickableText(causeInfo.codeFrame),
820
+ stackTrace: generateClickableText(causeInfo.codeFrame),
785
821
  })
786
- : stringifyMessageAndStack({
822
+ : stringifyStack({
823
+ name: causeInfo.name,
787
824
  message: generateClickableText(causeInfo.stack),
788
- stack: generateClickableText(causeInfo.codeFrame),
825
+ stackTrace: generateClickableText(causeInfo.codeFrame),
789
826
  });
790
827
  return {
791
828
  cause: causeText,
@@ -117,6 +117,7 @@ export const jsenvPluginSupervisor = ({
117
117
  causeInfo
118
118
  ? {
119
119
  code: causeInfo.code,
120
+ name: causeInfo.name,
120
121
  message: causeInfo.message,
121
122
  reason: causeInfo.reason,
122
123
  stack: errorBaseUrl
@@ -143,15 +144,18 @@ export const jsenvPluginSupervisor = ({
143
144
  "/__open_in_editor__/".length,
144
145
  );
145
146
  file = decodeURIComponent(file);
147
+
146
148
  if (!file) {
147
149
  return {
148
150
  status: 400,
149
151
  body: "Missing file in url",
150
152
  };
151
153
  }
154
+ const fileUrl = new URL(file, serveInfo.rootDirectoryUrl);
155
+ const filePath = fileURLToPath(fileUrl);
152
156
  const require = createRequire(import.meta.url);
153
157
  const launch = require("launch-editor");
154
- launch(fileURLToPath(file), () => {
158
+ launch(filePath, () => {
155
159
  // ignore error for now
156
160
  });
157
161
  return {