MCPcopy
hub / github.com/processing/p5.js / replace

Function replace

utils/patch.mjs:7–27  ·  view source on GitHub ↗
(path, src, dest)

Source from the content-addressed store, hash-verified

5 const patched = {};
6
7 const replace = (path, src, dest) => {
8 if (Array.isArray(path)) {
9 path.forEach(path => replace(path, src, dest));
10 return;
11 }
12 try {
13 if (!path.startsWith("types/"))
14 path = "types/" + path;
15
16 const before = patched[path] ??
17 (cache[path] ??= fs.readFileSync("./" + path, { encoding: 'utf-8' }));
18 const after = before.replaceAll(src, dest);
19
20 if (after !== before)
21 patched[path] = after;
22 else
23 console.error(`A patch failed in ${path}:\n -${src}\n +${dest}`);
24 } catch (err) {
25 console.error(err);
26 }
27 };
28
29 // TODO: Handle this better in the docs instead of patching
30 replace(

Callers 2

rollup.config.mjsFile · 0.85
applyPatchesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected