MCPcopy Create free account
hub / github.com/jhen0409/react-native-debugger / revertCode

Function revertCode

npm-package/src/injectDevToolsMiddleware.js:205–230  ·  view source on GitHub ↗
(
  modulePath,
  {
    func: funcFlag, replaceFunc: replaceFuncFlag, target, dir, file,
  },
)

Source from the content-addressed store, hash-verified

203}
204
205const revertCode = (
206 modulePath,
207 {
208 func: funcFlag, replaceFunc: replaceFuncFlag, target, dir, file,
209 },
210) => {
211 const filePath = join(modulePath, target, dir, file)
212 if (!fs.existsSync(filePath)) return false
213
214 const middlewareCode = fs.readFileSync(filePath, 'utf-8')
215 let start = middlewareCode.indexOf(startFlag)
216 let end = middlewareCode.indexOf(endFlag) + endFlag.length
217 // already injected
218 if (start > -1 && middlewareCode.indexOf(replaceFuncFlag) === -1) {
219 start = -1
220 end = -1
221 }
222 if (start === -1) return false
223 fs.writeFileSync(
224 filePath,
225 middlewareCode.substr(0, start)
226 + funcFlag
227 + middlewareCode.substr(end, middlewareCode.length),
228 )
229 return true
230}
231
232export const revert = (modulePath, moduleName) => {
233 const info = getModuleInfo(modulePath, moduleName)

Callers 1

revertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected