unpeek 4.0.1 → 4.1.0

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.
Files changed (62) hide show
  1. package/README.md +17 -9
  2. package/README.tr.md +17 -9
  3. package/dist/adapters/esbuild.cjs +5 -5
  4. package/dist/adapters/esbuild.d.cts +1 -1
  5. package/dist/adapters/esbuild.d.ts +1 -1
  6. package/dist/adapters/esbuild.js +3 -3
  7. package/dist/adapters/next/adapter.cjs +6 -6
  8. package/dist/adapters/next/adapter.d.cts +1 -1
  9. package/dist/adapters/next/adapter.d.ts +1 -1
  10. package/dist/adapters/next/adapter.js +5 -5
  11. package/dist/adapters/next/index.cjs +6 -6
  12. package/dist/adapters/next/index.js +5 -5
  13. package/dist/adapters/rollup.cjs +5 -5
  14. package/dist/adapters/rollup.d.cts +1 -1
  15. package/dist/adapters/rollup.d.ts +1 -1
  16. package/dist/adapters/rollup.js +3 -3
  17. package/dist/adapters/rspack.cjs +5 -5
  18. package/dist/adapters/rspack.d.cts +1 -1
  19. package/dist/adapters/rspack.d.ts +1 -1
  20. package/dist/adapters/rspack.js +3 -3
  21. package/dist/adapters/vite.cjs +5 -5
  22. package/dist/adapters/vite.d.cts +1 -1
  23. package/dist/adapters/vite.d.ts +1 -1
  24. package/dist/adapters/vite.js +3 -3
  25. package/dist/adapters/webpack.cjs +5 -5
  26. package/dist/adapters/webpack.d.cts +1 -1
  27. package/dist/adapters/webpack.d.ts +1 -1
  28. package/dist/adapters/webpack.js +3 -3
  29. package/dist/browser.cjs +2 -2
  30. package/dist/browser.d.cts +4 -4
  31. package/dist/browser.d.ts +4 -4
  32. package/dist/browser.js +1 -1
  33. package/dist/{chunk-TYL32LUK.js → chunk-32GLSJAW.js} +91 -569
  34. package/dist/{chunk-W77DAC3H.js → chunk-6EWFL4LQ.js} +16 -0
  35. package/dist/{chunk-LGTXAAZH.js → chunk-6KLUNEKE.js} +1939 -290
  36. package/dist/{chunk-3GDHYBVH.cjs → chunk-AD6UFBPA.cjs} +96 -574
  37. package/dist/{chunk-X6EETCO6.cjs → chunk-BQ2O6HM5.cjs} +16 -0
  38. package/dist/{chunk-NNAAPDUS.cjs → chunk-FLZ4FSP5.cjs} +8 -8
  39. package/dist/{chunk-4SOS3LRV.js → chunk-HV47WJIR.js} +6 -6
  40. package/dist/{chunk-OTA75YI6.cjs → chunk-Q4DFRMAV.cjs} +53 -36
  41. package/dist/{chunk-XYN5NYSD.js → chunk-STTUFUDC.js} +21 -15
  42. package/dist/{chunk-4G2HCME5.js → chunk-TOUYQ4N5.js} +30 -13
  43. package/dist/{chunk-M46SFJE7.cjs → chunk-VLL4THTG.cjs} +2137 -488
  44. package/dist/{chunk-7ZEVJ4OR.cjs → chunk-WYW5UOBE.cjs} +40 -34
  45. package/dist/cli/index.js +1399 -280
  46. package/dist/{config-Y6JwVGwX.d.cts → config-BFAZrfjQ.d.cts} +2 -0
  47. package/dist/{config-Y6JwVGwX.d.ts → config-BFAZrfjQ.d.ts} +2 -0
  48. package/dist/config.cjs +2 -2
  49. package/dist/config.d.cts +1 -1
  50. package/dist/config.d.ts +1 -1
  51. package/dist/config.js +1 -1
  52. package/dist/{index-COVHErnx.d.cts → index-Bo4S_VVM.d.cts} +1 -1
  53. package/dist/{index-0O1WSfVP.d.ts → index-CKdYVt_L.d.ts} +1 -1
  54. package/dist/index.cjs +21 -21
  55. package/dist/index.d.cts +6 -6
  56. package/dist/index.d.ts +6 -6
  57. package/dist/index.js +8 -8
  58. package/dist/plugins/unplugin.cjs +4 -4
  59. package/dist/plugins/unplugin.js +3 -3
  60. package/dist/{types-CMtZnV8C.d.ts → types-BZqvBhBI.d.ts} +4 -2
  61. package/dist/{types-D93PuOOl.d.cts → types-E4ugA4Oz.d.cts} +4 -2
  62. package/package.json +1 -1
