@jsenv/plugin-supervisor 1.4.16 → 1.5.1
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/dist/js/supervisor.js +56 -14
- package/dist/jsenv_plugin_supervisor.js +57 -34
- package/package.json +2 -2
- package/src/client/supervisor.js +70 -28
- package/src/html_supervisor.js +13 -41
- package/src/jsenv_plugin_supervisor.js +49 -9
package/dist/js/supervisor.js
CHANGED
|
@@ -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
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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:
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -4,7 +4,7 @@ import process$1 from "node:process";
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import tty from "node:tty";
|
|
6
6
|
import "string-width";
|
|
7
|
-
import { applyBabelPlugins, parseHtml, visitHtmlNodes, analyzeScriptNode, getHtmlNodeAttribute, getHtmlNodeText,
|
|
7
|
+
import { applyBabelPlugins, parseHtml, visitHtmlNodes, analyzeScriptNode, getHtmlNodeAttribute, getHtmlNodeText, injectJsenvScript, stringifyHtmlAst, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeText, setHtmlNodeAttributes } from "@jsenv/ast";
|
|
8
8
|
|
|
9
9
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
10
10
|
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
@@ -1140,20 +1140,19 @@ const injectSupervisorIntoHTML = async ({
|
|
|
1140
1140
|
}
|
|
1141
1141
|
// 2. Inject supervisor js file + setup call
|
|
1142
1142
|
{
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}), "jsenv:supervisor");
|
|
1143
|
+
injectJsenvScript(htmlAst, {
|
|
1144
|
+
src: supervisorScriptSrc,
|
|
1145
|
+
initCall: {
|
|
1146
|
+
callee: "window.__supervisor__.setup",
|
|
1147
|
+
params: {
|
|
1148
|
+
...supervisorOptions,
|
|
1149
|
+
serverIsJsenvDevServer: webServer.isJsenvDevServer,
|
|
1150
|
+
rootDirectoryUrl: webServer.rootDirectoryUrl,
|
|
1151
|
+
scriptInfos
|
|
1152
|
+
}
|
|
1153
|
+
},
|
|
1154
|
+
pluginName: "jsenv:supervisor"
|
|
1155
|
+
});
|
|
1157
1156
|
}
|
|
1158
1157
|
// 3. Perform actions (transforming inline script content) and html mutations
|
|
1159
1158
|
if (actions.length > 0) {
|
|
@@ -1165,18 +1164,6 @@ const injectSupervisorIntoHTML = async ({
|
|
|
1165
1164
|
content: htmlModified
|
|
1166
1165
|
};
|
|
1167
1166
|
};
|
|
1168
|
-
const stringifyParams = (params, prefix = "") => {
|
|
1169
|
-
const source = JSON.stringify(params, null, prefix);
|
|
1170
|
-
if (prefix.length) {
|
|
1171
|
-
// remove leading "{\n"
|
|
1172
|
-
// remove leading prefix
|
|
1173
|
-
// remove trailing "\n}"
|
|
1174
|
-
return source.slice(2 + prefix.length, -2);
|
|
1175
|
-
}
|
|
1176
|
-
// remove leading "{"
|
|
1177
|
-
// remove trailing "}"
|
|
1178
|
-
return source.slice(1, -1);
|
|
1179
|
-
};
|
|
1180
1167
|
const generateCodeToSuperviseScriptWithSrc = ({
|
|
1181
1168
|
type,
|
|
1182
1169
|
src
|
|
@@ -1200,6 +1187,41 @@ const jsenvPluginSupervisor = ({
|
|
|
1200
1187
|
openInEditor = true,
|
|
1201
1188
|
errorBaseUrl
|
|
1202
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
|
+
};
|
|
1203
1225
|
return {
|
|
1204
1226
|
name: "jsenv:supervisor",
|
|
1205
1227
|
appliesDuring: "dev",
|
|
@@ -1209,18 +1231,19 @@ const jsenvPluginSupervisor = ({
|
|
|
1209
1231
|
pathname,
|
|
1210
1232
|
searchParams
|
|
1211
1233
|
} = new URL(serveInfo.request.url);
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (!match) {
|
|
1234
|
+
const urlWithLineAndColumn = decodeURIComponent(pathname.slice("/__get_cause_trace__/".length));
|
|
1235
|
+
const result = resolveUrlSite(urlWithLineAndColumn);
|
|
1236
|
+
if (!result) {
|
|
1216
1237
|
return {
|
|
1217
1238
|
status: 400,
|
|
1218
1239
|
body: "Missing line and column in url"
|
|
1219
1240
|
};
|
|
1220
1241
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1242
|
+
let {
|
|
1243
|
+
file,
|
|
1244
|
+
line,
|
|
1245
|
+
column
|
|
1246
|
+
} = result;
|
|
1224
1247
|
const urlInfo = serveInfo.kitchen.graph.getUrlInfo(file);
|
|
1225
1248
|
if (!urlInfo) {
|
|
1226
1249
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-supervisor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"/dist/"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@jsenv/ast": "6.1
|
|
29
|
+
"@jsenv/ast": "6.2.1",
|
|
30
30
|
"@jsenv/urls": "2.2.10",
|
|
31
31
|
"@jsenv/sourcemap": "1.2.13",
|
|
32
32
|
"launch-editor": "2.8.0"
|
package/src/client/supervisor.js
CHANGED
|
@@ -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
|
-
|
|
645
|
-
fileUrlSite
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
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
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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
|
}
|
package/src/html_supervisor.js
CHANGED
|
@@ -52,8 +52,7 @@ import {
|
|
|
52
52
|
getHtmlNodeAttribute,
|
|
53
53
|
setHtmlNodeAttributes,
|
|
54
54
|
analyzeScriptNode,
|
|
55
|
-
|
|
56
|
-
createHtmlNode,
|
|
55
|
+
injectJsenvScript,
|
|
57
56
|
getHtmlNodePosition,
|
|
58
57
|
getHtmlNodeText,
|
|
59
58
|
setHtmlNodeText,
|
|
@@ -224,33 +223,19 @@ export const injectSupervisorIntoHTML = async (
|
|
|
224
223
|
}
|
|
225
224
|
// 2. Inject supervisor js file + setup call
|
|
226
225
|
{
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
injectJsenvScript(htmlAst, {
|
|
227
|
+
src: supervisorScriptSrc,
|
|
228
|
+
initCall: {
|
|
229
|
+
callee: "window.__supervisor__.setup",
|
|
230
|
+
params: {
|
|
231
|
+
...supervisorOptions,
|
|
232
|
+
serverIsJsenvDevServer: webServer.isJsenvDevServer,
|
|
233
|
+
rootDirectoryUrl: webServer.rootDirectoryUrl,
|
|
234
|
+
scriptInfos,
|
|
235
|
+
},
|
|
233
236
|
},
|
|
234
|
-
"
|
|
235
|
-
);
|
|
236
|
-
injectHtmlNodeAsEarlyAsPossible(
|
|
237
|
-
htmlAst,
|
|
238
|
-
createHtmlNode({
|
|
239
|
-
tagName: "script",
|
|
240
|
-
textContent: `window.__supervisor__.setup({
|
|
241
|
-
${setupParamsSource}
|
|
242
|
-
});`,
|
|
243
|
-
}),
|
|
244
|
-
"jsenv:supervisor",
|
|
245
|
-
);
|
|
246
|
-
injectHtmlNodeAsEarlyAsPossible(
|
|
247
|
-
htmlAst,
|
|
248
|
-
createHtmlNode({
|
|
249
|
-
tagName: "script",
|
|
250
|
-
src: supervisorScriptSrc,
|
|
251
|
-
}),
|
|
252
|
-
"jsenv:supervisor",
|
|
253
|
-
);
|
|
237
|
+
pluginName: "jsenv:supervisor",
|
|
238
|
+
});
|
|
254
239
|
}
|
|
255
240
|
// 3. Perform actions (transforming inline script content) and html mutations
|
|
256
241
|
if (actions.length > 0) {
|
|
@@ -263,19 +248,6 @@ export const injectSupervisorIntoHTML = async (
|
|
|
263
248
|
};
|
|
264
249
|
};
|
|
265
250
|
|
|
266
|
-
const stringifyParams = (params, prefix = "") => {
|
|
267
|
-
const source = JSON.stringify(params, null, prefix);
|
|
268
|
-
if (prefix.length) {
|
|
269
|
-
// remove leading "{\n"
|
|
270
|
-
// remove leading prefix
|
|
271
|
-
// remove trailing "\n}"
|
|
272
|
-
return source.slice(2 + prefix.length, -2);
|
|
273
|
-
}
|
|
274
|
-
// remove leading "{"
|
|
275
|
-
// remove trailing "}"
|
|
276
|
-
return source.slice(1, -1);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
251
|
const generateCodeToSuperviseScriptWithSrc = ({ type, src }) => {
|
|
280
252
|
const srcEncoded = JSON.stringify(src);
|
|
281
253
|
if (type === "js_module") {
|
|
@@ -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
|
-
|
|
30
|
-
"/__get_cause_trace__/".length,
|
|
73
|
+
const urlWithLineAndColumn = decodeURIComponent(
|
|
74
|
+
pathname.slice("/__get_cause_trace__/".length),
|
|
31
75
|
);
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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: {
|