@jsenv/plugin-supervisor 1.5.25 → 1.5.27

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.
@@ -566,6 +566,17 @@ window.__supervisor__ = (() => {
566
566
  stackFrames = [];
567
567
  for (const callSite of callSites) {
568
568
  const url = callSite.getFileName() || callSite.getScriptNameOrSourceURL();
569
+ if (!url) {
570
+ // thinks like Array.forEach can generate this
571
+ const stackFrame = {
572
+ raw: " at ".concat(String(callSite)),
573
+ url: null,
574
+ line: null,
575
+ column: null
576
+ };
577
+ stackFrames.push(stackFrame);
578
+ continue;
579
+ }
569
580
  const line = callSite.getLineNumber();
570
581
  const column = callSite.getColumnNumber();
571
582
  const site = resolveUrlSite({
@@ -454,6 +454,38 @@ isBrowser ? () => {
454
454
  throw new Error('`process.cwd()` only works in Node.js, not the browser.');
455
455
  } : process$1.cwd;
456
456
 
457
+ // normalize url search params:
458
+ // Using URLSearchParams to alter the url search params
459
+ // can result into "file:///file.css?css_module"
460
+ // becoming "file:///file.css?css_module="
461
+ // we want to get rid of the "=" and consider it's the same url
462
+ const normalizeUrl = url => {
463
+ if (url.includes("?")) {
464
+ // disable on data urls (would mess up base64 encoding)
465
+ if (url.startsWith("data:")) {
466
+ return url;
467
+ }
468
+ return url.replace(/[=](?=&|$)/g, "");
469
+ }
470
+ return url;
471
+ };
472
+ const injectQueryParams = (url, params) => {
473
+ const urlObject = new URL(url);
474
+ const {
475
+ searchParams
476
+ } = urlObject;
477
+ Object.keys(params).forEach(key => {
478
+ const value = params[key];
479
+ if (value === undefined) {
480
+ searchParams.delete(key);
481
+ } else {
482
+ searchParams.set(key, value);
483
+ }
484
+ });
485
+ const urlWithParams = urlObject.href;
486
+ return normalizeUrl(urlWithParams);
487
+ };
488
+
457
489
  const getCommonPathname = (pathname, otherPathname) => {
458
490
  if (pathname === otherPathname) {
459
491
  return pathname;
@@ -1199,7 +1231,9 @@ const jsenvPluginSupervisor = ({
1199
1231
  const resolveUrlSite = urlWithLineAndColumn => {
1200
1232
  const inlineUrlMatch = urlWithLineAndColumn.match(/@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/);
1201
1233
  if (inlineUrlMatch) {
1202
- const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
1234
+ const htmlUrl = injectQueryParams(urlWithLineAndColumn.slice(0, inlineUrlMatch.index), {
1235
+ hot: undefined
1236
+ });
1203
1237
  const tagLineStart = parseInt(inlineUrlMatch[1]);
1204
1238
  const tagColumnStart = parseInt(inlineUrlMatch[2]);
1205
1239
  // const tagLineEnd = parseInt(inlineUrlMatch[3]);
@@ -1220,7 +1254,9 @@ const jsenvPluginSupervisor = ({
1220
1254
  if (!match) {
1221
1255
  return null;
1222
1256
  }
1223
- const file = urlWithLineAndColumn.slice(0, match.index);
1257
+ const file = injectQueryParams(urlWithLineAndColumn.slice(0, match.index), {
1258
+ hot: undefined
1259
+ });
1224
1260
  let line = parseInt(match[1]);
1225
1261
  let column = parseInt(match[2]);
1226
1262
  return {
@@ -1260,6 +1296,9 @@ const jsenvPluginSupervisor = ({
1260
1296
  }
1261
1297
  };
1262
1298
  }
1299
+ if (!urlInfo.originalContent) {
1300
+ await urlInfo.fetchContent();
1301
+ }
1263
1302
  const remap = searchParams.has("remap");
1264
1303
  if (remap) {
1265
1304
  const sourcemap = urlInfo.sourcemap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.5.25",
3
+ "version": "1.5.27",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -528,6 +528,17 @@ window.__supervisor__ = (() => {
528
528
  for (const callSite of callSites) {
529
529
  const url =
530
530
  callSite.getFileName() || callSite.getScriptNameOrSourceURL();
531
+ if (!url) {
532
+ // thinks like Array.forEach can generate this
533
+ const stackFrame = {
534
+ raw: ` at ${String(callSite)}`,
535
+ url: null,
536
+ line: null,
537
+ column: null,
538
+ };
539
+ stackFrames.push(stackFrame);
540
+ continue;
541
+ }
531
542
  const line = callSite.getLineNumber();
532
543
  const column = callSite.getColumnNumber();
533
544
  const site = resolveUrlSite({ url, line, column });
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { generateContentFrame } from "@jsenv/humanize";
7
7
  import { getOriginalPosition } from "@jsenv/sourcemap";
8
+ import { injectQueryParams } from "@jsenv/urls";
8
9
  import { createRequire } from "node:module";
9
10
  import { fileURLToPath } from "node:url";
10
11
  import {
@@ -24,7 +25,10 @@ export const jsenvPluginSupervisor = ({
24
25
  /@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/,
25
26
  );
26
27
  if (inlineUrlMatch) {
27
- const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
28
+ const htmlUrl = injectQueryParams(
29
+ urlWithLineAndColumn.slice(0, inlineUrlMatch.index),
30
+ { hot: undefined },
31
+ );
28
32
  const tagLineStart = parseInt(inlineUrlMatch[1]);
29
33
  const tagColumnStart = parseInt(inlineUrlMatch[2]);
30
34
  // const tagLineEnd = parseInt(inlineUrlMatch[3]);
@@ -52,7 +56,9 @@ export const jsenvPluginSupervisor = ({
52
56
  if (!match) {
53
57
  return null;
54
58
  }
55
- const file = urlWithLineAndColumn.slice(0, match.index);
59
+ const file = injectQueryParams(urlWithLineAndColumn.slice(0, match.index), {
60
+ hot: undefined,
61
+ });
56
62
  let line = parseInt(match[1]);
57
63
  let column = parseInt(match[2]);
58
64
  return {
@@ -88,6 +94,9 @@ export const jsenvPluginSupervisor = ({
88
94
  },
89
95
  };
90
96
  }
97
+ if (!urlInfo.originalContent) {
98
+ await urlInfo.fetchContent();
99
+ }
91
100
  const remap = searchParams.has("remap");
92
101
  if (remap) {
93
102
  const sourcemap = urlInfo.sourcemap;