- 添加 JavaScript 脚本修复 lodash.template 模块中的 assignWith 问题 - 提供 Shell 脚本支持 Linux/Mac 系统的自动修复功能 - 实现 assignWith 函数的简单 polyfill 版本以确保兼容性 - 添加补丁检测机制防止重复修补同一文件 - 在构建前自动运行修复脚本确保依赖完整性
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
/**
|
|
* Fix lodash.template assignWith issue
|
|
* This script patches the lodash.template module to include assignWith
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const lodashTemplatePath = path.join(__dirname, 'node_modules', 'lodash.template', 'index.js');
|
|
|
|
if (!fs.existsSync(lodashTemplatePath)) {
|
|
console.log('lodash.template not found, skipping patch');
|
|
process.exit(0);
|
|
}
|
|
|
|
let content = fs.readFileSync(lodashTemplatePath, 'utf8');
|
|
|
|
// Check if already patched
|
|
if (content.includes('/* LODASH_TEMPLATE_PATCHED */')) {
|
|
console.log('lodash.template already patched');
|
|
process.exit(0);
|
|
}
|
|
|
|
// Simple assignWith implementation
|
|
const assignWithImpl = `
|
|
/* LODASH_TEMPLATE_PATCHED */
|
|
// Simple assignWith implementation
|
|
function assignWith(object, source, customizer) {
|
|
if (object == null) {
|
|
return object;
|
|
}
|
|
var props = Object.keys(Object(source));
|
|
var index = -1;
|
|
var length = props.length;
|
|
|
|
while (++index < length) {
|
|
var key = props[index];
|
|
var value = source[key];
|
|
var assignedValue = customizer ? customizer(object[key], value, key, object, source) : value;
|
|
if (assignedValue !== undefined) {
|
|
object[key] = assignedValue;
|
|
}
|
|
}
|
|
return object;
|
|
}
|
|
`;
|
|
|
|
// Insert at the beginning of the file after any comments
|
|
const firstLineEnd = content.indexOf('\n') + 1;
|
|
const before = content.substring(0, firstLineEnd);
|
|
const after = content.substring(firstLineEnd);
|
|
|
|
content = before + assignWithImpl + after;
|
|
|
|
fs.writeFileSync(lodashTemplatePath, content);
|
|
console.log('✓ Patched lodash.template with assignWith function');
|