MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / normalizeSpec

Function normalizeSpec

packages/vite/hmr/client/utils.ts:295–331  ·  view source on GitHub ↗
(raw: string)

Source from the content-addressed store, hash-verified

293
294// Normalize import specifiers for HTTP-only ESM runtime
295export function normalizeSpec(raw: string): string {
296 if (typeof raw !== 'string') return raw as any;
297 let spec = raw.trim();
298 try {
299 // Expand HTTP origin placeholder emitted by server rewrites
300 if (spec.startsWith('/__NS_HTTP_ORIGIN__')) {
301 const origin = httpOriginForVite || deriveHttpOrigin(hmrWsUrl);
302 if (origin) return origin + spec.slice('__NS_HTTP_ORIGIN__'.length);
303 }
304 // If server emitted path-style endpoints inside modules, prefix with origin here
305 if (spec.startsWith('/ns/m') || spec.startsWith('/ns/sfc')) {
306 const origin = httpOriginForVite || deriveHttpOrigin(hmrWsUrl);
307 if (origin) return origin + spec;
308 }
309 } catch {}
310 // Strip query/hash (cache busters like ?t=, ?v= etc.)
311 const before = spec;
312 spec = spec.replace(/[?#].*$/, '');
313 if (spec !== before) {
314 try {
315 hmrMetrics.specQueryStripped = (hmrMetrics.specQueryStripped || 0) + 1;
316 } catch {}
317 }
318 if (spec.startsWith('@/')) {
319 // Generic alias '@/' -> project root relative; avoid assuming '/src/' structure
320 spec = '/' + spec.slice(2);
321 }
322 if (spec === '@') {
323 // Map anomalous '@' sentinel to a safe stub module path.
324 if (__NS_ENV_VERBOSE__) console.warn('[hmr-normalize] mapping anomalous "@" to stub module');
325 try {
326 hmrMetrics.invalidAtSpec = (hmrMetrics.invalidAtSpec || 0) + 1;
327 } catch {}
328 return '/__invalid_at__.mjs';
329 }
330 return spec;
331}
332
333export function attachDiagnosticsToFrame(frame: any) {
334 if (!__NS_ENV_VERBOSE__ || !frame) return;

Callers 4

applyDeltaFunction · 0.85
processQueueFunction · 0.85
index.tsFile · 0.85
addSfcMappingFunction · 0.85

Calls 4

deriveHttpOriginFunction · 0.85
replaceMethod · 0.80
warnMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected