mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
Merge branch 'feature/fork-pjax-api' into develop
This commit is contained in:
commit
5d22dd35a0
2 changed files with 37 additions and 1 deletions
|
|
@ -11,7 +11,7 @@
|
|||
"start": "VERSION=dev-v$(node scripts/get-version.js) webpack --watch",
|
||||
"debug-firefox": "web-ext run -s dist",
|
||||
"analyse-bundle": "ANALYSE= NODE_ENV=production webpack",
|
||||
"postinstall": "rm -rf node_modules/@types/react-native",
|
||||
"postinstall": "rm -rf node_modules/@types/react-native && node scripts/fix-pjax-api",
|
||||
"build": "VERSION=v$(node scripts/get-version.js) NODE_ENV=production webpack",
|
||||
"roll": "make release"
|
||||
},
|
||||
|
|
|
|||
36
scripts/fix-pjax-api.js
Normal file
36
scripts/fix-pjax-api.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const fs = require('fs').promises
|
||||
const path = require('path')
|
||||
|
||||
function modify(source = '', pairs) {
|
||||
for (const [original, replace] of pairs) {
|
||||
if (source.includes(original)) {
|
||||
source = source.replace(original, replace)
|
||||
if (source.includes(original)) {
|
||||
throw new Error(`More than one original string found`, JSON.stringify(original))
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Original string not found`, JSON.stringify(original))
|
||||
}
|
||||
}
|
||||
|
||||
return source
|
||||
}
|
||||
|
||||
async function fixPJAXAPI() {
|
||||
const pairs = [
|
||||
[
|
||||
`void xhr.open(method, requestURL.path, true);`,
|
||||
`void xhr.open(method, requestURL.reference, true);`,
|
||||
],
|
||||
[
|
||||
`this.document = this.xhr.responseType === 'document' ? this.xhr.responseXML.cloneNode(true) : html_1.parse(this.xhr.responseText).extract();`,
|
||||
`this.document = this.xhr.responseType === 'document' ? this.xhr.responseXML : html_1.parse(this.xhr.responseText).extract();`,
|
||||
],
|
||||
]
|
||||
const filePath = path.resolve(__dirname, '..', `node_modules/pjax-api/dist/pjax-api.js`)
|
||||
const source = await fs.readFile(filePath, 'utf-8')
|
||||
const modified = modify(source, pairs)
|
||||
fs.writeFile(filePath, modified, 'utf-8')
|
||||
}
|
||||
|
||||
fixPJAXAPI()
|
||||
Loading…
Reference in a new issue