mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: patch webext-domain-permission-toggle
This commit is contained in:
parent
c9e1bb4887
commit
12535fb6fe
2 changed files with 38 additions and 2 deletions
|
|
@ -24,15 +24,25 @@ function modify(source = '', pairs = []) {
|
|||
|
||||
const nodeModulesPath = path.resolve(__dirname, '../../', `node_modules`)
|
||||
|
||||
const MODIFIED_MARK = `\n/* This file has been modified */\n`
|
||||
|
||||
exports.fixDep = async function fixDep(targetFilePath, pairs) {
|
||||
const filePath = path.resolve(nodeModulesPath, targetFilePath)
|
||||
const source = await fs.readFile(filePath, 'utf-8')
|
||||
const modified = modify(source, pairs)
|
||||
if (source.includes(MODIFIED_MARK)) {
|
||||
console.log(`${filePath} has been fixed, skipping.`)
|
||||
return
|
||||
}
|
||||
const modified = modify(source, pairs) + MODIFIED_MARK
|
||||
await fs.writeFile(filePath, modified, 'utf-8')
|
||||
}
|
||||
|
||||
async function fixDeps() {
|
||||
for (const fix of [require('./pjax-api').fix, require('./styled-components').fix]) {
|
||||
for (const fix of [
|
||||
require('./pjax-api').fix,
|
||||
require('./styled-components').fix,
|
||||
require('./webext-domain-permission-toggle').fix,
|
||||
]) {
|
||||
await fix()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
scripts/fix-deps/webext-domain-permission-toggle.js
Normal file
26
scripts/fix-deps/webext-domain-permission-toggle.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const { fixDep } = require('.')
|
||||
|
||||
const targetFilePath = `webext-domain-permission-toggle/index.js`
|
||||
const pairs = [
|
||||
[
|
||||
`const { name, optional_permissions: optionalPermissions } = chrome.runtime.getManifest();`, // prettier-ignore
|
||||
`const { name, optional_host_permissions: optionalPermissions } = chrome.runtime.getManifest();`, // prettier-ignore
|
||||
],
|
||||
[
|
||||
`const optionalHosts = optionalPermissions === null || optionalPermissions === void 0 ? void 0 : optionalPermissions.filter(permission => /<all_urls>|\\*/.test(permission));`, // prettier-ignore
|
||||
`const optionalHosts = optionalPermissions === null || optionalPermissions === void 0 ? void 0 : optionalPermissions.filter(permission => '*://*/*' === permission);`, // prettier-ignore
|
||||
],
|
||||
[
|
||||
`contexts: ['page_action', 'browser_action']`, // prettier-ignore
|
||||
`contexts: ['action', 'page_action', 'browser_action']`, // prettier-ignore
|
||||
],
|
||||
]
|
||||
|
||||
exports.fix = async () => {
|
||||
try {
|
||||
await fixDep(targetFilePath, pairs)
|
||||
} catch (err) {
|
||||
console.error((err && err.message) || err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue