-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatch.js
More file actions
41 lines (33 loc) · 1.41 KB
/
patch.js
File metadata and controls
41 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
// Patch script: replace `.some` with `?.some` in @web3modal/ui dist file
// Runs before build (see package.json: "node patch.js && next build")
const fs = require('fs');
const path = require('path');
const targetPath = path.resolve(__dirname, 'node_modules', '@web3modal', 'ui', 'dist', 'index.js');
function patchFile(filePath) {
try {
if (!fs.existsSync(filePath)) {
console.warn(`[patch] File not found: ${filePath}. Skipping.`);
return;
}
const original = fs.readFileSync(filePath, 'utf8');
let count = 0;
// Replace occurrences of `.some` that are NOT already optional chained (i.e., not `?.some`).
// Restrict to cases where previous char looks like a valid property access receiver end: word, ) or ]
// Avoids touching strings/comments in most minified bundles and avoids `?.some` double-patching.
const patched = original.replace(/([\w\)\]])\.some\b/g, (match, p1) => {
count += 1;
return `${p1}?.some`;
});
if (patched !== original) {
fs.writeFileSync(filePath, patched, 'utf8');
console.log(`[patch] Patched ${filePath} (${count} replacement${count === 1 ? '' : 's'}).`);
} else {
console.log(`[patch] No changes needed for ${filePath}.`);
}
} catch (err) {
console.error(`[patch] Failed to patch ${filePath}:`, err);
// Don't hard fail build for patch issues; exit gracefully.
}
}
patchFile(targetPath);