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

Function safeDynImport

packages/vite/hmr/client/utils.ts:199–225  ·  view source on GitHub ↗
(spec: string)

Source from the content-addressed store, hash-verified

197
198// Centralized safe dynamic import wrapper to guard anomalous specifiers
199export async function safeDynImport(spec: string): Promise<any> {
200 try {
201 const origin = httpOriginForVite || deriveHttpOrigin(hmrWsUrl);
202 let finalSpec = spec;
203 if (!finalSpec || finalSpec === '@') {
204 finalSpec = (origin ? origin : '') + '/ns/m/__invalid_at__.mjs';
205 }
206 if (__NS_ENV_VERBOSE__) {
207 try {
208 console.log('[hmr-client][dyn-import]', 'spec=', spec, 'final=', finalSpec);
209 } catch {}
210 }
211 // Use native dynamic import
212 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
213 // @ts-ignore - dynamic import expression
214 return await import(finalSpec);
215 } catch (e) {
216 if (__NS_ENV_VERBOSE__) {
217 console.warn('[hmr-client][dyn-import][error]', spec, e);
218 }
219 // Best-effort diagnostics: fetch sanitized and raw sources and print a snippet around the failing frame
220 try {
221 await dumpDynImportDiagnostics(spec, e as any);
222 } catch {}
223 throw e;
224 }
225}
226
227// Extract a (url, line, column) triple from a V8 stack string
228function parseStackFrame(err: any): {

Callers 2

syncPiniaAcrossEsmFunction · 0.85
loadSfcComponentFunction · 0.85

Calls 4

deriveHttpOriginFunction · 0.85
dumpDynImportDiagnosticsFunction · 0.85
warnMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected