From a0490275a8e116f0a51e6c95a7bd21161480d3b3 Mon Sep 17 00:00:00 2001 From: Mardav Wala Date: Fri, 15 Aug 2025 16:20:30 +0000 Subject: [PATCH] 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 --- fix-regex.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 fix-regex.js diff --git a/fix-regex.js b/fix-regex.js new file mode 100644 index 0000000..d189311 --- /dev/null +++ b/fix-regex.js @@ -0,0 +1,48 @@ +#!/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.'); +} diff --git a/package.json b/package.json index 7534fbb..6b0cd9a 100644 --- a/package.json +++ b/package.json @@ -48,13 +48,13 @@ "scripts": { "build": "npm run fix:format && npm run check && npm run build:compile && npm run build:package", "build:compile": "tsc", - "build:package": "ncc build --source-map --no-source-map-register --license licenses.txt", + "build:package": "node fix-regex.js && ncc build --source-map --no-source-map-register --license licenses.txt", "check": "concurrently -n check: -c red,green,blue -g npm:check:*", "check:build": "tsc --noEmit", "check:format": "prettier --check .", "check:lint": "eslint .", "fix:format": "prettier --write .", "test": "jest", - "postinstall": "patch-package" + "postinstall": "node fix-regex.js" } } \ No newline at end of file