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

Function replaceVueImport

packages/vite/hmr/server/websocket.ts:1908–2058  ·  view source on GitHub ↗
(_match: string, prefix: string, spec: string, suffix: string)

Source from the content-addressed store, hash-verified

1906
1907 // Replacement function for all imports
1908 const replaceVueImport = (_match: string, prefix: string, spec: string, suffix: string): string => {
1909 // Safety check
1910 if (!spec || typeof spec !== 'string') {
1911 return `${prefix}${spec}${suffix}`;
1912 }
1913
1914 // Guard 0: leave fully-qualified HTTP(S) URLs alone
1915 if (/^https?:\/\//.test(spec)) {
1916 return `${prefix}${spec}${suffix}`;
1917 }
1918
1919 // Guard: anomalous bare '@' spec should be rewritten to a safe stub module.
1920 // This can surface from upstream alias mishaps; mapping it here avoids device-side
1921 // "instantiate failed @" errors.
1922 if (spec === '@') {
1923 const stub = `/ns/m/__invalid_at__.mjs`;
1924 if (verbose) {
1925 try {
1926 console.warn(`[rewrite] mapped bare '@' spec to stub: ${stub}`);
1927 } catch {}
1928 }
1929 return `${prefix}${stub}${suffix}`;
1930 }
1931
1932 spec = normalizeNativeScriptCoreSpecifier(spec);
1933
1934 // Route internal NS endpoints to absolute HTTP origin for device
1935 if (spec.startsWith('/ns/')) {
1936 if (httpOriginSafe) {
1937 return `${prefix}${httpOriginSafe}${spec}${suffix}`;
1938 }
1939 return `${prefix}${spec}${suffix}`;
1940 }
1941
1942 if (isNativeScriptCoreModule(spec)) {
1943 return `${prefix}${spec}${suffix}`;
1944 }
1945
1946 const nodeModulesSpecifier = normalizeNodeModulesSpecifier(spec);
1947 const candidateNativeScriptSpec = nodeModulesSpecifier ?? spec;
1948
1949 const vendorCanonical = resolveVendorFromCandidate(nodeModulesSpecifier ?? spec);
1950
1951 if (vendorCanonical) {
1952 if (nodeModulesSpecifier) {
1953 return `${prefix}${nodeModulesSpecifier.replace(PAT.QUERY_PATTERN, '')}${suffix}`;
1954 }
1955 return `${prefix}${spec.replace(PAT.QUERY_PATTERN, '')}${suffix}`;
1956 }
1957
1958 if (isNativeScriptPluginModule(candidateNativeScriptSpec)) {
1959 const bareSpecifier = candidateNativeScriptSpec.replace(PAT.QUERY_PATTERN, '');
1960 return `${prefix}${bareSpecifier}${suffix}`;
1961 }
1962
1963 if (nodeModulesSpecifier) {
1964 return `${prefix}${nodeModulesSpecifier}${suffix}`;
1965 }

Callers

nothing calls this directly

Calls 15

isNativeScriptCoreModuleFunction · 0.85
resolveVueKeyFunction · 0.85
ensureRelFunction · 0.85
normalizeImportPathFunction · 0.85
toAppModuleBaseIdFunction · 0.85
isApplicationImportFunction · 0.85
findDependencyFileNameFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected