MCPcopy
hub / github.com/zh-lx/code-inspector / getMappingFilePath

Function getMappingFilePath

packages/core/src/shared/utils.ts:203–238  ·  view source on GitHub ↗
(
  file: string,
  mappings?:
    | Record<string, string>
    | Array<{ find: string | RegExp; replacement: string }>,
)

Source from the content-addressed store, hash-verified

201 * ```
202 */
203export function getMappingFilePath(
204 file: string,
205 mappings?:
206 | Record<string, string>
207 | Array<{ find: string | RegExp; replacement: string }>,
208): string {
209 if (!mappings) {
210 return file;
211 }
212 if (Array.isArray(mappings)) {
213 for (let i = 0; i < mappings.length; i++) {
214 let find = mappings[i].find;
215 let replacement = mappings[i].replacement;
216 if (typeof find === 'string') {
217 const realFilePath = replaceFileWithString(file, find, replacement);
218 if (realFilePath) {
219 return realFilePath;
220 }
221 } else if (find instanceof RegExp) {
222 const realFilePath = replaceFileWithRegExp(file, find, replacement);
223 if (realFilePath) {
224 return realFilePath;
225 }
226 }
227 }
228 } else {
229 for (let find in mappings) {
230 const replacement = mappings[find];
231 const realFilePath = replaceFileWithString(file, find, replacement);
232 if (realFilePath) {
233 return realFilePath;
234 }
235 }
236 }
237 return file;
238}
239
240function replaceFileWithString(
241 file: string,

Callers 7

MakoCodeInspectorPluginFunction · 0.90
getNodeFilePathFunction · 0.90
setupFunction · 0.90
loadFunction · 0.90
transformFunction · 0.90
mappings.test.tsFile · 0.90

Calls 2

replaceFileWithStringFunction · 0.85
replaceFileWithRegExpFunction · 0.85

Tested by

no test coverage detected