mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: patch @primer/behaviors
This commit is contained in:
parent
e5096e89b6
commit
20ed9b9a59
2 changed files with 36 additions and 6 deletions
23
scripts/fix-deps/@primer__behaviors.js
Normal file
23
scripts/fix-deps/@primer__behaviors.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const { fixDep } = require('.')
|
||||
|
||||
const targetFilePath = `@primer/behaviors/dist/esm/anchored-position.js`
|
||||
const pairs = [
|
||||
[
|
||||
`if (parentNode === document.body)`,
|
||||
`if (parentNode === document) break
|
||||
if (parentNode === document.body)`,
|
||||
],
|
||||
[
|
||||
`const clippingNode = parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;`, // prettier-ignore
|
||||
`const clippingNode = parentNode === document ? document.documentElement : parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;`, // prettier-ignore
|
||||
],
|
||||
]
|
||||
|
||||
exports.fix = async () => {
|
||||
try {
|
||||
await fixDep(targetFilePath, pairs)
|
||||
} catch (err) {
|
||||
console.error((err && err.message) || err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,10 +13,6 @@ function modify(source = '', pairs = []) {
|
|||
} else {
|
||||
throw new Error(`Original string not found: ${JSON.stringify(original)}`)
|
||||
}
|
||||
|
||||
if (source.includes(original)) {
|
||||
throw new Error(`More than one original string found`, JSON.stringify(original))
|
||||
}
|
||||
}
|
||||
|
||||
return source
|
||||
|
|
@ -24,15 +20,26 @@ 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
|
||||
}
|
||||
console.log(`Fixing ${targetFilePath}`)
|
||||
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('./@primer__behaviors').fix,
|
||||
]) {
|
||||
await fix()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue