-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (27 loc) · 1.05 KB
/
index.js
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
const path = require('path')
const fs = require('fs')
const f1 = path.resolve(__dirname, '../eslint/lib/shared/relative-module-resolver.js')
const f2 = path.resolve(__dirname, '../@eslint/eslintrc/lib/shared/relative-module-resolver.js')
const f3 = path.resolve(__dirname, '../@eslint/eslintrc/dist/eslintrc.cjs')
function doPatch(file) {
if (fs.existsSync(file)) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) return console.log(err)
if (data.includes('eslint-global-patch-applied')) return
const result = data.replace(/resolve\(moduleName, relativeToPath\) {[\s\S]*?catch/g, `resolve(moduleName, relativeToPath) {
// eslint-global-patch-applied
try {
return createRequire(relativeToPath).resolve(moduleName);
} catch (error) {} // eslint-disable-line
try {
return createRequire(__dirname).resolve(moduleName);
} catch`)
fs.writeFile(file, result, 'utf8', function (err) {
if (err) return console.log(err)
})
})
}
}
doPatch(f1)
doPatch(f2)
doPatch(f3)