Merge branch 'feature/fork-pjax-api' into develop

This commit is contained in:
EnixCoda 2020-06-21 16:58:26 +08:00
commit 5d22dd35a0
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
2 changed files with 37 additions and 1 deletions

View file

@ -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
View 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()