Files
add-to-project/fix-regex.js
Mardav Wala a0490275a8 Automate regex fix for CI builds
- Updated build:package script to run fix-regex.js before bundling
- Updated postinstall script to apply fix after npm install
- Ensures CI builds will have the fix applied automatically
- Fixes misleading operator precedence in /^text\/|charset=utf-8$/ regex
2025-08-15 16:20:30 +00:00

49 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* Fix for misleading operator precedence in @octokit/request regex
* Changes /^text\/|charset=utf-8$/ to /^text\/|charset=utf-8/
*/
const fs = require('fs');
const path = require('path');
const filesToFix = [
'node_modules/@actions/github/node_modules/@octokit/request/dist-src/fetch-wrapper.js',
'node_modules/@actions/github/node_modules/@octokit/request/dist-node/index.js',
'node_modules/@actions/github/node_modules/@octokit/request/dist-web/index.js'
];
console.log('🔧 Applying regex fix for @octokit/request...');
let filesFixed = 0;
filesToFix.forEach(filePath => {
if (fs.existsSync(filePath)) {
try {
let content = fs.readFileSync(filePath, 'utf8');
const originalContent = content;
// Fix the problematic regex pattern - replace the end anchor version with the fixed version
content = content.replace(/charset=utf-8\$\//g, 'charset=utf-8/');
if (content !== originalContent) {
fs.writeFileSync(filePath, content, 'utf8');
console.log(`✅ Fixed: ${filePath}`);
filesFixed++;
} else {
console.log(` No changes needed: ${filePath}`);
}
} catch (error) {
console.error(`❌ Error fixing ${filePath}:`, error.message);
}
} else {
console.log(`⚠️ File not found: ${filePath}`);
}
});
console.log(`\n🎉 Fix complete! ${filesFixed} files updated.`);
if (filesFixed > 0) {
console.log('Run "npm run build:package" to rebuild with the fix.');
}