forked from openchamber/openchamber
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-deprecation.js
More file actions
91 lines (73 loc) · 2.54 KB
/
Copy pathfix-deprecation.js
File metadata and controls
91 lines (73 loc) · 2.54 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/**
* Fix for http-proxy package util._extend deprecation warning
* This script patches the http-proxy package to use Object.assign instead of util._extend
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function fixHttpProxyDeprecation() {
try {
const candidateDirs = [
path.join(__dirname, 'node_modules', 'http-proxy', 'lib', 'http-proxy'),
];
const bunStoreDir = path.join(__dirname, 'node_modules', '.bun');
if (fs.existsSync(bunStoreDir)) {
for (const entry of fs.readdirSync(bunStoreDir, { withFileTypes: true })) {
if (!entry.isDirectory() || !entry.name.startsWith('http-proxy@')) continue;
candidateDirs.push(path.join(bunStoreDir, entry.name, 'node_modules', 'http-proxy', 'lib', 'http-proxy'));
}
}
for (const httpProxyDir of candidateDirs) {
patchHttpProxyDir(httpProxyDir);
}
} catch {
// Silently handle errors - functionality is not affected
}
}
function patchHttpProxyDir(httpProxyDir) {
const indexPath = path.join(httpProxyDir, 'index.js');
const commonPath = path.join(httpProxyDir, 'common.js');
if (!fs.existsSync(indexPath) || !fs.existsSync(commonPath)) {
return;
}
if (fs.existsSync(indexPath)) {
let content = fs.readFileSync(indexPath, 'utf8');
let indexPatched = false;
if (content.includes("require('util')._extend")) {
content = content.replace(
/extend\s*=\s*require\('util'\)\._extend,/,
"extend = Object.assign,"
);
indexPatched = true;
}
if (content.includes("require('util').inherits")) {
content = content.replace(
/require\('util'\)\.inherits\((\w+),\s*(\w+)\);/,
"Object.setPrototypeOf($1.prototype, $2.prototype);"
);
indexPatched = true;
}
if (indexPatched) {
fs.writeFileSync(indexPath, content, 'utf8');
}
}
if (fs.existsSync(commonPath)) {
let content = fs.readFileSync(commonPath, 'utf8');
let commonPatched = false;
if (content.includes("require('util')._extend")) {
content = content.replace(
/extend\s*=\s*require\('util'\)\._extend,/,
"extend = Object.assign,"
);
commonPatched = true;
}
if (commonPatched) {
fs.writeFileSync(commonPath, content, 'utf8');
}
}
}
// Run the fix
fixHttpProxyDeprecation();