@jsenv/plugin-supervisor 1.5.0 → 1.5.2

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.
@@ -504,11 +504,11 @@ window.__supervisor__ = (() => {
504
504
  },
505
505
  meta: null,
506
506
  site: {
507
+ ownerSite: null,
507
508
  isInline: null,
508
509
  url: null,
509
510
  line: null,
510
- column: null,
511
- originalUrl: null
511
+ column: null
512
512
  }
513
513
  };
514
514
  const writeBasicProperties = () => {
@@ -674,9 +674,38 @@ window.__supervisor__ = (() => {
674
674
  line,
675
675
  column
676
676
  });
677
- if (fileUrlSite.isInline && exception.name === "SyntaxError" && exception.code !== DYNAMIC_IMPORT_EXPORT_MISSING) {
678
- // syntax error on inline script need line-1 for some reason
679
- fileUrlSite.line = fileUrlSite.line - 1;
677
+ const decreaseLine = () => {
678
+ const {
679
+ ownerSite
680
+ } = fileUrlSite;
681
+ if (ownerSite) {
682
+ if (typeof ownerSite.line === "number") {
683
+ ownerSite.line = fileUrlSite.ownerSite.line - 1;
684
+ }
685
+ }
686
+ if (typeof fileUrlSite.line === "number") {
687
+ fileUrlSite.line = fileUrlSite.line - 1;
688
+ }
689
+ };
690
+ if (fileUrlSite.isInline) {
691
+ // chrome
692
+ if (Error.captureStackTrace && !isWebkitOrSafari) {
693
+ if (exception.name === "SyntaxError") {
694
+ // syntax error on inline script need line-1 for some reason
695
+ decreaseLine();
696
+ }
697
+ }
698
+ // firefox and webkit
699
+ else if (exception.name === "SyntaxError") {
700
+ if (exception.code === DYNAMIC_IMPORT_EXPORT_MISSING || exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR) {
701
+ decreaseLine();
702
+ } else {
703
+ decreaseLine();
704
+ decreaseLine();
705
+ }
706
+ } else {
707
+ decreaseLine();
708
+ }
680
709
  }
681
710
  Object.assign(exception.site, fileUrlSite);
682
711
  }
@@ -753,17 +782,22 @@ window.__supervisor__ = (() => {
753
782
  const tagColumnEnd = parseInt(inlineUrlMatch[4]);
754
783
  const extension = inlineUrlMatch[5];
755
784
  url = htmlUrl;
756
- line = tagLineStart + (typeof line === "number" ? line : 0);
757
- line = line - 1; // sauf pour les erreur de syntaxe
758
- column = tagColumnStart + (typeof column === "number" ? column : 0);
759
785
  const fileUrl = resolveFileUrl(url);
786
+ const ownerSiteUrl = "".concat(fileUrl, "@L").concat(tagLineStart, "C").concat(tagColumnStart, "-L").concat(tagLineEnd, "C").concat(tagColumnEnd).concat(extension);
787
+ const ownerSite = {
788
+ url: ownerSiteUrl,
789
+ ownerLine: tagLineStart,
790
+ ownerColumn: tagColumnStart,
791
+ inlineLine: typeof line === "number" ? line - 1 : undefined,
792
+ inlineColumn: column
793
+ };
760
794
  return {
795
+ ownerSite,
761
796
  isInline: true,
762
797
  serverUrl: url,
763
- originalUrl: "".concat(fileUrl, "@L").concat(tagLineStart, "C").concat(tagColumnStart, "-L").concat(tagLineEnd, "C").concat(tagColumnEnd).concat(extension),
764
798
  url: fileUrl,
765
- line,
766
- column
799
+ line: typeof ownerSite.inlineLine === "number" ? ownerSite.ownerLine + ownerSite.inlineLine : ownerSite.ownerLine,
800
+ column: typeof ownerSite.inlineColumn === "number" ? ownerSite.inlineColumn : ownerSite.ownerColumn
767
801
  };
768
802
  }
769
803
  return {
@@ -843,7 +877,7 @@ window.__supervisor__ = (() => {
843
877
  const lineString = lineMatch[0];
844
878
  replacement = replace({
845
879
  url: match.slice(0, -lineString.length),
846
- line: lineString ? parseInt(lineString) : null
880
+ line: parseInt(lineMatch[1])
847
881
  });
848
882
  } else {
849
883
  replacement = replace({
@@ -952,7 +986,9 @@ window.__supervisor__ = (() => {
952
986
  (async () => {
953
987
  try {
954
988
  if (exception.code === DYNAMIC_IMPORT_FETCH_ERROR || exception.reportedBy === "script_error_event") {
955
- const response = await window.fetch("/__get_error_cause__/".concat(encodeURIComponent(exception.site.isInline ? exception.site.originalUrl : exception.site.url)));
989
+ const errorCauseFile = exception.site.ownerSite ? exception.site.ownerSite.url : exception.site.url;
990
+ const errorCauseAPIUrl = "/__get_error_cause__/".concat(encodeURIComponent(errorCauseFile));
991
+ const response = await window.fetch(errorCauseAPIUrl);
956
992
  if (response.status !== 200) {
957
993
  return;
958
994
  }
@@ -965,7 +1001,13 @@ window.__supervisor__ = (() => {
965
1001
  return;
966
1002
  }
967
1003
  if (exception.site.line !== undefined) {
968
- const urlToFetch = new URL("/__get_cause_trace__/".concat(encodeURIComponent(stringifyUrlSite(exception.site))), window.origin);
1004
+ const errorTraceFile = exception.site.ownerSite ? stringifyUrlSite({
1005
+ url: exception.site.ownerSite.url,
1006
+ line: exception.site.ownerSite.inlineLine,
1007
+ column: exception.site.ownerSite.inlineColumn
1008
+ }) : stringifyUrlSite(exception.site);
1009
+ const errorTraceAPIUrl = "/__get_cause_trace__/".concat(encodeURIComponent(errorTraceFile));
1010
+ const urlToFetch = new URL(errorTraceAPIUrl, window.origin);
969
1011
  if (!exception.stackSourcemapped) {
970
1012
  urlToFetch.searchParams.set("remap", "");
971
1013
  }
@@ -1187,6 +1187,41 @@ const jsenvPluginSupervisor = ({
1187
1187
  openInEditor = true,
1188
1188
  errorBaseUrl
1189
1189
  }) => {
1190
+ const resolveUrlSite = urlWithLineAndColumn => {
1191
+ const inlineUrlMatch = urlWithLineAndColumn.match(
1192
+ // eslint-disable-next-line regexp/no-unused-capturing-group
1193
+ /@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/);
1194
+ if (inlineUrlMatch) {
1195
+ const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
1196
+ const tagLineStart = parseInt(inlineUrlMatch[1]);
1197
+ const tagColumnStart = parseInt(inlineUrlMatch[2]);
1198
+ // const tagLineEnd = parseInt(inlineUrlMatch[3]);
1199
+ // const tagColumnEnd = parseInt(inlineUrlMatch[4]);
1200
+ const inlineLine = inlineUrlMatch[6] === undefined ? undefined : parseInt(inlineUrlMatch[6]);
1201
+ const inlineColumn = inlineUrlMatch[7] === undefined ? undefined : parseInt(inlineUrlMatch[7]);
1202
+ return {
1203
+ file: htmlUrl,
1204
+ ownerLine: tagLineStart,
1205
+ ownerColumn: tagColumnStart,
1206
+ inlineLine,
1207
+ inlineColumn,
1208
+ line: inlineLine === undefined ? tagLineStart : tagLineStart + inlineLine,
1209
+ column: inlineColumn === undefined ? tagColumnStart : inlineColumn
1210
+ };
1211
+ }
1212
+ const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
1213
+ if (!match) {
1214
+ return null;
1215
+ }
1216
+ const file = urlWithLineAndColumn.slice(0, match.index);
1217
+ let line = parseInt(match[1]);
1218
+ let column = parseInt(match[2]);
1219
+ return {
1220
+ file,
1221
+ line,
1222
+ column
1223
+ };
1224
+ };
1190
1225
  return {
1191
1226
  name: "jsenv:supervisor",
1192
1227
  appliesDuring: "dev",
@@ -1196,18 +1231,19 @@ const jsenvPluginSupervisor = ({
1196
1231
  pathname,
1197
1232
  searchParams
1198
1233
  } = new URL(serveInfo.request.url);
1199
- let urlWithLineAndColumn = pathname.slice("/__get_cause_trace__/".length);
1200
- urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
1201
- const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
1202
- if (!match) {
1234
+ const urlWithLineAndColumn = decodeURIComponent(pathname.slice("/__get_cause_trace__/".length));
1235
+ const result = resolveUrlSite(urlWithLineAndColumn);
1236
+ if (!result) {
1203
1237
  return {
1204
1238
  status: 400,
1205
1239
  body: "Missing line and column in url"
1206
1240
  };
1207
1241
  }
1208
- const file = urlWithLineAndColumn.slice(0, match.index);
1209
- let line = parseInt(match[1]);
1210
- let column = parseInt(match[2]);
1242
+ let {
1243
+ file,
1244
+ line,
1245
+ column
1246
+ } = result;
1211
1247
  const urlInfo = serveInfo.kitchen.graph.getUrlInfo(file);
1212
1248
  if (!urlInfo) {
1213
1249
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "/dist/"
27
27
  ],
28
28
  "dependencies": {
29
- "@jsenv/ast": "6.2.1",
30
- "@jsenv/urls": "2.2.10",
31
- "@jsenv/sourcemap": "1.2.13",
29
+ "@jsenv/ast": "6.2.2",
30
+ "@jsenv/urls": "2.2.11",
31
+ "@jsenv/sourcemap": "1.2.14",
32
32
  "launch-editor": "2.8.0"
33
33
  },
34
34
  "scripts": {
@@ -458,11 +458,11 @@ window.__supervisor__ = (() => {
458
458
  },
459
459
  meta: null,
460
460
  site: {
461
+ ownerSite: null,
461
462
  isInline: null,
462
463
  url: null,
463
464
  line: null,
464
465
  column: null,
465
- originalUrl: null,
466
466
  },
467
467
  };
468
468
 
@@ -641,13 +641,39 @@ window.__supervisor__ = (() => {
641
641
  column = parseInt(column);
642
642
  }
643
643
  const fileUrlSite = resolveUrlSite({ url, line, column });
644
- if (
645
- fileUrlSite.isInline &&
646
- exception.name === "SyntaxError" &&
647
- exception.code !== DYNAMIC_IMPORT_EXPORT_MISSING
648
- ) {
649
- // syntax error on inline script need line-1 for some reason
650
- fileUrlSite.line = fileUrlSite.line - 1;
644
+ const decreaseLine = () => {
645
+ const { ownerSite } = fileUrlSite;
646
+ if (ownerSite) {
647
+ if (typeof ownerSite.line === "number") {
648
+ ownerSite.line = fileUrlSite.ownerSite.line - 1;
649
+ }
650
+ }
651
+ if (typeof fileUrlSite.line === "number") {
652
+ fileUrlSite.line = fileUrlSite.line - 1;
653
+ }
654
+ };
655
+ if (fileUrlSite.isInline) {
656
+ // chrome
657
+ if (Error.captureStackTrace && !isWebkitOrSafari) {
658
+ if (exception.name === "SyntaxError") {
659
+ // syntax error on inline script need line-1 for some reason
660
+ decreaseLine();
661
+ }
662
+ }
663
+ // firefox and webkit
664
+ else if (exception.name === "SyntaxError") {
665
+ if (
666
+ exception.code === DYNAMIC_IMPORT_EXPORT_MISSING ||
667
+ exception.code === DYNAMIC_IMPORT_SYNTAX_ERROR
668
+ ) {
669
+ decreaseLine();
670
+ } else {
671
+ decreaseLine();
672
+ decreaseLine();
673
+ }
674
+ } else {
675
+ decreaseLine();
676
+ }
651
677
  }
652
678
  Object.assign(exception.site, fileUrlSite);
653
679
  }
@@ -721,17 +747,28 @@ window.__supervisor__ = (() => {
721
747
  const tagColumnEnd = parseInt(inlineUrlMatch[4]);
722
748
  const extension = inlineUrlMatch[5];
723
749
  url = htmlUrl;
724
- line = tagLineStart + (typeof line === "number" ? line : 0);
725
- line = line - 1; // sauf pour les erreur de syntaxe
726
- column = tagColumnStart + (typeof column === "number" ? column : 0);
727
750
  const fileUrl = resolveFileUrl(url);
751
+ const ownerSiteUrl = `${fileUrl}@L${tagLineStart}C${tagColumnStart}-L${tagLineEnd}C${tagColumnEnd}${extension}`;
752
+ const ownerSite = {
753
+ url: ownerSiteUrl,
754
+ ownerLine: tagLineStart,
755
+ ownerColumn: tagColumnStart,
756
+ inlineLine: typeof line === "number" ? line - 1 : undefined,
757
+ inlineColumn: column,
758
+ };
728
759
  return {
760
+ ownerSite,
729
761
  isInline: true,
730
762
  serverUrl: url,
731
- originalUrl: `${fileUrl}@L${tagLineStart}C${tagColumnStart}-L${tagLineEnd}C${tagColumnEnd}${extension}`,
732
763
  url: fileUrl,
733
- line,
734
- column,
764
+ line:
765
+ typeof ownerSite.inlineLine === "number"
766
+ ? ownerSite.ownerLine + ownerSite.inlineLine
767
+ : ownerSite.ownerLine,
768
+ column:
769
+ typeof ownerSite.inlineColumn === "number"
770
+ ? ownerSite.inlineColumn
771
+ : ownerSite.ownerColumn,
735
772
  };
736
773
  }
737
774
  return {
@@ -819,7 +856,7 @@ window.__supervisor__ = (() => {
819
856
  const lineString = lineMatch[0];
820
857
  replacement = replace({
821
858
  url: match.slice(0, -lineString.length),
822
- line: lineString ? parseInt(lineString) : null,
859
+ line: parseInt(lineMatch[1]),
823
860
  });
824
861
  } else {
825
862
  replacement = replace({
@@ -962,13 +999,13 @@ window.__supervisor__ = (() => {
962
999
  exception.code === DYNAMIC_IMPORT_FETCH_ERROR ||
963
1000
  exception.reportedBy === "script_error_event"
964
1001
  ) {
965
- const response = await window.fetch(
966
- `/__get_error_cause__/${encodeURIComponent(
967
- exception.site.isInline
968
- ? exception.site.originalUrl
969
- : exception.site.url,
970
- )}`,
971
- );
1002
+ const errorCauseFile = exception.site.ownerSite
1003
+ ? exception.site.ownerSite.url
1004
+ : exception.site.url;
1005
+ const errorCauseAPIUrl = `/__get_error_cause__/${encodeURIComponent(
1006
+ errorCauseFile,
1007
+ )}`;
1008
+ const response = await window.fetch(errorCauseAPIUrl);
972
1009
  if (response.status !== 200) {
973
1010
  return;
974
1011
  }
@@ -981,12 +1018,17 @@ window.__supervisor__ = (() => {
981
1018
  return;
982
1019
  }
983
1020
  if (exception.site.line !== undefined) {
984
- const urlToFetch = new URL(
985
- `/__get_cause_trace__/${encodeURIComponent(
986
- stringifyUrlSite(exception.site),
987
- )}`,
988
- window.origin,
989
- );
1021
+ const errorTraceFile = exception.site.ownerSite
1022
+ ? stringifyUrlSite({
1023
+ url: exception.site.ownerSite.url,
1024
+ line: exception.site.ownerSite.inlineLine,
1025
+ column: exception.site.ownerSite.inlineColumn,
1026
+ })
1027
+ : stringifyUrlSite(exception.site);
1028
+ const errorTraceAPIUrl = `/__get_cause_trace__/${encodeURIComponent(
1029
+ errorTraceFile,
1030
+ )}`;
1031
+ const urlToFetch = new URL(errorTraceAPIUrl, window.origin);
990
1032
  if (!exception.stackSourcemapped) {
991
1033
  urlToFetch.searchParams.set("remap", "");
992
1034
  }
@@ -20,26 +20,67 @@ export const jsenvPluginSupervisor = ({
20
20
  openInEditor = true,
21
21
  errorBaseUrl,
22
22
  }) => {
23
+ const resolveUrlSite = (urlWithLineAndColumn) => {
24
+ const inlineUrlMatch = urlWithLineAndColumn.match(
25
+ // eslint-disable-next-line regexp/no-unused-capturing-group
26
+ /@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/,
27
+ );
28
+ if (inlineUrlMatch) {
29
+ const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
30
+ const tagLineStart = parseInt(inlineUrlMatch[1]);
31
+ const tagColumnStart = parseInt(inlineUrlMatch[2]);
32
+ // const tagLineEnd = parseInt(inlineUrlMatch[3]);
33
+ // const tagColumnEnd = parseInt(inlineUrlMatch[4]);
34
+ const inlineLine =
35
+ inlineUrlMatch[6] === undefined
36
+ ? undefined
37
+ : parseInt(inlineUrlMatch[6]);
38
+ const inlineColumn =
39
+ inlineUrlMatch[7] === undefined
40
+ ? undefined
41
+ : parseInt(inlineUrlMatch[7]);
42
+ return {
43
+ file: htmlUrl,
44
+ ownerLine: tagLineStart,
45
+ ownerColumn: tagColumnStart,
46
+ inlineLine,
47
+ inlineColumn,
48
+ line:
49
+ inlineLine === undefined ? tagLineStart : tagLineStart + inlineLine,
50
+ column: inlineColumn === undefined ? tagColumnStart : inlineColumn,
51
+ };
52
+ }
53
+ const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
54
+ if (!match) {
55
+ return null;
56
+ }
57
+ const file = urlWithLineAndColumn.slice(0, match.index);
58
+ let line = parseInt(match[1]);
59
+ let column = parseInt(match[2]);
60
+ return {
61
+ file,
62
+ line,
63
+ column,
64
+ };
65
+ };
66
+
23
67
  return {
24
68
  name: "jsenv:supervisor",
25
69
  appliesDuring: "dev",
26
70
  serve: async (serveInfo) => {
27
71
  if (serveInfo.request.pathname.startsWith("/__get_cause_trace__/")) {
28
72
  const { pathname, searchParams } = new URL(serveInfo.request.url);
29
- let urlWithLineAndColumn = pathname.slice(
30
- "/__get_cause_trace__/".length,
73
+ const urlWithLineAndColumn = decodeURIComponent(
74
+ pathname.slice("/__get_cause_trace__/".length),
31
75
  );
32
- urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
33
- const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
34
- if (!match) {
76
+ const result = resolveUrlSite(urlWithLineAndColumn);
77
+ if (!result) {
35
78
  return {
36
79
  status: 400,
37
80
  body: "Missing line and column in url",
38
81
  };
39
82
  }
40
- const file = urlWithLineAndColumn.slice(0, match.index);
41
- let line = parseInt(match[1]);
42
- let column = parseInt(match[2]);
83
+ let { file, line, column } = result;
43
84
  const urlInfo = serveInfo.kitchen.graph.getUrlInfo(file);
44
85
  if (!urlInfo) {
45
86
  return {
@@ -78,7 +119,6 @@ export const jsenvPluginSupervisor = ({
78
119
  }),
79
120
  };
80
121
  const causeTraceJson = JSON.stringify(causeTrace, null, " ");
81
-
82
122
  return {
83
123
  status: 200,
84
124
  headers: {