-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch.js
More file actions
157 lines (145 loc) · 4.65 KB
/
patch.js
File metadata and controls
157 lines (145 loc) · 4.65 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const fs = require('fs/promises')
async function fixBrowserCheck(path) {
const vueRuntimeDom = await fs.readFile(path, { encoding: 'utf8' })
const fixedVueRuntimeDom = vueRuntimeDom
.replaceAll(
"typeof window !== 'undefined'",
"typeof window !== 'undefined' && typeof document !== 'undefined'",
)
.replaceAll(
'"undefined"!=typeof window',
'"undefined"!=typeof window && "undefined"!==typeof document',
)
await fs.writeFile(path, fixedVueRuntimeDom)
}
;(async () => {
//Fix solana
const solanaWeb3Package = await fs.readFile(
'node_modules/@solana/web3.js/package.json',
{ encoding: 'utf8' },
)
const fixedSolanaWeb3Package = solanaWeb3Package.replaceAll(
'./lib/index.browser.cjs.js',
'./lib/index.cjs.js',
)
await fs.writeFile(
'node_modules/@solana/web3.js/package.json',
fixedSolanaWeb3Package,
)
//Fix ethers pbkdf2
const ethersPbkdf2Web3Package = await fs.readFile(
'node_modules/@ethersproject/pbkdf2/package.json',
{ encoding: 'utf8' },
)
const fixedEthersPbkdf2Package = ethersPbkdf2Web3Package.replaceAll(
'browser-pbkdf2.js',
'pbkdf2.js',
)
await fs.writeFile(
'node_modules/@ethersproject/pbkdf2/package.json',
fixedEthersPbkdf2Package,
)
//Fix xmlhttprequest file
const xmlHttpRequestFile = await fs.readFile(
'node_modules/xmlhttprequest/lib/XMLHttpRequest.js',
{ encoding: 'utf8' },
)
const fixedXmlHttpRequestFile = xmlHttpRequestFile.replaceAll(
'var spawn = require("child_process").spawn;',
'var spawn = () => {}',
)
await fs.writeFile(
'node_modules/xmlhttprequest/lib/XMLHttpRequest.js',
fixedXmlHttpRequestFile,
)
//Fix Vue JSX conflict with react-native jsx
const vueJsxTypeDef = await fs.readFile('node_modules/vue/types/jsx.d.ts', {
encoding: 'utf8',
})
const fixVueJsxTypeDef = vueJsxTypeDef.replaceAll('JSX', 'JSX_NOT_REQUIRED')
await fs.writeFile('node_modules/vue/types/jsx.d.ts', fixVueJsxTypeDef)
try {
await fs.rename(
'node_modules/superstruct/lib/index.cjs',
'node_modules/superstruct/lib/index.cjs.js',
)
} catch (e) {
//Ignore error
//console.log('node_modules/superstruct/lib/index.cjs', 'already renamed?')
}
await fixBrowserCheck('node_modules/vue/dist/vue.runtime.common.dev.js')
await fixBrowserCheck('node_modules/vue/dist/vue.runtime.common.prod.js')
//Fix for bitcoin send issue with BufferN for file p2pkh
const readBufferN_p2pkh = await fs.readFile(
'node_modules/bitcoinjs-lib/src/payments/p2pkh.js',
{
encoding: 'utf8',
},
)
const writeBufferN_To_Buffer_p2pkh = readBufferN_p2pkh.replaceAll(
'output: typef.maybe(typef.BufferN(25))',
'output: typef.maybe(typef.Buffer)',
)
await fs.writeFile(
'node_modules/bitcoinjs-lib/src/payments/p2pkh.js',
writeBufferN_To_Buffer_p2pkh,
)
//Fix for bitcoin send issue with BufferN for file p2sh
const readBufferN_p2sh = await fs.readFile(
'node_modules/bitcoinjs-lib/src/payments/p2sh.js',
{
encoding: 'utf8',
},
)
const writeBufferN_To_Buffer_p2sh = readBufferN_p2sh.replaceAll(
'output: typef.maybe(typef.BufferN(23))',
'output: typef.maybe(typef.Buffer)',
)
await fs.writeFile(
'node_modules/bitcoinjs-lib/src/payments/p2sh.js',
writeBufferN_To_Buffer_p2sh,
)
//Fix for bitcoin send issue with BufferN for file p2wpkh
const readBufferN_p2wpkh = await fs.readFile(
'node_modules/bitcoinjs-lib/src/payments/p2wpkh.js',
{
encoding: 'utf8',
},
)
const writeBufferN_To_Buffer_p2wpkh = readBufferN_p2wpkh.replaceAll(
'output: typef.maybe(typef.BufferN(22))',
'output: typef.maybe(typef.Buffer)',
)
await fs.writeFile(
'node_modules/bitcoinjs-lib/src/payments/p2wpkh.js',
writeBufferN_To_Buffer_p2wpkh,
)
//Fix for bitcoin send issue with BufferN for file p2wsh
const readBufferN_p2wsh = await fs.readFile(
'node_modules/bitcoinjs-lib/src/payments/p2wsh.js',
{
encoding: 'utf8',
},
)
const writeBufferN_To_Buffer_p2wsh = readBufferN_p2wsh.replaceAll(
'output: typef.maybe(typef.BufferN(34))',
'output: typef.maybe(typef.Buffer)',
)
await fs.writeFile(
'node_modules/bitcoinjs-lib/src/payments/p2wsh.js',
writeBufferN_To_Buffer_p2wsh,
)
//Fix ZLIB FILE
const zLibFile = await fs.readFile(
'node_modules/@eth-optimism/core-utils/dist/optimism/batch-encoding.js',
{ encoding: 'utf8' },
)
const fixedZLibFile = zLibFile.replaceAll(
'const zlib_1 = __importDefault(require("zlib"));',
'const zlib_1 = () => {}',
)
await fs.writeFile(
'node_modules/@eth-optimism/core-utils/dist/optimism/batch-encoding.js',
fixedZLibFile,
)
})()