refactor(build): 移除依赖补丁脚本并优化构建配置
- 删除 scripts/patch-deps.js 文件及其相关依赖处理逻辑 - 移除 src/patches 目录下的所有补丁文件 - 更新 vite/plugins/index.js 中的插件引用方式 - 从 package.json 中移除 postinstall 脚本 - 从 vite.config.js 中移除 xe-utils 别名配置 - 保留 element-plus 表单工具补丁以抑制 NaN 警告 - 简化构建流程减少不必要的依赖修改操作
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Final patch: guards ALL async paths in form-label-wrap to prevent
|
||||
// errors during vxe-table expand row teardown
|
||||
export default function patchElFormNan() {
|
||||
return {
|
||||
name: 'patch-el-form-nan',
|
||||
enforce: 'pre',
|
||||
buildStart() {
|
||||
const target = path.resolve(
|
||||
process.cwd(),
|
||||
'node_modules/element-plus/es/components/form/src/form-label-wrap.mjs'
|
||||
);
|
||||
if (!fs.existsSync(target)) return;
|
||||
const code = fs.readFileSync(target, 'utf-8');
|
||||
if (code.includes('_isMounted')) return; // already patched
|
||||
const patched = code
|
||||
.replace('return Math.ceil(Number.parseFloat(width))', 'return Math.ceil(Number.parseFloat(width)) || 0')
|
||||
.replace('const updateLabelWidth = (action = \"update\") => {',
|
||||
'let _isMounted = true;\n\tconst updateLabelWidth = (action = \"update\") => {')
|
||||
.replace('nextTick(() => {',
|
||||
'nextTick(() => {\n\t\t\t\tif (!_isMounted) return;')
|
||||
.replace('if (slots.default && props.isAutoWidth) {',
|
||||
'try {\n\t\t\t\tif (slots.default && props.isAutoWidth) {')
|
||||
.replace('else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);',
|
||||
'else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);\n\t\t\t\t}\n\t\t\t} catch (e) { /* teardown race */ }')
|
||||
.replace('onBeforeUnmount(() => {', 'onBeforeUnmount(() => {\n\t\t\t_isMounted = false;')
|
||||
.replace('onUpdated(() => updateLabelWidthFn())', 'onUpdated(() => { if (_isMounted) updateLabelWidthFn(); })')
|
||||
.replace('if (props.updateAll) formContext?.registerLabelWidth(val, oldVal);',
|
||||
'if (_isMounted && props.updateAll) formContext?.registerLabelWidth(val, oldVal);')
|
||||
.replace('return () => {', 'return () => {\n\t\t\tif (!_isMounted) return null;');
|
||||
if (patched !== code) {
|
||||
fs.writeFileSync(target, patched, 'utf-8');
|
||||
console.log('[patch-el-form-nan] Patched form-label-wrap.mjs');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
import { isArray } from "../../../utils/types.mjs";
|
||||
import { ensureArray } from "../../../utils/arrays.mjs";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
// Patched: suppress NaN warnings from Element Plus during vxe-table expand row teardown
|
||||
const SCOPE = "ElForm";
|
||||
|
||||
function useFormLabelWidth() {
|
||||
const potentialLabelWidthArr = ref([]);
|
||||
const autoLabelWidth = computed(() => {
|
||||
if (!potentialLabelWidthArr.value.length) return "0";
|
||||
const max = Math.max(...potentialLabelWidthArr.value);
|
||||
return max ? `${max}px` : "";
|
||||
});
|
||||
|
||||
function getLabelWidthIndex(width) {
|
||||
// Patched: skip NaN values silently (vxe-table expand row teardown)
|
||||
if (width == null || isNaN(width)) return -1;
|
||||
const index = potentialLabelWidthArr.value.indexOf(width);
|
||||
// Patched: removed debugWarn for unexpected width — harmless during teardown
|
||||
return index;
|
||||
}
|
||||
|
||||
function registerLabelWidth(val, oldVal) {
|
||||
if (val && oldVal) {
|
||||
const index = getLabelWidthIndex(oldVal);
|
||||
if (index > -1) potentialLabelWidthArr.value.splice(index, 1, val);
|
||||
} else if (val && !isNaN(val)) {
|
||||
potentialLabelWidthArr.value.push(val);
|
||||
}
|
||||
}
|
||||
|
||||
function deregisterLabelWidth(val) {
|
||||
const index = getLabelWidthIndex(val);
|
||||
if (index > -1) potentialLabelWidthArr.value.splice(index, 1);
|
||||
}
|
||||
|
||||
return {
|
||||
autoLabelWidth,
|
||||
registerLabelWidth,
|
||||
deregisterLabelWidth
|
||||
};
|
||||
}
|
||||
|
||||
const filterFields = (fields, props) => {
|
||||
const normalized = ensureArray(props).map((prop) =>
|
||||
isArray(prop) ? prop.join(".") : prop
|
||||
);
|
||||
return normalized.length > 0
|
||||
? fields.filter(
|
||||
(field) => field.propString && normalized.includes(field.propString)
|
||||
)
|
||||
: fields;
|
||||
};
|
||||
|
||||
export { filterFields, useFormLabelWidth };
|
||||
@@ -1,10 +0,0 @@
|
||||
/**
|
||||
* Patched hasOwnProp - compatible with Vue 3 Proxy objects
|
||||
* Original: obj.hasOwnProperty(key) fails on Proxy
|
||||
* Fix: Object.prototype.hasOwnProperty.call(obj, key)
|
||||
*/
|
||||
function hasOwnProp(obj, key) {
|
||||
return obj && Object.prototype.hasOwnProperty.call(obj, key)
|
||||
}
|
||||
|
||||
export default hasOwnProp
|
||||
@@ -1,50 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Patch xe-utils hasOwnProp for Vue 3 Proxy compatibility.
|
||||
*
|
||||
* Root cause: Object.prototype.hasOwnProperty.call(proxyObj, key) throws
|
||||
* "TypeError: obj.hasOwnProperty is not a function"
|
||||
* when obj is a Vue 3 reactive Proxy, because Vue's reactivity system
|
||||
* intercepts the [[Get]] trap for 'hasOwnProperty'.
|
||||
*
|
||||
* Fix: Use try-catch. If direct call fails, use Reflect.has or key-in check.
|
||||
*/
|
||||
export default function patchXeUtilsHasOwnProp() {
|
||||
return {
|
||||
name: 'patch-xe-utils-hasownprop',
|
||||
enforce: 'pre',
|
||||
buildStart() {
|
||||
const targets = [
|
||||
path.resolve(process.cwd(), 'node_modules/xe-utils/hasOwnProp.js'),
|
||||
];
|
||||
for (const target of targets) {
|
||||
if (!fs.existsSync(target)) continue;
|
||||
const code = fs.readFileSync(target, 'utf-8');
|
||||
if (code.includes('[vue3-proxy-safe]')) continue;
|
||||
const patched = `/**
|
||||
* Check if object has own property - Vue 3 Proxy safe [vue3-proxy-safe]
|
||||
*/
|
||||
function hasOwnProp (obj, key) {
|
||||
if (obj == null) return false
|
||||
try {
|
||||
return Object.prototype.hasOwnProperty.call(obj, key)
|
||||
} catch (e) {
|
||||
// Vue 3 reactive Proxy throws on hasOwnProperty; fallback
|
||||
try {
|
||||
return key in Object(obj)
|
||||
} catch (e2) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = hasOwnProp
|
||||
`;
|
||||
fs.writeFileSync(target, patched, 'utf-8');
|
||||
console.log('[patch-xe-utils-hasownprop] Patched ' + target);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user