MCPcopy Index your code
hub / github.com/zh-lx/code-inspector / replaceFileWithString

Function replaceFileWithString

packages/core/src/shared/utils.ts:240–263  ·  view source on GitHub ↗
(
  file: string,
  find: string,
  replacement: string,
)

Source from the content-addressed store, hash-verified

238}
239
240function replaceFileWithString(
241 file: string,
242 find: string,
243 replacement: string,
244): string | null {
245 find = handlePathWithSlash(find);
246 replacement = handlePathWithSlash(replacement);
247 if (file.startsWith(find)) {
248 const realFilePath = file.replace(find, replacement);
249 if (fs.existsSync(realFilePath)) {
250 return realFilePath;
251 }
252 } else {
253 find = `/node_modules/${find}`;
254 const index = file.indexOf(find);
255 if (index !== -1) {
256 const realFilePath = replacement + file.slice(index + find.length);
257 if (fs.existsSync(realFilePath)) {
258 return realFilePath;
259 }
260 }
261 }
262 return null;
263}
264
265function replaceFileWithRegExp(
266 file: string,

Callers 1

getMappingFilePathFunction · 0.85

Calls 1

handlePathWithSlashFunction · 0.85

Tested by

no test coverage detected