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

Function stripToProjectRelative

packages/vite/hmr/server/websocket.ts:1007–1034  ·  view source on GitHub ↗
(importPath: string, projectRoot?: string)

Source from the content-addressed store, hash-verified

1005}
1006
1007function stripToProjectRelative(importPath: string, projectRoot?: string): string {
1008 if (!importPath) {
1009 return '';
1010 }
1011
1012 let normalized = importPath.replace(/\\/g, '/');
1013 normalized = normalized.replace(/^\/?@fs\//, '/');
1014 if (normalized.startsWith('file://')) {
1015 normalized = normalized.replace(/^file:\/\//, '/');
1016 }
1017
1018 const documentsMarker = '/Documents/';
1019 const documentsIndex = normalized.indexOf(documentsMarker);
1020 if (documentsIndex !== -1) {
1021 return normalized.substring(documentsIndex + documentsMarker.length);
1022 }
1023
1024 if (projectRoot) {
1025 const normalizedRoot = projectRoot.replace(/\\/g, '/').replace(/\/+$/, '');
1026 const rootIndex = normalized.indexOf(normalizedRoot);
1027 if (rootIndex !== -1) {
1028 const sliced = normalized.substring(rootIndex + normalizedRoot.length);
1029 return sliced.replace(/^\/+/, '');
1030 }
1031 }
1032
1033 return normalized.replace(/^\/+/, '');
1034}
1035
1036/**
1037 * Convert absolute application import to relative .mjs path for Documents folder

Callers 1

rewriteImportsFunction · 0.85

Calls 2

replaceMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected