@jsenv/plugin-supervisor 1.6.6 → 1.6.8
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 +3 -3
- package/dist/jsenv_plugin_supervisor.js +79 -180
- package/package.json +7 -5
- package/src/client/supervisor.js +3 -3
- package/src/jsenv_plugin_supervisor.js +123 -145
package/dist/js/supervisor.js
CHANGED
|
@@ -1013,7 +1013,7 @@ window.__supervisor__ = (() => {
|
|
|
1013
1013
|
try {
|
|
1014
1014
|
if (exception.code === DYNAMIC_IMPORT_FETCH_ERROR || exception.reportedBy === "script_error_event") {
|
|
1015
1015
|
const errorCauseFile = exception.site.ownerSite ? exception.site.ownerSite.url : exception.site.url;
|
|
1016
|
-
const errorCauseAPIUrl = "/
|
|
1016
|
+
const errorCauseAPIUrl = "/.internal/get_error_cause/".concat(encodeURIComponent(errorCauseFile));
|
|
1017
1017
|
const response = await window.fetch(errorCauseAPIUrl);
|
|
1018
1018
|
if (response.status !== 200) {
|
|
1019
1019
|
return;
|
|
@@ -1032,7 +1032,7 @@ window.__supervisor__ = (() => {
|
|
|
1032
1032
|
line: exception.site.ownerSite.inlineLine,
|
|
1033
1033
|
column: exception.site.ownerSite.inlineColumn
|
|
1034
1034
|
}) : stringifyUrlSite(exception.site);
|
|
1035
|
-
const errorTraceAPIUrl = "/
|
|
1035
|
+
const errorTraceAPIUrl = "/.internal/get_cause_trace/".concat(encodeURIComponent(errorTraceFile));
|
|
1036
1036
|
const urlToFetch = new URL(errorTraceAPIUrl, window.origin);
|
|
1037
1037
|
if (!exception.stackSourcemapped) {
|
|
1038
1038
|
urlToFetch.searchParams.set("remap", "");
|
|
@@ -1077,7 +1077,7 @@ window.__supervisor__ = (() => {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
const urlWithLineAndColumn = stringifyUrlSite(urlSite);
|
|
1079
1079
|
return {
|
|
1080
|
-
href: urlSite.url.startsWith("file:") && openInEditor ? "javascript:window.fetch('/
|
|
1080
|
+
href: urlSite.url.startsWith("file:") && openInEditor ? "javascript:window.fetch('/.internal/open_file/".concat(encodeURIComponent(urlWithLineAndColumn), "')") : urlSite.url,
|
|
1081
1081
|
text: urlWithLineAndColumn
|
|
1082
1082
|
};
|
|
1083
1083
|
}
|
|
@@ -3,11 +3,9 @@ import process$1 from "node:process";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import tty from "node:tty";
|
|
5
5
|
import "string-width";
|
|
6
|
-
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
7
6
|
import { createRequire } from "node:module";
|
|
8
7
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
9
|
-
import "node:
|
|
10
|
-
import "node:crypto";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
9
|
|
|
12
10
|
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
|
|
13
11
|
/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
|
|
@@ -156,6 +154,48 @@ function createSupportsColor(stream, options = {}) {
|
|
|
156
154
|
isTTY: tty.isatty(2)
|
|
157
155
|
})
|
|
158
156
|
});
|
|
157
|
+
function isUnicodeSupported() {
|
|
158
|
+
const {
|
|
159
|
+
env
|
|
160
|
+
} = process$1;
|
|
161
|
+
const {
|
|
162
|
+
TERM,
|
|
163
|
+
TERM_PROGRAM
|
|
164
|
+
} = env;
|
|
165
|
+
if (process$1.platform !== 'win32') {
|
|
166
|
+
return TERM !== 'linux'; // Linux console (kernel)
|
|
167
|
+
}
|
|
168
|
+
return Boolean(env.WT_SESSION) // Windows Terminal
|
|
169
|
+
|| Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
170
|
+
|| env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
171
|
+
|| TERM_PROGRAM === 'Terminus-Sublime' || TERM_PROGRAM === 'vscode' || TERM === 'xterm-256color' || TERM === 'alacritty' || TERM === 'rxvt-unicode' || TERM === 'rxvt-unicode-256color' || env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
|
|
175
|
+
|
|
176
|
+
const isBrowser = globalThis.window?.document !== undefined;
|
|
177
|
+
globalThis.process?.versions?.node !== undefined;
|
|
178
|
+
globalThis.process?.versions?.bun !== undefined;
|
|
179
|
+
globalThis.Deno?.version?.deno !== undefined;
|
|
180
|
+
globalThis.process?.versions?.electron !== undefined;
|
|
181
|
+
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
182
|
+
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
183
|
+
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
184
|
+
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
185
|
+
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
186
|
+
|
|
187
|
+
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
188
|
+
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
189
|
+
platform === 'macOS' || globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
190
|
+
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true || globalThis.process?.platform === 'darwin';
|
|
191
|
+
platform === 'Windows' || globalThis.navigator?.platform === 'Win32' || globalThis.process?.platform === 'win32';
|
|
192
|
+
platform === 'Linux' || globalThis.navigator?.platform?.startsWith('Linux') === true || globalThis.navigator?.userAgent?.includes(' Linux ') === true || globalThis.process?.platform === 'linux';
|
|
193
|
+
platform === 'Android' || globalThis.navigator?.platform === 'Android' || globalThis.navigator?.userAgent?.includes(' Android ') === true || globalThis.process?.platform === 'android';
|
|
194
|
+
!isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
195
|
+
!isBrowser && process$1.platform === 'win32';
|
|
196
|
+
isBrowser ? () => {
|
|
197
|
+
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
198
|
+
} : process$1.cwd;
|
|
159
199
|
|
|
160
200
|
// https://github.com/Marak/colors.js/blob/master/lib/styles.js
|
|
161
201
|
// https://stackoverflow.com/a/75985833/2634179
|
|
@@ -211,22 +251,6 @@ const ANSI = createAnsi({
|
|
|
211
251
|
// because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
|
|
212
252
|
process.env.GITHUB_WORKFLOW
|
|
213
253
|
});
|
|
214
|
-
function isUnicodeSupported() {
|
|
215
|
-
const {
|
|
216
|
-
env
|
|
217
|
-
} = process$1;
|
|
218
|
-
const {
|
|
219
|
-
TERM,
|
|
220
|
-
TERM_PROGRAM
|
|
221
|
-
} = env;
|
|
222
|
-
if (process$1.platform !== 'win32') {
|
|
223
|
-
return TERM !== 'linux'; // Linux console (kernel)
|
|
224
|
-
}
|
|
225
|
-
return Boolean(env.WT_SESSION) // Windows Terminal
|
|
226
|
-
|| Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
227
|
-
|| env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
228
|
-
|| TERM_PROGRAM === 'Terminus-Sublime' || TERM_PROGRAM === 'vscode' || TERM === 'xterm-256color' || TERM === 'alacritty' || TERM === 'rxvt-unicode' || TERM === 'rxvt-unicode-256color' || env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
229
|
-
}
|
|
230
254
|
|
|
231
255
|
// see also https://github.com/sindresorhus/figures
|
|
232
256
|
|
|
@@ -439,32 +463,6 @@ const fillLeft = (value, biggestValue, char = " ") => {
|
|
|
439
463
|
return padded;
|
|
440
464
|
};
|
|
441
465
|
|
|
442
|
-
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
|
|
443
|
-
|
|
444
|
-
const isBrowser = globalThis.window?.document !== undefined;
|
|
445
|
-
globalThis.process?.versions?.node !== undefined;
|
|
446
|
-
globalThis.process?.versions?.bun !== undefined;
|
|
447
|
-
globalThis.Deno?.version?.deno !== undefined;
|
|
448
|
-
globalThis.process?.versions?.electron !== undefined;
|
|
449
|
-
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
450
|
-
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
451
|
-
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
452
|
-
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
453
|
-
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
454
|
-
|
|
455
|
-
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
456
|
-
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
457
|
-
platform === 'macOS' || globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
458
|
-
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true || globalThis.process?.platform === 'darwin';
|
|
459
|
-
platform === 'Windows' || globalThis.navigator?.platform === 'Win32' || globalThis.process?.platform === 'win32';
|
|
460
|
-
platform === 'Linux' || globalThis.navigator?.platform?.startsWith('Linux') === true || globalThis.navigator?.userAgent?.includes(' Linux ') === true || globalThis.process?.platform === 'linux';
|
|
461
|
-
platform === 'Android' || globalThis.navigator?.platform === 'Android' || globalThis.navigator?.userAgent?.includes(' Android ') === true || globalThis.process?.platform === 'android';
|
|
462
|
-
!isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
463
|
-
!isBrowser && process$1.platform === 'win32';
|
|
464
|
-
isBrowser ? () => {
|
|
465
|
-
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
466
|
-
} : process$1.cwd;
|
|
467
|
-
|
|
468
466
|
// normalize url search params:
|
|
469
467
|
// Using URLSearchParams to alter the url search params
|
|
470
468
|
// can result into "file:///file.css?css_module"
|
|
@@ -497,30 +495,6 @@ const injectQueryParams = (url, params) => {
|
|
|
497
495
|
return normalizeUrl(urlWithParams);
|
|
498
496
|
};
|
|
499
497
|
|
|
500
|
-
const isFileSystemPath = value => {
|
|
501
|
-
if (typeof value !== "string") {
|
|
502
|
-
throw new TypeError("isFileSystemPath first arg must be a string, got ".concat(value));
|
|
503
|
-
}
|
|
504
|
-
if (value[0] === "/") {
|
|
505
|
-
return true;
|
|
506
|
-
}
|
|
507
|
-
return startsWithWindowsDriveLetter(value);
|
|
508
|
-
};
|
|
509
|
-
const startsWithWindowsDriveLetter = string => {
|
|
510
|
-
const firstChar = string[0];
|
|
511
|
-
if (!/[a-zA-Z]/.test(firstChar)) return false;
|
|
512
|
-
const secondChar = string[1];
|
|
513
|
-
if (secondChar !== ":") return false;
|
|
514
|
-
return true;
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
const fileSystemPathToUrl = value => {
|
|
518
|
-
if (!isFileSystemPath(value)) {
|
|
519
|
-
throw new Error("value must be a filesystem path, got ".concat(value));
|
|
520
|
-
}
|
|
521
|
-
return String(pathToFileURL(value));
|
|
522
|
-
};
|
|
523
|
-
|
|
524
498
|
const getCommonPathname = (pathname, otherPathname) => {
|
|
525
499
|
if (pathname === otherPathname) {
|
|
526
500
|
return pathname;
|
|
@@ -605,41 +579,6 @@ const pathnameToParentPathname = pathname => {
|
|
|
605
579
|
return pathname.slice(0, slashLastIndex + 1);
|
|
606
580
|
};
|
|
607
581
|
|
|
608
|
-
const urlToFileSystemPath = url => {
|
|
609
|
-
const urlObject = new URL(url);
|
|
610
|
-
let {
|
|
611
|
-
origin,
|
|
612
|
-
pathname,
|
|
613
|
-
hash
|
|
614
|
-
} = urlObject;
|
|
615
|
-
if (urlObject.protocol === "file:") {
|
|
616
|
-
origin = "file://";
|
|
617
|
-
}
|
|
618
|
-
pathname = pathname.split("/").map(part => {
|
|
619
|
-
return part.replace(/%(?![0-9A-F][0-9A-F])/g, "%25");
|
|
620
|
-
}).join("/");
|
|
621
|
-
if (hash) {
|
|
622
|
-
pathname += "%23".concat(encodeURIComponent(hash.slice(1)));
|
|
623
|
-
}
|
|
624
|
-
const urlString = "".concat(origin).concat(pathname);
|
|
625
|
-
const fileSystemPath = fileURLToPath(urlString);
|
|
626
|
-
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
|
|
627
|
-
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|
|
628
|
-
// the trailing slash on linux but does not on windows
|
|
629
|
-
return fileSystemPath.slice(0, -1);
|
|
630
|
-
}
|
|
631
|
-
return fileSystemPath;
|
|
632
|
-
};
|
|
633
|
-
|
|
634
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
635
|
-
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
636
|
-
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
637
|
-
for (let i = 0; i < chars.length; i++) {
|
|
638
|
-
const c = chars.charCodeAt(i);
|
|
639
|
-
intToChar[i] = c;
|
|
640
|
-
charToInt[c] = i;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
582
|
const require = createRequire(import.meta.url);
|
|
644
583
|
// consider using https://github.com/7rulnik/source-map-js
|
|
645
584
|
|
|
@@ -648,12 +587,6 @@ const requireSourcemap = () => {
|
|
|
648
587
|
return namespace;
|
|
649
588
|
};
|
|
650
589
|
|
|
651
|
-
/*
|
|
652
|
-
* https://github.com/mozilla/source-map#sourcemapgenerator
|
|
653
|
-
*/
|
|
654
|
-
|
|
655
|
-
requireSourcemap();
|
|
656
|
-
|
|
657
590
|
// https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
|
|
658
591
|
const getOriginalPosition = ({
|
|
659
592
|
sourcemap,
|
|
@@ -1227,7 +1160,7 @@ const injectSupervisorIntoHTML = async ({
|
|
|
1227
1160
|
}
|
|
1228
1161
|
const src = getHtmlNodeAttribute(scriptNode, "src");
|
|
1229
1162
|
if (src) {
|
|
1230
|
-
const urlObject = new URL(src, "http://example.com
|
|
1163
|
+
const urlObject = new URL(src, "http://example.com");
|
|
1231
1164
|
if (urlObject.searchParams.has("inline")) {
|
|
1232
1165
|
return;
|
|
1233
1166
|
}
|
|
@@ -1416,7 +1349,7 @@ const createPackageImportNotDefinedError = (specifier, {
|
|
|
1416
1349
|
const isSpecifierForNodeBuiltin = specifier => {
|
|
1417
1350
|
return specifier.startsWith("node:") || NODE_BUILTIN_MODULE_SPECIFIERS.includes(specifier);
|
|
1418
1351
|
};
|
|
1419
|
-
const NODE_BUILTIN_MODULE_SPECIFIERS = ["assert", "assert/strict", "async_hooks", "buffer_ieee754", "buffer", "child_process", "cluster", "console", "constants", "crypto", "_debugger", "dgram", "dns", "domain", "events", "freelist", "fs", "fs/promises", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing", "_http_server", "http", "http2", "https", "inspector", "_linklist", "module", "net", "node-inspect/lib/_inspect", "node-inspect/lib/internal/inspect_client", "node-inspect/lib/internal/inspect_repl", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "smalloc", "_stream_duplex", "_stream_transform", "_stream_wrap", "_stream_passthrough", "_stream_readable", "_stream_writable", "stream", "stream/promises", "string_decoder", "sys", "timers", "_tls_common", "_tls_legacy", "_tls_wrap", "tls", "trace_events", "tty", "url", "util", "v8/tools/arguments", "v8/tools/codemap", "v8/tools/consarray", "v8/tools/csvparser", "v8/tools/logreader", "v8/tools/profile_view", "v8/tools/splaytree", "v8", "vm", "worker_threads", "zlib",
|
|
1352
|
+
const NODE_BUILTIN_MODULE_SPECIFIERS = ["assert", "assert/strict", "async_hooks", "buffer_ieee754", "buffer", "child_process", "cluster", "console", "constants", "crypto", "_debugger", "dgram", "dns", "domain", "events", "freelist", "fs", "fsevents", "fs/promises", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing", "_http_server", "http", "http2", "https", "inspector", "_linklist", "module", "net", "node-inspect/lib/_inspect", "node-inspect/lib/internal/inspect_client", "node-inspect/lib/internal/inspect_repl", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "smalloc", "_stream_duplex", "_stream_transform", "_stream_wrap", "_stream_passthrough", "_stream_readable", "_stream_writable", "stream", "stream/promises", "string_decoder", "sys", "timers", "_tls_common", "_tls_legacy", "_tls_wrap", "tls", "trace_events", "tty", "url", "util", "v8/tools/arguments", "v8/tools/codemap", "v8/tools/consarray", "v8/tools/csvparser", "v8/tools/logreader", "v8/tools/profile_view", "v8/tools/splaytree", "v8", "vm", "worker_threads", "zlib",
|
|
1420
1353
|
// global is special
|
|
1421
1354
|
"global"];
|
|
1422
1355
|
|
|
@@ -1555,6 +1488,7 @@ const applyBrowserFieldResolution = (specifier, resolutionContext) => {
|
|
|
1555
1488
|
if (url) {
|
|
1556
1489
|
return {
|
|
1557
1490
|
type: "field:browser",
|
|
1491
|
+
isMain: true,
|
|
1558
1492
|
packageDirectoryUrl,
|
|
1559
1493
|
packageJson,
|
|
1560
1494
|
url
|
|
@@ -1784,6 +1718,7 @@ const applyPackageTargetResolution = (target, resolutionContext) => {
|
|
|
1784
1718
|
}
|
|
1785
1719
|
return {
|
|
1786
1720
|
type: isImport ? "field:imports" : "field:exports",
|
|
1721
|
+
isMain: subpath === "" || subpath === ".",
|
|
1787
1722
|
packageDirectoryUrl,
|
|
1788
1723
|
packageJson,
|
|
1789
1724
|
url: pattern ? targetUrl.replaceAll("*", subpath) : new URL(subpath, targetUrl).href
|
|
@@ -1966,6 +1901,7 @@ const applyLegacySubpathResolution = (packageSubpath, resolutionContext) => {
|
|
|
1966
1901
|
}
|
|
1967
1902
|
return {
|
|
1968
1903
|
type: "subpath",
|
|
1904
|
+
isMain: packageSubpath === ".",
|
|
1969
1905
|
packageDirectoryUrl,
|
|
1970
1906
|
packageJson,
|
|
1971
1907
|
url: new URL(packageSubpath, packageDirectoryUrl).href
|
|
@@ -1986,6 +1922,7 @@ const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
|
|
|
1986
1922
|
if (resolved) {
|
|
1987
1923
|
return {
|
|
1988
1924
|
type: resolved.type,
|
|
1925
|
+
isMain: resolved.isMain,
|
|
1989
1926
|
packageDirectoryUrl,
|
|
1990
1927
|
packageJson,
|
|
1991
1928
|
url: new URL(resolved.path, packageDirectoryUrl).href
|
|
@@ -1995,6 +1932,7 @@ const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
|
|
|
1995
1932
|
return {
|
|
1996
1933
|
type: "field:main",
|
|
1997
1934
|
// the absence of "main" field
|
|
1935
|
+
isMain: true,
|
|
1998
1936
|
packageDirectoryUrl,
|
|
1999
1937
|
packageJson,
|
|
2000
1938
|
url: new URL("index.js", packageDirectoryUrl).href
|
|
@@ -2007,18 +1945,21 @@ const mainLegacyResolvers = {
|
|
|
2007
1945
|
if (typeof packageJson.module === "string") {
|
|
2008
1946
|
return {
|
|
2009
1947
|
type: "field:module",
|
|
1948
|
+
isMain: true,
|
|
2010
1949
|
path: packageJson.module
|
|
2011
1950
|
};
|
|
2012
1951
|
}
|
|
2013
1952
|
if (typeof packageJson.jsnext === "string") {
|
|
2014
1953
|
return {
|
|
2015
1954
|
type: "field:jsnext",
|
|
1955
|
+
isMain: true,
|
|
2016
1956
|
path: packageJson.jsnext
|
|
2017
1957
|
};
|
|
2018
1958
|
}
|
|
2019
1959
|
if (typeof packageJson.main === "string") {
|
|
2020
1960
|
return {
|
|
2021
1961
|
type: "field:main",
|
|
1962
|
+
isMain: true,
|
|
2022
1963
|
path: packageJson.main
|
|
2023
1964
|
};
|
|
2024
1965
|
}
|
|
@@ -2041,6 +1982,7 @@ const mainLegacyResolvers = {
|
|
|
2041
1982
|
if (typeof packageJson.module === "string") {
|
|
2042
1983
|
return {
|
|
2043
1984
|
type: "field:module",
|
|
1985
|
+
isMain: true,
|
|
2044
1986
|
path: packageJson.module
|
|
2045
1987
|
};
|
|
2046
1988
|
}
|
|
@@ -2049,6 +1991,7 @@ const mainLegacyResolvers = {
|
|
|
2049
1991
|
if (typeof packageJson.module !== "string" || packageJson.module === browserMain) {
|
|
2050
1992
|
return {
|
|
2051
1993
|
type: "field:browser",
|
|
1994
|
+
isMain: true,
|
|
2052
1995
|
path: browserMain
|
|
2053
1996
|
};
|
|
2054
1997
|
}
|
|
@@ -2057,11 +2000,13 @@ const mainLegacyResolvers = {
|
|
|
2057
2000
|
if (/typeof exports\s*==/.test(content) && /typeof module\s*==/.test(content) || /module\.exports\s*=/.test(content)) {
|
|
2058
2001
|
return {
|
|
2059
2002
|
type: "field:module",
|
|
2003
|
+
isMain: true,
|
|
2060
2004
|
path: packageJson.module
|
|
2061
2005
|
};
|
|
2062
2006
|
}
|
|
2063
2007
|
return {
|
|
2064
2008
|
type: "field:browser",
|
|
2009
|
+
isMain: true,
|
|
2065
2010
|
path: browserMain
|
|
2066
2011
|
};
|
|
2067
2012
|
},
|
|
@@ -2071,6 +2016,7 @@ const mainLegacyResolvers = {
|
|
|
2071
2016
|
if (typeof packageJson.main === "string") {
|
|
2072
2017
|
return {
|
|
2073
2018
|
type: "field:main",
|
|
2019
|
+
isMain: true,
|
|
2074
2020
|
path: packageJson.main
|
|
2075
2021
|
};
|
|
2076
2022
|
}
|
|
@@ -2114,35 +2060,6 @@ const resolvePackageSymlink = packageDirectoryUrl => {
|
|
|
2114
2060
|
return "".concat(packageDirectoryResolvedUrl, "/");
|
|
2115
2061
|
};
|
|
2116
2062
|
|
|
2117
|
-
process.platform === "win32";
|
|
2118
|
-
fileSystemPathToUrl(process.cwd());
|
|
2119
|
-
|
|
2120
|
-
/*
|
|
2121
|
-
* - stats object documentation on Node.js
|
|
2122
|
-
* https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_class_fs_stats
|
|
2123
|
-
*/
|
|
2124
|
-
|
|
2125
|
-
process.platform === "win32";
|
|
2126
|
-
|
|
2127
|
-
/*
|
|
2128
|
-
* - stats object documentation on Node.js
|
|
2129
|
-
* https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_class_fs_stats
|
|
2130
|
-
*/
|
|
2131
|
-
|
|
2132
|
-
process.platform === "win32";
|
|
2133
|
-
|
|
2134
|
-
process.platform === "win32";
|
|
2135
|
-
|
|
2136
|
-
process.platform === "win32";
|
|
2137
|
-
|
|
2138
|
-
process.platform === "win32";
|
|
2139
|
-
|
|
2140
|
-
process.platform === "linux";
|
|
2141
|
-
|
|
2142
|
-
process.platform === "darwin";
|
|
2143
|
-
process.platform === "linux";
|
|
2144
|
-
process.platform === "freebsd";
|
|
2145
|
-
|
|
2146
2063
|
/*
|
|
2147
2064
|
* This plugin provides a way for jsenv to supervisor js execution:
|
|
2148
2065
|
* - Know how many js are executed, when they are done, collect errors, etc...
|
|
@@ -2195,13 +2112,14 @@ const jsenvPluginSupervisor = ({
|
|
|
2195
2112
|
return {
|
|
2196
2113
|
name: "jsenv:supervisor",
|
|
2197
2114
|
appliesDuring: "dev",
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2115
|
+
devServerRoutes: [{
|
|
2116
|
+
endpoint: "GET /.internal/get_cause_trace/*",
|
|
2117
|
+
description: "Return source code around the place an error was thrown.",
|
|
2118
|
+
declarationSource: import.meta.url,
|
|
2119
|
+
fetch: async (request, {
|
|
2120
|
+
kitchen
|
|
2121
|
+
}) => {
|
|
2122
|
+
const urlWithLineAndColumn = decodeURIComponent(request.params[0]);
|
|
2205
2123
|
const result = resolveUrlSite(urlWithLineAndColumn);
|
|
2206
2124
|
if (!result) {
|
|
2207
2125
|
return {
|
|
@@ -2214,7 +2132,7 @@ const jsenvPluginSupervisor = ({
|
|
|
2214
2132
|
line,
|
|
2215
2133
|
column
|
|
2216
2134
|
} = result;
|
|
2217
|
-
const urlInfo =
|
|
2135
|
+
const urlInfo = kitchen.graph.getUrlInfo(file);
|
|
2218
2136
|
if (!urlInfo) {
|
|
2219
2137
|
return {
|
|
2220
2138
|
status: 204,
|
|
@@ -2226,13 +2144,12 @@ const jsenvPluginSupervisor = ({
|
|
|
2226
2144
|
if (!urlInfo.originalContent) {
|
|
2227
2145
|
await urlInfo.fetchContent();
|
|
2228
2146
|
}
|
|
2229
|
-
const remap = searchParams.has("remap");
|
|
2147
|
+
const remap = request.searchParams.has("remap");
|
|
2230
2148
|
if (remap) {
|
|
2231
2149
|
const sourcemap = urlInfo.sourcemap;
|
|
2232
2150
|
if (sourcemap) {
|
|
2233
2151
|
const original = getOriginalPosition({
|
|
2234
2152
|
sourcemap,
|
|
2235
|
-
url: file,
|
|
2236
2153
|
line,
|
|
2237
2154
|
column
|
|
2238
2155
|
});
|
|
@@ -2265,8 +2182,14 @@ const jsenvPluginSupervisor = ({
|
|
|
2265
2182
|
body: causeTraceJson
|
|
2266
2183
|
};
|
|
2267
2184
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2185
|
+
}, {
|
|
2186
|
+
endpoint: "GET /.internal/get_error_cause/*",
|
|
2187
|
+
description: "Return the error that occured when a file was served by jsenv dev server or null.",
|
|
2188
|
+
declarationSource: import.meta.url,
|
|
2189
|
+
fetch: (request, {
|
|
2190
|
+
kitchen
|
|
2191
|
+
}) => {
|
|
2192
|
+
let file = decodeURIComponent(request.params[0]);
|
|
2270
2193
|
file = decodeURIComponent(file);
|
|
2271
2194
|
if (!file) {
|
|
2272
2195
|
return {
|
|
@@ -2278,12 +2201,12 @@ const jsenvPluginSupervisor = ({
|
|
|
2278
2201
|
url
|
|
2279
2202
|
} = applyNodeEsmResolution({
|
|
2280
2203
|
conditions: [],
|
|
2281
|
-
parentUrl:
|
|
2204
|
+
parentUrl: kitchen.context.rootDirectoryUrl,
|
|
2282
2205
|
specifier: file
|
|
2283
2206
|
});
|
|
2284
2207
|
file = url;
|
|
2285
2208
|
const getErrorCauseInfo = () => {
|
|
2286
|
-
const urlInfo =
|
|
2209
|
+
const urlInfo = kitchen.graph.getUrlInfo(file);
|
|
2287
2210
|
if (!urlInfo) {
|
|
2288
2211
|
return null;
|
|
2289
2212
|
}
|
|
@@ -2321,31 +2244,7 @@ const jsenvPluginSupervisor = ({
|
|
|
2321
2244
|
body
|
|
2322
2245
|
};
|
|
2323
2246
|
}
|
|
2324
|
-
|
|
2325
|
-
let file = serveInfo.request.pathname.slice("/__open_in_editor__/".length);
|
|
2326
|
-
file = decodeURIComponent(file);
|
|
2327
|
-
if (!file) {
|
|
2328
|
-
return {
|
|
2329
|
-
status: 400,
|
|
2330
|
-
body: "Missing file in url"
|
|
2331
|
-
};
|
|
2332
|
-
}
|
|
2333
|
-
const fileUrl = new URL(file, serveInfo.rootDirectoryUrl);
|
|
2334
|
-
const filePath = urlToFileSystemPath(fileUrl);
|
|
2335
|
-
const require = createRequire(import.meta.url);
|
|
2336
|
-
const launch = require("launch-editor");
|
|
2337
|
-
launch(filePath, () => {
|
|
2338
|
-
// ignore error for now
|
|
2339
|
-
});
|
|
2340
|
-
return {
|
|
2341
|
-
status: 200,
|
|
2342
|
-
headers: {
|
|
2343
|
-
"cache-control": "no-store"
|
|
2344
|
-
}
|
|
2345
|
-
};
|
|
2346
|
-
}
|
|
2347
|
-
return null;
|
|
2348
|
-
},
|
|
2247
|
+
}],
|
|
2349
2248
|
transformUrlContent: {
|
|
2350
2249
|
html: htmlUrlInfo => {
|
|
2351
2250
|
const supervisorFileReference = htmlUrlInfo.dependencies.inject({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-supervisor",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,11 +25,13 @@
|
|
|
25
25
|
"/src/",
|
|
26
26
|
"/dist/"
|
|
27
27
|
],
|
|
28
|
+
"sideEffects": [
|
|
29
|
+
"./src/client/supervisor.js"
|
|
30
|
+
],
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@jsenv/ast": "6.
|
|
30
|
-
"@jsenv/urls": "2.6.
|
|
31
|
-
"@jsenv/sourcemap": "1.
|
|
32
|
-
"launch-editor": "2.9.1"
|
|
32
|
+
"@jsenv/ast": "6.6.1",
|
|
33
|
+
"@jsenv/urls": "2.6.2",
|
|
34
|
+
"@jsenv/sourcemap": "1.3.1"
|
|
33
35
|
},
|
|
34
36
|
"scripts": {
|
|
35
37
|
"build": "node ./scripts/build.mjs",
|
package/src/client/supervisor.js
CHANGED
|
@@ -1041,7 +1041,7 @@ window.__supervisor__ = (() => {
|
|
|
1041
1041
|
const errorCauseFile = exception.site.ownerSite
|
|
1042
1042
|
? exception.site.ownerSite.url
|
|
1043
1043
|
: exception.site.url;
|
|
1044
|
-
const errorCauseAPIUrl =
|
|
1044
|
+
const errorCauseAPIUrl = `/.internal/get_error_cause/${encodeURIComponent(
|
|
1045
1045
|
errorCauseFile,
|
|
1046
1046
|
)}`;
|
|
1047
1047
|
const response = await window.fetch(errorCauseAPIUrl);
|
|
@@ -1064,7 +1064,7 @@ window.__supervisor__ = (() => {
|
|
|
1064
1064
|
column: exception.site.ownerSite.inlineColumn,
|
|
1065
1065
|
})
|
|
1066
1066
|
: stringifyUrlSite(exception.site);
|
|
1067
|
-
const errorTraceAPIUrl =
|
|
1067
|
+
const errorTraceAPIUrl = `/.internal/get_cause_trace/${encodeURIComponent(
|
|
1068
1068
|
errorTraceFile,
|
|
1069
1069
|
)}`;
|
|
1070
1070
|
const urlToFetch = new URL(errorTraceAPIUrl, window.origin);
|
|
@@ -1107,7 +1107,7 @@ window.__supervisor__ = (() => {
|
|
|
1107
1107
|
return {
|
|
1108
1108
|
href:
|
|
1109
1109
|
urlSite.url.startsWith("file:") && openInEditor
|
|
1110
|
-
? `javascript:window.fetch('/
|
|
1110
|
+
? `javascript:window.fetch('/.internal/open_file/${encodeURIComponent(
|
|
1111
1111
|
urlWithLineAndColumn,
|
|
1112
1112
|
)}')`
|
|
1113
1113
|
: urlSite.url,
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
import { generateContentFrame } from "@jsenv/humanize";
|
|
7
7
|
import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
|
|
8
8
|
import { getOriginalPosition } from "@jsenv/sourcemap";
|
|
9
|
-
import { injectQueryParams
|
|
10
|
-
import { createRequire } from "node:module";
|
|
9
|
+
import { injectQueryParams } from "@jsenv/urls";
|
|
11
10
|
import {
|
|
12
11
|
injectSupervisorIntoHTML,
|
|
13
12
|
supervisorFileUrl,
|
|
@@ -71,161 +70,140 @@ export const jsenvPluginSupervisor = ({
|
|
|
71
70
|
return {
|
|
72
71
|
name: "jsenv:supervisor",
|
|
73
72
|
appliesDuring: "dev",
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
73
|
+
devServerRoutes: [
|
|
74
|
+
{
|
|
75
|
+
endpoint: "GET /.internal/get_cause_trace/*",
|
|
76
|
+
description: "Return source code around the place an error was thrown.",
|
|
77
|
+
declarationSource: import.meta.url,
|
|
78
|
+
fetch: async (request, { kitchen }) => {
|
|
79
|
+
const urlWithLineAndColumn = decodeURIComponent(request.params[0]);
|
|
80
|
+
const result = resolveUrlSite(urlWithLineAndColumn);
|
|
81
|
+
if (!result) {
|
|
82
|
+
return {
|
|
83
|
+
status: 400,
|
|
84
|
+
body: "Missing line and column in url",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
let { file, line, column } = result;
|
|
88
|
+
const urlInfo = kitchen.graph.getUrlInfo(file);
|
|
89
|
+
if (!urlInfo) {
|
|
90
|
+
return {
|
|
91
|
+
status: 204,
|
|
92
|
+
headers: {
|
|
93
|
+
"cache-control": "no-store",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (!urlInfo.originalContent) {
|
|
98
|
+
await urlInfo.fetchContent();
|
|
99
|
+
}
|
|
100
|
+
const remap = request.searchParams.has("remap");
|
|
101
|
+
if (remap) {
|
|
102
|
+
const sourcemap = urlInfo.sourcemap;
|
|
103
|
+
if (sourcemap) {
|
|
104
|
+
const original = getOriginalPosition({
|
|
105
|
+
sourcemap,
|
|
106
|
+
url: file,
|
|
107
|
+
line,
|
|
108
|
+
column,
|
|
109
|
+
});
|
|
110
|
+
if (original.line !== null) {
|
|
111
|
+
line = original.line;
|
|
112
|
+
if (original.column !== null) {
|
|
113
|
+
column = original.column;
|
|
114
|
+
}
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
url: file,
|
|
120
|
-
line,
|
|
121
|
-
column,
|
|
122
|
-
codeFrame: generateContentFrame({
|
|
118
|
+
const causeTrace = {
|
|
119
|
+
url: file,
|
|
123
120
|
line,
|
|
124
121
|
column,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"cache-control": "no-store",
|
|
133
|
-
"content-type": "application/json",
|
|
134
|
-
"content-length": Buffer.byteLength(causeTraceJson),
|
|
135
|
-
},
|
|
136
|
-
body: causeTraceJson,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (serveInfo.request.pathname.startsWith("/__get_error_cause__/")) {
|
|
140
|
-
let file = serveInfo.request.pathname.slice(
|
|
141
|
-
"/__get_error_cause__/".length,
|
|
142
|
-
);
|
|
143
|
-
file = decodeURIComponent(file);
|
|
144
|
-
if (!file) {
|
|
122
|
+
codeFrame: generateContentFrame({
|
|
123
|
+
line,
|
|
124
|
+
column,
|
|
125
|
+
content: urlInfo.originalContent,
|
|
126
|
+
}),
|
|
127
|
+
};
|
|
128
|
+
const causeTraceJson = JSON.stringify(causeTrace, null, " ");
|
|
145
129
|
return {
|
|
146
|
-
status:
|
|
147
|
-
|
|
130
|
+
status: 200,
|
|
131
|
+
headers: {
|
|
132
|
+
"cache-control": "no-store",
|
|
133
|
+
"content-type": "application/json",
|
|
134
|
+
"content-length": Buffer.byteLength(causeTraceJson),
|
|
135
|
+
},
|
|
136
|
+
body: causeTraceJson,
|
|
148
137
|
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
endpoint: "GET /.internal/get_error_cause/*",
|
|
142
|
+
description:
|
|
143
|
+
"Return the error that occured when a file was served by jsenv dev server or null.",
|
|
144
|
+
declarationSource: import.meta.url,
|
|
145
|
+
fetch: (request, { kitchen }) => {
|
|
146
|
+
let file = decodeURIComponent(request.params[0]);
|
|
147
|
+
file = decodeURIComponent(file);
|
|
148
|
+
if (!file) {
|
|
149
|
+
return {
|
|
150
|
+
status: 400,
|
|
151
|
+
body: "Missing file in url",
|
|
152
|
+
};
|
|
164
153
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
154
|
+
const { url } = applyNodeEsmResolution({
|
|
155
|
+
conditions: [],
|
|
156
|
+
parentUrl: kitchen.context.rootDirectoryUrl,
|
|
157
|
+
specifier: file,
|
|
158
|
+
});
|
|
159
|
+
file = url;
|
|
160
|
+
const getErrorCauseInfo = () => {
|
|
161
|
+
const urlInfo = kitchen.graph.getUrlInfo(file);
|
|
162
|
+
if (!urlInfo) {
|
|
163
|
+
return null;
|
|
170
164
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
message: causeInfo.message,
|
|
181
|
-
reason: causeInfo.reason,
|
|
182
|
-
stack: errorBaseUrl
|
|
183
|
-
? `stack mocked for snapshot`
|
|
184
|
-
: causeInfo.stack,
|
|
185
|
-
trace: causeInfo.trace,
|
|
165
|
+
const { error } = urlInfo;
|
|
166
|
+
if (error) {
|
|
167
|
+
return error;
|
|
168
|
+
}
|
|
169
|
+
// search in direct dependencies (404 or 500)
|
|
170
|
+
for (const referenceToOther of urlInfo.referenceToOthersSet) {
|
|
171
|
+
const referencedUrlInfo = referenceToOther.urlInfo;
|
|
172
|
+
if (referencedUrlInfo.error) {
|
|
173
|
+
return referencedUrlInfo.error;
|
|
186
174
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (!file) {
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
178
|
+
const causeInfo = getErrorCauseInfo();
|
|
179
|
+
const body = JSON.stringify(
|
|
180
|
+
causeInfo
|
|
181
|
+
? {
|
|
182
|
+
code: causeInfo.code,
|
|
183
|
+
name: causeInfo.name,
|
|
184
|
+
message: causeInfo.message,
|
|
185
|
+
reason: causeInfo.reason,
|
|
186
|
+
stack: errorBaseUrl
|
|
187
|
+
? `stack mocked for snapshot`
|
|
188
|
+
: causeInfo.stack,
|
|
189
|
+
trace: causeInfo.trace,
|
|
190
|
+
}
|
|
191
|
+
: null,
|
|
192
|
+
null,
|
|
193
|
+
" ",
|
|
194
|
+
);
|
|
208
195
|
return {
|
|
209
|
-
status:
|
|
210
|
-
|
|
196
|
+
status: 200,
|
|
197
|
+
headers: {
|
|
198
|
+
"cache-control": "no-store",
|
|
199
|
+
"content-type": "application/json",
|
|
200
|
+
"content-length": Buffer.byteLength(body),
|
|
201
|
+
},
|
|
202
|
+
body,
|
|
211
203
|
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const require = createRequire(import.meta.url);
|
|
216
|
-
const launch = require("launch-editor");
|
|
217
|
-
launch(filePath, () => {
|
|
218
|
-
// ignore error for now
|
|
219
|
-
});
|
|
220
|
-
return {
|
|
221
|
-
status: 200,
|
|
222
|
-
headers: {
|
|
223
|
-
"cache-control": "no-store",
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
],
|
|
229
207
|
transformUrlContent: {
|
|
230
208
|
html: (htmlUrlInfo) => {
|
|
231
209
|
const supervisorFileReference = htmlUrlInfo.dependencies.inject({
|