@@ -229,6 +229,84 @@ function detectTargetFramework(cwd, explicitOutDir, explicitConfig) {
229
229
  }
230
230
  return { framework, outDir };
231
231
  }
232
+ function globBodyToRegex(pat) {
233
+ let out = "";
234
+ let i = 0;
235
+ while (i < pat.length) {
236
+ const ch = pat[i];
237
+ if (ch === "/" && pat.slice(i, i + 4) === "/**/") {
238
+ out += "(?:/.+/|/)";
239
+ i += 4;
240
+ continue;
241
+ }
242
+ if (ch === "/" && pat.slice(i) === "/**") {
243
+ out += "/.*";
244
+ i = pat.length;
245
+ continue;
246
+ }
247
+ if (ch === "*" && pat[i + 1] === "*") {
248
+ if ((i === 0 || pat[i - 1] === "/") && pat[i + 2] === "/") {
249
+ out += "(?:.*/)?";
250
+ i += 3;
251
+ } else {
252
+ out += ".*";
253
+ i += 2;
254
+ }
255
+ continue;
256
+ }
257
+ if (ch === "*") {
258
+ out += "[^/]*";
259
+ i += 1;
260
+ continue;
261
+ }
262
+ if (ch === "?") {
263
+ out += "[^/]";
264
+ i += 1;
265
+ continue;
266
+ }
267
+ if (ch === "{") {
268
+ let depth = 1;
269
+ let j = i + 1;
270
+ const alts = [];
271
+ let segStart = j;
272
+ while (j < pat.length && depth > 0) {
273
+ if (pat[j] === "{") depth++;
274
+ else if (pat[j] === "}") {
275
+ depth--;
276
+ if (depth === 0) {
277
+ alts.push(pat.slice(segStart, j));
278
+ break;
279
+ }
280
+ } else if (pat[j] === "," && depth === 1) {
281
+ alts.push(pat.slice(segStart, j));
282
+ segStart = j + 1;
283
+ }
284
+ j++;
285
+ }
286
+ if (depth === 0 && alts.length > 0) {
287
+ out += `(?:${alts.map(globBodyToRegex).join("|")})`;
288
+ i = j + 1;
289
+ continue;
290
+ }
291
+ }
292
+ out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
293
+ i += 1;
294
+ }
295
+ return out;
296
+ }
297
+ function matchesGlobPattern(relPath, pattern) {
298
+ const normPattern = pattern.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "").trim();
299
+ if (!normPattern) return false;
300
+ const normPath = relPath.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\/+/, "");
301
+ const regex = new RegExp(`^${globBodyToRegex(normPattern)}$`);
302
+ if (regex.test(normPath)) {
303
+ return true;
304
+ }
305
+ if (!normPattern.includes("/")) {
306
+ return regex.test(path.posix.basename(normPath));
307
+ }
308
+ return false;
309
+ }
232
310
  function scanClientBundles(outDir, config) {
233
311
  const resolvedOutDir = path.resolve(outDir);
234
312
  if (!fs.existsSync(resolvedOutDir)) {
@@ -275,6 +353,17 @@ function scanClientBundles(outDir, config) {
275
353
  if (config?.target !== "worker" && isWorkerOrServiceWorkerFile(fullPath, resolvedOutDir)) {
276
354
  continue;
277
355
  }
356
+ const relPath = path.relative(resolvedOutDir, fullPath).replace(/\\/g, "/");
357
+ if (config?.filter?.include && config.filter.include.length > 0) {
358
+ if (!config.filter.include.some((pattern) => matchesGlobPattern(relPath, pattern))) {
359
+ continue;
360
+ }
361
+ }
362
+ if (config?.filter?.exclude && config.filter.exclude.length > 0) {
363
+ if (config.filter.exclude.some((pattern) => matchesGlobPattern(relPath, pattern))) {
364
+ continue;
365
+ }
366
+ }
278
367
  results.push(fullPath);
279
368
  }
280
369
  }
@@ -508,572 +597,12 @@ function relocateSourceMaps(outDir, cwd, keepPrivateMaps = true, privateMapsDir
508
597
  };
509
598
  }
510
599
 
511
- // src/core/vlq.ts
512
- import crypto from "crypto";
513
- import fs3 from "fs";
514
- import path3 from "path";
515
- var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
516
- var BASE64_MAP = /* @__PURE__ */ new Map();
517
- for (let i = 0; i < BASE64_CHARS.length; i++) {
518
- BASE64_MAP.set(BASE64_CHARS[i], i);
519
- }
520
- var VLQ_BASE_SHIFT = 5;
521
- var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
522
- var VLQ_BASE_MASK = VLQ_BASE - 1;
523
- var VLQ_CONTINUATION_BIT = VLQ_BASE;
524
- function encodeVlq(value) {
525
- let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
526
- let encoded = "";
527
- do {
528
- let digit = vlq & VLQ_BASE_MASK;
529
- vlq >>>= VLQ_BASE_SHIFT;
530
- if (vlq > 0) {
531
- digit |= VLQ_CONTINUATION_BIT;
532
- }
533
- encoded += BASE64_CHARS[digit];
534
- } while (vlq > 0);
535
- return encoded;
536
- }
537
- function decodeVlq(segment, startIndex) {
538
- let result = 0;
539
- let shift = 0;
540
- let index = startIndex;
541
- while (index < segment.length) {
542
- const digit = BASE64_MAP.get(segment[index]);
543
- if (digit === void 0) {
544
- return null;
545
- }
546
- index++;
547
- const continuation = (digit & VLQ_CONTINUATION_BIT) !== 0;
548
- result += (digit & VLQ_BASE_MASK) << shift;
549
- shift += VLQ_BASE_SHIFT;
550
- if (!continuation) {
551
- const isNegative = (result & 1) === 1;
552
- const shifted = result >> 1;
553
- return {
554
- value: isNegative ? -shifted : shifted,
555
- nextIndex: index
556
- };
557
- }
558
- if (shift > 30) {
559
- return null;
560
- }
561
- }
562
- return null;
563
- }
564
- function decodeMappingsString(mappingsStr) {
565
- const mappings = [];
566
- let malformedCount = 0;
567
- if (!mappingsStr) {
568
- return { mappings, malformedCount };
569
- }
570
- let sourceIndex = 0;
571
- let originalLine = 0;
572
- let originalColumn = 0;
573
- let nameIndex = 0;
574
- const lines = mappingsStr.split(";");
575
- for (let genLine = 0; genLine < lines.length; genLine++) {
576
- const lineStr = lines[genLine];
577
- if (!lineStr) continue;
578
- let genCol = 0;
579
- const segments = lineStr.split(",");
580
- for (const seg of segments) {
581
- if (!seg) continue;
582
- const values = [];
583
- let idx = 0;
584
- let valid = true;
585
- while (idx < seg.length) {
586
- const decoded = decodeVlq(seg, idx);
587
- if (!decoded) {
588
- valid = false;
589
- break;
590
- }
591
- values.push(decoded.value);
592
- idx = decoded.nextIndex;
593
- }
594
- if (!valid || values.length !== 1 && values.length !== 4 && values.length !== 5) {
595
- malformedCount++;
596
- continue;
597
- }
598
- genCol += values[0];
599
- if (values.length >= 4) {
600
- sourceIndex += values[1];
601
- originalLine += values[2];
602
- originalColumn += values[3];
603
- const mapping = {
604
- generatedLine: genLine,
605
- generatedColumn: genCol,
606
- sourceIndex,
607
- originalLine,
608
- originalColumn
609
- };
610
- if (values.length === 5) {
611
- nameIndex += values[4];
612
- mapping.nameIndex = nameIndex;
613
- }
614
- mappings.push(mapping);
615
- }
616
- }
617
- }
618
- return { mappings, malformedCount };
619
- }
620
- function resolveSourceWithRoot(rawSource, sourceRoot) {
621
- if (!sourceRoot || !rawSource || rawSource.startsWith(sourceRoot)) {
622
- return rawSource;
623
- }
624
- return `${sourceRoot.replace(/\/$/, "")}/${rawSource.replace(/^\//, "")}`;
625
- }
626
- function flattenSourceMapSectionsWithStats(rawMap) {
627
- if (!Array.isArray(rawMap.sections)) {
628
- const normalized = {
629
- version: rawMap.version ?? 3,
630
- sources: Array.isArray(rawMap.sources) ? [...rawMap.sources] : [],
631
- names: Array.isArray(rawMap.names) ? [...rawMap.names] : [],
632
- mappings: typeof rawMap.mappings === "string" ? rawMap.mappings : ""
633
- };
634
- if (rawMap.file !== void 0) normalized.file = rawMap.file;
635
- if (rawMap.sourceRoot !== void 0) normalized.sourceRoot = rawMap.sourceRoot;
636
- if (Array.isArray(rawMap.sourcesContent)) {
637
- normalized.sourcesContent = [...rawMap.sourcesContent];
638
- }
639
- const debugId2 = rawMap.debugId ?? rawMap.debug_id;
640
- if (debugId2) normalized.debugId = debugId2;
641
- return { map: normalized, malformedCount: 0 };
642
- }
643
- const mergedSources = [];
644
- const mergedSourcesContent = [];
645
- let hasAnySourcesContent = false;
646
- const sourceIndexMap = /* @__PURE__ */ new Map();
647
- const mergedNames = [];
648
- const nameIndexMap = /* @__PURE__ */ new Map();
649
- const mergedMappings = [];
650
- let totalMalformed = 0;
651
- const internSource = (src, content) => {
652
- const existing = sourceIndexMap.get(src);
653
- if (existing !== void 0) {
654
- if (mergedSourcesContent[existing] === null && content !== void 0 && content !== null) {
655
- mergedSourcesContent[existing] = content;
656
- hasAnySourcesContent = true;
657
- }
658
- return existing;
659
- }
660
- const nextIdx = mergedSources.length;
661
- mergedSources.push(src);
662
- if (content !== void 0 && content !== null) {
663
- hasAnySourcesContent = true;
664
- }
665
- mergedSourcesContent.push(content ?? null);
666
- sourceIndexMap.set(src, nextIdx);
667
- return nextIdx;
668
- };
669
- const internName = (name) => {
670
- const existing = nameIndexMap.get(name);
671
- if (existing !== void 0) return existing;
672
- const nextIdx = mergedNames.length;
673
- mergedNames.push(name);
674
- nameIndexMap.set(name, nextIdx);
675
- return nextIdx;
676
- };
677
- for (const section of rawMap.sections) {
678
- if (!section || !section.map) continue;
679
- const offLine = (section.offset?.line ?? 0) | 0;
680
- const offCol = (section.offset?.column ?? 0) | 0;
681
- const flatSecResult = flattenSourceMapSectionsWithStats(section.map);
682
- const flatSec = flatSecResult.map;
683
- totalMalformed += flatSecResult.malformedCount;
684
- const decoded = decodeMappingsString(flatSec.mappings);
685
- totalMalformed += decoded.malformedCount;
686
- const secSources = flatSec.sources ?? [];
687
- const secContents = flatSec.sourcesContent ?? [];
688
- const secNames = flatSec.names ?? [];
689
- const sourceRemap = /* @__PURE__ */ new Map();
690
- for (let i = 0; i < secSources.length; i++) {
691
- const fullSource = resolveSourceWithRoot(secSources[i], flatSec.sourceRoot);
692
- sourceRemap.set(i, internSource(fullSource, secContents[i]));
693
- }
694
- const nameRemap = /* @__PURE__ */ new Map();
695
- for (let i = 0; i < secNames.length; i++) {
696
- nameRemap.set(i, internName(secNames[i]));
697
- }
698
- for (const m of decoded.mappings) {
699
- const mappedSource = sourceRemap.get(m.sourceIndex);
700
- if (mappedSource === void 0) continue;
701
- const shifted = {
702
- generatedLine: offLine + m.generatedLine,
703
- generatedColumn: (m.generatedLine === 0 ? offCol : 0) + m.generatedColumn,
704
- sourceIndex: mappedSource,
705
- originalLine: m.originalLine,
706
- originalColumn: m.originalColumn
707
- };
708
- if (m.nameIndex !== void 0) {
709
- const mappedName = nameRemap.get(m.nameIndex);
710
- if (mappedName !== void 0) {
711
- shifted.nameIndex = mappedName;
712
- }
713
- }
714
- mergedMappings.push(shifted);
715
- }
716
- }
717
- mergedMappings.sort(
718
- (a, b) => a.generatedLine !== b.generatedLine ? a.generatedLine - b.generatedLine : a.generatedColumn - b.generatedColumn
719
- );
720
- const flat = {
721
- version: rawMap.version ?? 3,
722
- sources: mergedSources,
723
- names: mergedNames,
724
- mappings: encodeMappings(mergedMappings)
725
- };
726
- if (rawMap.file !== void 0) flat.file = rawMap.file;
727
- if (rawMap.sourceRoot !== void 0) flat.sourceRoot = rawMap.sourceRoot;
728
- if (hasAnySourcesContent) flat.sourcesContent = mergedSourcesContent;
729
- const debugId = rawMap.debugId ?? rawMap.debug_id;
730
- if (debugId) flat.debugId = debugId;
731
- return { map: flat, malformedCount: totalMalformed };
732
- }
733
- function flattenSourceMapSections(rawMap) {
734
- return flattenSourceMapSectionsWithStats(rawMap).map;
735
- }
736
- function encodeMappings(decoded) {
737
- if (decoded.length === 0) return "";
738
- const sorted = [...decoded].sort(
739
- (a, b) => a.generatedLine !== b.generatedLine ? a.generatedLine - b.generatedLine : a.generatedColumn - b.generatedColumn
740
- );
741
- const maxLine = sorted[sorted.length - 1].generatedLine;
742
- const lineBuckets = Array.from({ length: maxLine + 1 }, () => []);
743
- let prevSource = 0;
744
- let prevOrigLine = 0;
745
- let prevOrigCol = 0;
746
- let prevName = 0;
747
- let prevGenLine = -1;
748
- let prevGenCol = 0;
749
- for (const m of sorted) {
750
- if (m.generatedLine !== prevGenLine) {
751
- prevGenLine = m.generatedLine;
752
- prevGenCol = 0;
753
- }
754
- let seg = encodeVlq(m.generatedColumn - prevGenCol) + encodeVlq(m.sourceIndex - prevSource) + encodeVlq(m.originalLine - prevOrigLine) + encodeVlq(m.originalColumn - prevOrigCol);
755
- prevGenCol = m.generatedColumn;
756
- prevSource = m.sourceIndex;
757
- prevOrigLine = m.originalLine;
758
- prevOrigCol = m.originalColumn;
759
- if (m.nameIndex !== void 0) {
760
- seg += encodeVlq(m.nameIndex - prevName);
761
- prevName = m.nameIndex;
762
- }
763
- lineBuckets[m.generatedLine].push(seg);
764
- }
765
- return lineBuckets.map((segs) => segs.join(",")).join(";");
766
- }
767
- function ensureSortedMappings(mappings) {
768
- for (let i = 1; i < mappings.length; i++) {
769
- const prev = mappings[i - 1];
770
- const curr = mappings[i];
771
- if (curr.generatedLine < prev.generatedLine || curr.generatedLine === prev.generatedLine && curr.generatedColumn < prev.generatedColumn) {
772
- return [...mappings].sort(
773
- (a, b) => a.generatedLine !== b.generatedLine ? a.generatedLine - b.generatedLine : a.generatedColumn - b.generatedColumn
774
- );
775
- }
776
- }
777
- return mappings;
778
- }
779
- function findMappingAt(mappings, line0, col0) {
780
- let lo = 0;
781
- let hi = mappings.length - 1;
782
- let best;
783
- while (lo <= hi) {
784
- const mid = lo + hi >> 1;
785
- const m = mappings[mid];
786
- if (m.generatedLine < line0 || m.generatedLine === line0 && m.generatedColumn <= col0) {
787
- if (m.generatedLine === line0) {
788
- best = m;
789
- }
790
- lo = mid + 1;
791
- } else {
792
- hi = mid - 1;
793
- }
794
- }
795
- return best;
796
- }
797
- function shiftSourceMapLines(map, lineOffset) {
798
- if (lineOffset <= 0 || !map.mappings) {
799
- return map;
800
- }
801
- return {
802
- ...map,
803
- mappings: `${";".repeat(lineOffset)}${map.mappings}`
804
- };
805
- }
806
- function computeDeterministicDebugId(code, mappings = "") {
807
- const hash = crypto.createHash("sha256").update(code, "utf8");
808
- if (mappings) {
809
- hash.update("\0", "utf8").update(mappings, "utf8");
810
- }
811
- const bytes = hash.digest();
812
- bytes[6] = bytes[6] & 15 | 64;
813
- bytes[8] = bytes[8] & 63 | 128;
814
- const hex = bytes.subarray(0, 16).toString("hex");
815
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
816
- }
817
- function chainSourceMaps(mapB, mapA) {
818
- const flatB = flattenSourceMapSections(mapB);
819
- const flatA = flattenSourceMapSections(mapA);
820
- const decodedB = ensureSortedMappings(decodeMappingsString(flatB.mappings).mappings);
821
- const decodedA = ensureSortedMappings(decodeMappingsString(flatA.mappings).mappings);
822
- const chained = [];
823
- for (const mB of decodedB) {
824
- const mA = findMappingAt(decodedA, mB.originalLine, mB.originalColumn);
825
- if (mA) {
826
- chained.push({
827
- generatedLine: mB.generatedLine,
828
- generatedColumn: mB.generatedColumn,
829
- sourceIndex: mA.sourceIndex,
830
- originalLine: mA.originalLine,
831
- originalColumn: mA.originalColumn,
832
- nameIndex: mA.nameIndex
833
- });
834
- }
835
- }
836
- const debugId = flatA.debugId ?? flatA.debug_id ?? flatB.debugId ?? flatB.debug_id;
837
- const result = {
838
- version: 3,
839
- file: flatB.file ?? flatA.file,
840
- sourceRoot: flatA.sourceRoot,
841
- sources: [...flatA.sources],
842
- sourcesContent: flatA.sourcesContent ? [...flatA.sourcesContent] : void 0,
843
- names: [...flatA.names],
844
- mappings: encodeMappings(chained)
845
- };
846
- if (debugId) {
847
- result.debugId = debugId;
848
- }
849
- return result;
850
- }
851
- function resolvePosition(map, line1Based, column1Based) {
852
- const { map: flatMap, malformedCount: flattenMalformed } = flattenSourceMapSectionsWithStats(map);
853
- const { mappings, malformedCount: decodeMalformed } = decodeMappingsString(flatMap.mappings);
854
- const malformedCount = flattenMalformed + decodeMalformed;
855
- const sortedMappings = ensureSortedMappings(mappings);
856
- const match = findMappingAt(
857
- sortedMappings,
858
- Math.max(0, line1Based - 1),
859
- Math.max(0, column1Based - 1)
860
- );
861
- if (!match) {
862
- return { malformedCount };
863
- }
864
- const rawSource = flatMap.sources[match.sourceIndex];
865
- const source = resolveSourceWithRoot(rawSource, flatMap.sourceRoot);
866
- return {
867
- source,
868
- line: match.originalLine + 1,
869
- column: match.originalColumn + 1,
870
- name: match.nameIndex !== void 0 ? flatMap.names[match.nameIndex] : void 0,
871
- malformedCount
872
- };
873
- }
874
- function safeDecodeURIComponent(input) {
875
- try {
876
- return decodeURIComponent(input);
877
- } catch {
878
- return input.replace(/%[0-9A-Fa-f]{2}/g, (seq) => {
879
- try {
880
- return decodeURIComponent(seq);
881
- } catch {
882
- return seq;
883
- }
884
- });
885
- }
886
- }
887
- function collectMapFiles(mapsDir) {
888
- if (!fs3.existsSync(mapsDir)) return [];
889
- const results = [];
890
- const walk = (dir) => {
891
- let entries;
892
- try {
893
- entries = fs3.readdirSync(dir, { withFileTypes: true });
894
- } catch {
895
- return;
896
- }
897
- for (const entry of entries) {
898
- const fullPath = path3.join(dir, entry.name);
899
- if (entry.isDirectory()) {
900
- walk(fullPath);
901
- } else if (entry.isFile() && entry.name.endsWith(".map")) {
902
- results.push(fullPath);
903
- }
904
- }
905
- };
906
- walk(mapsDir);
907
- return results;
908
- }
909
- function normalizeFileRefCandidates(fileRef) {
910
- let cleanRef = fileRef.trim();
911
- try {
912
- if (/^(?:https?|file):\/\//i.test(cleanRef)) {
913
- cleanRef = new URL(cleanRef).pathname;
914
- }
915
- } catch {
916
- }
917
- cleanRef = cleanRef.split("?")[0].split("#")[0].replace(/\\/g, "/");
918
- cleanRef = cleanRef.replace(/^\/+([A-Za-z]:\/)/, "$1").replace(/^\/+/, "");
919
- const decodedRef = safeDecodeURIComponent(cleanRef).replace(/\\/g, "/").replace(/^\/+/, "");
920
- const variants = /* @__PURE__ */ new Set();
921
- for (const raw of [decodedRef, cleanRef]) {
922
- if (!raw) continue;
923
- variants.add(raw);
924
- const withoutDrive = raw.replace(/^[A-Za-z]:\//, "");
925
- variants.add(withoutDrive);
926
- for (const v of [raw, withoutDrive]) {
927
- const nextStripped = v.replace(
928
- /^(?:.*\/)?(?:_next\/static\/chunks\/|_next\/static\/|_next\/|static\/chunks\/|static\/)/,
929
- ""
930
- );
931
- if (nextStripped) variants.add(nextStripped);
932
- const chunksIdx = v.indexOf("/chunks/");
933
- if (chunksIdx !== -1) {
934
- variants.add(v.slice(chunksIdx + "/chunks/".length));
935
- }
936
- }
937
- }
938
- return Array.from(variants).filter(Boolean);
939
- }
940
- function findMatchingMapFile(fileRef, mapsDir, allMaps) {
941
- const candidates = normalizeFileRefCandidates(fileRef);
942
- for (const cand of candidates) {
943
- const exactCandidate = path3.join(mapsDir, `${cand}.map`);
944
- if (fs3.existsSync(exactCandidate)) {
945
- return exactCandidate;
946
- }
947
- }
948
- for (const mapPath of allMaps) {
949
- const relRaw = path3.relative(mapsDir, mapPath).replace(/\\/g, "/");
950
- const relDecoded = safeDecodeURIComponent(relRaw);
951
- for (const rel of [relDecoded, relRaw]) {
952
- const relNoMap = rel.slice(0, -4);
953
- for (const cand of candidates) {
954
- if (rel === `${cand}.map` || rel.endsWith(`/${cand}.map`) || cand.endsWith(`/${relNoMap}`) || cand === relNoMap) {
955
- return mapPath;
956
- }
957
- }
958
- }
959
- }
960
- const baseNames = new Set(candidates.map((c) => `${path3.posix.basename(c)}.map`));
961
- return allMaps.find((m) => {
962
- const base = path3.basename(m);
963
- return baseNames.has(base) || baseNames.has(safeDecodeURIComponent(base));
964
- });
965
- }
966
- var V8_PARENS_FRAME_REGEX = /^\s*at\s+(?:.+?\s+\()(.+):(\d+):(\d+)\)\s*$/;
967
- var V8_BARE_FRAME_REGEX = /^\s*at\s+(.+?):(\d+):(\d+)\s*$/;
968
- var FIREFOX_FRAME_REGEX = /^[^@]*@(.+?):(\d+):(\d+)\s*$/;
969
- var STACK_FRAME_REGEX = /(?:at\s+(?:[^(]+\s+\()?|\@)([^\s()]+?):(\d+):(\d+)\)?/;
970
- function parseStackFrame(rawLine) {
971
- const match = rawLine.match(V8_PARENS_FRAME_REGEX) ?? rawLine.match(V8_BARE_FRAME_REGEX) ?? rawLine.match(FIREFOX_FRAME_REGEX) ?? rawLine.match(STACK_FRAME_REGEX);
972
- if (!match) {
973
- return null;
974
- }
975
- return {
976
- fileRef: match[1],
977
- lineNum: Number(match[2]),
978
- colNum: Number(match[3])
979
- };
980
- }
981
- async function symbolicateStackTrace(options) {
982
- const cwd = path3.resolve(options.cwd ?? process.cwd());
983
- const mapsDir = path3.resolve(cwd, options.mapsDir ?? ".unpeek-maps");
984
- const allMaps = collectMapFiles(mapsDir);
985
- const warnings = [];
986
- const mapCache = /* @__PURE__ */ new Map();
987
- if (allMaps.length === 0) {
988
- warnings.push(`No .map files found in "${mapsDir}".`);
989
- }
990
- const lines = options.stackTrace.split(/\r?\n/);
991
- const frames = [];
992
- const outputLines = [];
993
- for (const rawLine of lines) {
994
- const parsedFrame = parseStackFrame(rawLine);
995
- if (!parsedFrame) {
996
- frames.push({ raw: rawLine, resolved: false });
997
- outputLines.push(rawLine);
998
- continue;
999
- }
1000
- const { fileRef, lineNum, colNum } = parsedFrame;
1001
- const normalizedFrameFile = safeDecodeURIComponent(fileRef).replace(/\\/g, "/");
1002
- const mapPath = findMatchingMapFile(fileRef, mapsDir, allMaps);
1003
- if (!mapPath) {
1004
- frames.push({
1005
- raw: rawLine,
1006
- file: normalizedFrameFile,
1007
- line: lineNum,
1008
- column: colNum,
1009
- resolved: false
1010
- });
1011
- outputLines.push(rawLine);
1012
- continue;
1013
- }
1014
- let parsedMap = mapCache.get(mapPath);
1015
- if (parsedMap === void 0) {
1016
- try {
1017
- const rawJson = JSON.parse(fs3.readFileSync(mapPath, "utf8"));
1018
- parsedMap = Array.isArray(rawJson?.sections) ? flattenSourceMapSections(rawJson) : rawJson;
1019
- } catch {
1020
- parsedMap = null;
1021
- warnings.push(`Failed to parse source map "${mapPath}".`);
1022
- }
1023
- mapCache.set(mapPath, parsedMap);
1024
- }
1025
- if (!parsedMap || typeof parsedMap.mappings !== "string" || !Array.isArray(parsedMap.sources)) {
1026
- frames.push({
1027
- raw: rawLine,
1028
- file: normalizedFrameFile,
1029
- line: lineNum,
1030
- column: colNum,
1031
- resolved: false
1032
- });
1033
- outputLines.push(rawLine);
1034
- continue;
1035
- }
1036
- const pos = resolvePosition(parsedMap, lineNum, colNum);
1037
- if (pos.malformedCount > 0) {
1038
- warnings.push(`Skipped ${pos.malformedCount} malformed VLQ segment(s) in "${path3.basename(mapPath)}".`);
1039
- }
1040
- if (!pos.source || pos.line === void 0 || pos.column === void 0) {
1041
- frames.push({
1042
- raw: rawLine,
1043
- file: normalizedFrameFile,
1044
- line: lineNum,
1045
- column: colNum,
1046
- resolved: false
1047
- });
1048
- outputLines.push(rawLine);
1049
- continue;
1050
- }
1051
- frames.push({
1052
- raw: rawLine,
1053
- file: normalizedFrameFile,
1054
- line: lineNum,
1055
- column: colNum,
1056
- originalSource: pos.source,
1057
- originalLine: pos.line,
1058
- originalColumn: pos.column,
1059
- originalName: pos.name,
1060
- resolved: true
1061
- });
1062
- const fnPrefix = pos.name ? `${pos.name} ` : "";
1063
- outputLines.push(` at ${fnPrefix}(${pos.source}:${pos.line}:${pos.column})`);
1064
- }
1065
- return {
1066
- stackTrace: outputLines.join("\n"),
1067
- frames,
1068
- warnings: Array.from(new Set(warnings))
1069
- };
1070
- }
1071
-
1072
600
  export {
1073
601
  isWorkerOrServiceWorkerFile,
1074
602
  hasNextServerSegment,
1075
603
  hasJsBundleFiles,
1076
604
  detectTargetFramework,
605
+ matchesGlobPattern,
1077
606
  scanClientBundles,
1078
607
  SOURCE_MAP_COMMENT_REGEX,
1079
608
  extractDebugId,
@@ -1081,12 +610,5 @@ export {
1081
610
  replaceOrAppendDebugId,
1082
611
  stripSourceMapComments,
1083
612
  findMonorepoRoots,
1084
- relocateSourceMaps,
1085
- flattenSourceMapSections,
1086
- shiftSourceMapLines,
1087
- computeDeterministicDebugId,
1088
- chainSourceMaps,
1089
- resolvePosition,
1090
- safeDecodeURIComponent,
1091
- symbolicateStackTrace
613
+ relocateSourceMaps
1092
614
  };