/** * Fix lodash.template assignWith issue - Manual fix script * Run this after npm/yarn install and before build * * Usage: node fix-lodash-manual.js */ const fs = require('fs'); const path = require('path'); const lodashTemplatePath = path.join(__dirname, 'node_modules', 'lodash.template', 'index.js'); if (!fs.existsSync(lodashTemplatePath)) { console.error('❌ lodash.template not found at:', lodashTemplatePath); console.error('Please run npm install or yarn install first'); process.exit(1); } let content = fs.readFileSync(lodashTemplatePath, 'utf8'); // Check if already patched with new version if (content.includes('/* LODASH_TEMPLATE_PATCHED_V2 */')) { console.log('✓ lodash.template already patched with v2'); process.exit(0); } // Remove old patch if exists if (content.includes('/* LODASH_TEMPLATE_PATCHED */')) { console.log('🔄 Removing old patch...'); content = content.replace(/\/\* LODASH_TEMPLATE_PATCHED \*\/\n.*assignWith[\s\S]*?^\}/m, ''); } console.log('🔧 Patching lodash.template with v2...'); // Correct assignWith implementation that handles undefined customizer const assignWithImpl = `/* LODASH_TEMPLATE_PATCHED_V2 */ // assignWith polyfill for lodash.template - Fixed version function assignWith(object, source, customizer) { if (object == null) return object; if (typeof customizer !== 'function') { customizer = function(objValue, srcValue) { return srcValue; }; } var props = Object.keys(Object(source)); for (var i = 0; i < props.length; i++) { var key = props[i]; var value = source[key]; var assignedValue = customizer(object[key], value, key, object, source); if (assignedValue !== undefined) { object[key] = assignedValue; } } return object; } `; // Find first line break after comments let insertPos = 0; const lines = content.split('\n'); for (let i = 0; i < lines.length; i++) { if (lines[i].trim() === ' */' || lines[i].trim() === '*/') { insertPos = content.indexOf('\n', content.indexOf(lines[i])) + 1; break; } } if (insertPos === 0) { insertPos = content.indexOf('\n') + 1; } const before = content.substring(0, insertPos); const after = content.substring(insertPos); content = before + '\n' + assignWithImpl + after; fs.writeFileSync(lodashTemplatePath, content); console.log('✅ Successfully patched lodash.template with assignWith function (v2)'); console.log(' File:', lodashTemplatePath);