MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / dumpDynImportDiagnostics

Function dumpDynImportDiagnostics

packages/vite/hmr/client/utils.ts:249–292  ·  view source on GitHub ↗
(spec: string, err: any)

Source from the content-addressed store, hash-verified

247}
248
249async function dumpDynImportDiagnostics(spec: string, err: any) {
250 try {
251 const origin = httpOriginForVite || deriveHttpOrigin(hmrWsUrl) || '';
252 const target = spec || '';
253 const { url: uFromStack, line, column } = parseStackFrame(err);
254 const url = uFromStack || target;
255 if (!/^https?:\/\//.test(url)) return;
256 const addParam = (u: string, k: string, v = '1') => u + (u.includes('?') ? '&' : '?') + `${k}=${v}`;
257 const urlsToTry = [url];
258 if (/(\/ns\/(asm|sfc))/.test(url)) urlsToTry.push(addParam(url, 'raw'));
259 const results: Array<{ which: string; text?: string; hash?: string }> = [];
260 for (const u of urlsToTry) {
261 try {
262 const res = await fetch(u as any, { method: 'GET' as any });
263 const text = await res.text();
264 const hash = res.headers?.get?.('X-NS-Source-Hash') || undefined;
265 results.push({ which: u === url ? 'sanitized' : 'raw', text, hash });
266 } catch {}
267 }
268 const locInfo = line && line > 0 ? ` at ${url}:${line}:${column || 0}` : '';
269 try {
270 console.warn('[hmr-client][dyn-import][diagnostics]', `error${locInfo}`);
271 } catch {}
272 for (const r of results) {
273 if (!r.text) continue;
274 const lines = r.text.split('\n');
275 let ctx = '';
276 if (line && line > 0) {
277 const start = Math.max(1, line - 3),
278 end = Math.min(lines.length, line + 3);
279 for (let i = start; i <= end; i++) {
280 const mark = i === line ? '>' : ' ';
281 const ln = String(i).padStart(4, ' ');
282 ctx += `${mark}${ln}: ${lines[i - 1]}\n`;
283 }
284 } else {
285 ctx = lines.slice(0, 20).join('\n');
286 }
287 try {
288 console.warn(`[hmr-client][dyn-import][${r.which}]`, r.hash ? `(hash ${r.hash})` : '', '\n' + ctx);
289 } catch {}
290 }
291 } catch {}
292}
293
294// Normalize import specifiers for HTTP-only ESM runtime
295export function normalizeSpec(raw: string): string {

Callers 1

safeDynImportFunction · 0.85

Calls 12

deriveHttpOriginFunction · 0.85
parseStackFrameFunction · 0.85
addParamFunction · 0.85
fetchFunction · 0.85
warnMethod · 0.80
joinMethod · 0.80
getMethod · 0.65
StringClass · 0.50
testMethod · 0.45
pushMethod · 0.45
textMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected