build: upgrade pjax and use patch-package

This commit is contained in:
EnixCoda 2024-07-11 23:43:39 +08:00
parent f0fc30f57f
commit 3fed802e64
12 changed files with 1399 additions and 2802 deletions

View file

@ -8,12 +8,12 @@
"private": true,
"homepage": "https://github.com/EnixCoda/Gitako",
"scripts": {
"prepare": "husky install",
"dev": "NODE_OPTIONS=--openssl-legacy-provider VERSION=dev-v$(node scripts/get-version.js) webpack --watch",
"dev-safari": "TARGET=safari yarn run dev",
"dev-firefox": "web-ext run --source-dir=dist --firefox-profile=firefox-profile --profile-create-if-missing --keep-profile-changes --start-url https://github.com/EnixCoda/Gitako",
"analyze-bundle": "NODE_OPTIONS=--openssl-legacy-provider ANALYZE= NODE_ENV=production webpack",
"postinstall": "node scripts/fix-deps",
"prepare": "husky install",
"postinstall": "patch-package",
"postversion": "sh scripts/post-version.sh",
"build": "NODE_OPTIONS=--openssl-legacy-provider VERSION=v$(node scripts/get-version.js) NODE_ENV=production webpack",
"roll": "make release",
@ -28,7 +28,7 @@
"ini": "^3.0.0",
"js-base64": "^3.7.2",
"nprogress": "^0.2.0",
"pjax-api": "^3.33.0",
"pjax-api": "^3.44.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-iifc": "^1.2.0",
@ -75,7 +75,7 @@
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"file-loader": "^3.0.1",
"fork-ts-checker-webpack-plugin": "^6.5.0",
"fork-ts-checker-webpack-plugin": "^9.0.2",
"husky": "^8.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
@ -83,18 +83,18 @@
"json-loader": "^0.5.7",
"lint-staged": "^13.0.3",
"mini-css-extract-plugin": "^0.9.0",
"patch-package": "^8.0.0",
"prettier": "^2.8.3",
"puppeteer": "^22.12.1",
"raw-loader": "^4.0.0",
"sass": "^1.26.2",
"sass-loader": "^8.0.2",
"typescript": "^4.9.4",
"uglifyjs-webpack-plugin": "^2.1.2",
"typescript": "^5.5.3",
"url-loader": "^1.1.2",
"web-ext": "^7.1.1",
"webpack": "^5.91.0",
"webpack-bundle-analyzer": "^3.6.0",
"webpack-cli": "^3.1.2"
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4"
},
"prettier": {
"printWidth": 100,

View file

@ -0,0 +1,23 @@
diff --git a/node_modules/@primer/behaviors/dist/esm/anchored-position.js b/node_modules/@primer/behaviors/dist/esm/anchored-position.js
index 3729dce..0f3cfc0 100644
--- a/node_modules/@primer/behaviors/dist/esm/anchored-position.js
+++ b/node_modules/@primer/behaviors/dist/esm/anchored-position.js
@@ -34,6 +34,9 @@ function getPositionedParent(element) {
function getClippingRect(element) {
let parentNode = element;
while (parentNode !== null) {
+ if (parentNode === document) {
+ break
+ }
if (parentNode === document.body) {
break;
}
@@ -43,7 +46,7 @@ function getClippingRect(element) {
}
parentNode = parentNode.parentNode;
}
- const clippingNode = parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;
+ const clippingNode = parentNode === document ? document.documentElement : parentNode === document.body || !(parentNode instanceof HTMLElement) ? document.body : parentNode;
const elemRect = clippingNode.getBoundingClientRect();
const elemStyle = getComputedStyle(clippingNode);
const [borderTop, borderLeft, borderRight, borderBottom] = [

View file

@ -0,0 +1,29 @@
diff --git a/node_modules/pjax-api/dist/index.js b/node_modules/pjax-api/dist/index.js
index bafa42e..9a124a2 100644
--- a/node_modules/pjax-api/dist/index.js
+++ b/node_modules/pjax-api/dist/index.js
@@ -5759,14 +5759,7 @@ function loadPosition() {
}
exports.loadPosition = loadPosition;
function savePosition() {
- window.history.replaceState({
- ...window.history.state,
- position: {
- ...window.history.state?.position,
- top: window.scrollY,
- left: window.scrollX
- }
- }, document.title);
+ return;
}
exports.savePosition = savePosition;
function isTransitable(state) {
@@ -6100,7 +6093,7 @@ class Response {
this.url = url;
this.xhr = xhr;
this.header = name => this.xhr.getResponseHeader(name);
- this.document = this.xhr.responseXML.cloneNode(true);
+ this.document = this.xhr.responseXML;
if (url.origin !== new url_1.URL(xhr.responseURL, window.location.href).origin) throw new Error(`Redirected to another origin`);
Object.defineProperty(this.document, 'URL', {
configurable: true,

View file

@ -0,0 +1,24 @@
diff --git a/node_modules/spica/type.ts b/node_modules/spica/type.ts
index c11e7a7..969a841 100644
--- a/node_modules/spica/type.ts
+++ b/node_modules/spica/type.ts
@@ -1,4 +1,4 @@
-import { isArray, toString, ObjectGetPrototypeOf } from './alias';
+import { ObjectGetPrototypeOf, isArray, toString } from './alias';
export type NonNull = {};
type Falsy = undefined | false | 0 | 0n | '' | null | void;
@@ -238,9 +238,10 @@ export function type(value: unknown): string {
case 'function':
return 'Function';
case 'object':
- if (value === null) return 'null';
- assert(value = value as object);
- const tag: string = (value as object)[Symbol.toStringTag];
+ if (value === null || value === undefined) return 'null';
+ const tag: string = (value as {
+ [key in typeof Symbol.toStringTag]: string
+ })[Symbol.toStringTag];
if (tag) return tag;
switch (ObjectGetPrototypeOf(value)) {
case ArrayPrototype:

File diff suppressed because one or more lines are too long

View file

@ -1,23 +0,0 @@
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)
}
}

View file

@ -1,47 +0,0 @@
const fs = require('fs').promises
const path = require('path')
/**
* This script rewrites local dependency files to resolve compatibility issues.
* This is a bit dirty but really effective.
*/
function modify(source = '', pairs = []) {
for (const [original, replace] of pairs) {
if (source.includes(original)) {
source = source.replace(original, replace)
} else {
throw new Error(`Original string not found: ${JSON.stringify(original)}`)
}
}
return source
}
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')
if (source.includes(MODIFIED_MARK)) {
console.log(`${filePath.replace(process.cwd(), '.')} 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,
require('./@primer__behaviors').fix,
]) {
await fix()
}
}
fixDeps()

View file

@ -1,45 +0,0 @@
const { fixDep } = require('.')
const targetFilePath = `pjax-api/dist/pjax-api.js`
const pairs = [
// Firefox
[
`void xhr.open(method, requestURL.path, true);`,
`void xhr.open(method, requestURL.reference, true);`,
],
// Firefox
[
`this.document = this.xhr.responseXML.cloneNode(true);`,
`this.document = this.xhr.responseXML;`,
],
// Chrome: modifying cross-context history state causes troubles
// Scroll position can still be restored without this function
[
`
function savePosition() {
var _a;
void window.history.replaceState({
...window.history.state,
position: {
...(_a = window.history.state) === null || _a === void 0 ? void 0 : _a.position,
top: window.pageYOffset,
left: window.pageXOffset
}
}, document.title);
}`,
`
function savePosition() {
return;
}`,
],
]
exports.fix = async () => {
try {
await fixDep(targetFilePath, pairs)
} catch (err) {
console.error((err && err.message) || err)
const shouldTerminate = process.env.IGNORE_FIX_PJAX_API_FAILURE !== 'true'
if (shouldTerminate) process.exit(1)
}
}

View file

@ -1,20 +0,0 @@
const { fixDep } = require('.')
const targetFilePath = `styled-components/dist/styled-components.browser.esm.js`
const pairs = [
// Firefox
// disable production check in `checkDynamicCreation`
[
`function(e,t){if("production"!==process.env.NODE_ENV)`, // prettier-ignore
`function(e,t){if(false)`,
],
]
exports.fix = async () => {
try {
await fixDep(targetFilePath, pairs)
} catch (err) {
console.error((err && err.message) || err)
process.exit(1)
}
}

View file

@ -2,6 +2,7 @@ import { useConfigs } from 'containers/ConfigsContext'
import { platform } from 'platforms'
import * as React from 'react'
import { useEvent, useInterval } from 'react-use'
import { run } from 'utils/general'
const config: import('pjax-api').Config = {
areas: [
@ -15,11 +16,7 @@ const config: import('pjax-api').Config = {
update: {
css: false,
},
fetch: {
cache(path) {
return path
},
},
fetch: {},
link: 'a:not(a)', // this helps fixing the go-back-in-history issue
form: 'form:not(form)', // prevent blocking form submissions
fallback(/* target, reason */) {
@ -32,13 +29,14 @@ export function usePJAXAPI() {
// make history travel work
React.useEffect(() => {
if (pjaxMode === 'pjax-api') {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Pjax } = require('pjax-api')
new Pjax({
...config,
filter() {
return false
},
run(async () => {
const { Pjax } = await import('pjax-api')
new Pjax({
...config,
filter() {
return false
},
})
})
}
}, []) // eslint-disable-line react-hooks/exhaustive-deps

View file

@ -83,7 +83,6 @@ if (analyze) {
plugins.push(
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VERSION': JSON.stringify(process.env.VERSION),
}),
)

3936
yarn.lock

File diff suppressed because it is too large Load diff