@impakers/debug 1.3.11 → 1.3.13

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/react.js CHANGED
@@ -2121,30 +2121,58 @@ async function updateTaskStatus(endpoint, taskId, status) {
2121
2121
  var import_trace_mapping = require("@jridgewell/trace-mapping");
2122
2122
  var cache2 = /* @__PURE__ */ new Map();
2123
2123
  var failedUrls = /* @__PURE__ */ new Set();
2124
- function getSourceMapUrl(bundleUrl) {
2125
- if (bundleUrl.endsWith(".map")) return bundleUrl;
2126
- return `${bundleUrl}.map`;
2124
+ async function getSourceMapUrlFromBundle(bundleUrl) {
2125
+ try {
2126
+ const res = await fetch(bundleUrl, { cache: "force-cache" });
2127
+ if (!res.ok) return null;
2128
+ const text = await res.text();
2129
+ const match = text.match(/\/\/[#@]\s*sourceMappingURL\s*=\s*(\S+)\s*$/m);
2130
+ if (!match) return null;
2131
+ const mapRef = match[1];
2132
+ if (mapRef.startsWith("http")) return mapRef;
2133
+ const base = bundleUrl.substring(0, bundleUrl.lastIndexOf("/") + 1);
2134
+ return base + mapRef;
2135
+ } catch {
2136
+ return null;
2137
+ }
2127
2138
  }
2128
2139
  async function loadSourceMap(bundleUrl) {
2129
2140
  if (cache2.has(bundleUrl)) return cache2.get(bundleUrl) ?? null;
2130
2141
  if (failedUrls.has(bundleUrl)) return null;
2131
- const mapUrl = getSourceMapUrl(bundleUrl);
2142
+ const debugLog = typeof window !== "undefined" && window.__IMPAKERS_DEBUG_LOG;
2143
+ const directMapUrl = bundleUrl.endsWith(".map") ? bundleUrl : `${bundleUrl}.map`;
2132
2144
  try {
2133
- const res = await fetch(mapUrl, { cache: "force-cache" });
2134
- if (!res.ok) {
2135
- failedUrls.add(bundleUrl);
2136
- cache2.set(bundleUrl, null);
2137
- return null;
2145
+ const res = await fetch(directMapUrl, { cache: "force-cache" });
2146
+ if (debugLog) console.log("[impakers-debug] 1\uCC28 .map fetch:", res.status, directMapUrl);
2147
+ if (res.ok) {
2148
+ const rawMap = await res.json();
2149
+ const traceMap = new import_trace_mapping.AnyMap(rawMap);
2150
+ cache2.set(bundleUrl, traceMap);
2151
+ return traceMap;
2138
2152
  }
2139
- const rawMap = await res.json();
2140
- const traceMap = new import_trace_mapping.AnyMap(rawMap);
2141
- cache2.set(bundleUrl, traceMap);
2142
- return traceMap;
2143
- } catch {
2144
- failedUrls.add(bundleUrl);
2145
- cache2.set(bundleUrl, null);
2146
- return null;
2153
+ } catch (e) {
2154
+ if (debugLog) console.log("[impakers-debug] 1\uCC28 .map fetch exception:", e);
2147
2155
  }
2156
+ if (debugLog) console.log("[impakers-debug] 2\uCC28 \uC2DC\uB3C4: JS\uC5D0\uC11C sourceMappingURL \uCD94\uCD9C...");
2157
+ const actualMapUrl = await getSourceMapUrlFromBundle(bundleUrl);
2158
+ if (debugLog) console.log("[impakers-debug] 2\uCC28 actualMapUrl:", actualMapUrl);
2159
+ if (actualMapUrl) {
2160
+ try {
2161
+ const res = await fetch(actualMapUrl, { cache: "force-cache" });
2162
+ if (debugLog) console.log("[impakers-debug] 2\uCC28 .map fetch:", res.status, actualMapUrl);
2163
+ if (res.ok) {
2164
+ const rawMap = await res.json();
2165
+ const traceMap = new import_trace_mapping.AnyMap(rawMap);
2166
+ cache2.set(bundleUrl, traceMap);
2167
+ return traceMap;
2168
+ }
2169
+ } catch (e) {
2170
+ if (debugLog) console.log("[impakers-debug] 2\uCC28 .map fetch exception:", e);
2171
+ }
2172
+ }
2173
+ failedUrls.add(bundleUrl);
2174
+ cache2.set(bundleUrl, null);
2175
+ return null;
2148
2176
  }
2149
2177
  async function resolveSourcePosition(bundlePath, line, column) {
2150
2178
  let bundleUrl;