'use strict';
import * as _0x242f85 from 'node:child_process';
import * as _0x2c891a from 'node:fs';
import _0x1c3e3a from 'node:path';
import { folders, files } from '../../base-repo/app-constants/project-paths.js';
import { stdioStatuses, eslint } from '../../base-repo/constants/tools-constants.js';
import { commandExecutionMessages } from '@code-quality/config-aware-lint/constants';

var __defProp=Object['defineProperty'],__name=(_0x425413,_0x110b4b)=>__defProp(_0x425413,'name',{'value':_0x110b4b,'configurable':!![]});const lintableFilePattern=/\.(js|jsx|ts|tsx)$/;let cachedEslintRulesBuildResult;function formatSpawnFailureMessage(_0x31acf8){return ''+commandExecutionMessages['failedToSpawnCommandPrefix']+_0x31acf8;}__name(formatSpawnFailureMessage,'formatSpawnFailureMessage');function executeCommandWithCombinedOutput(_0x3266bc,_0x1778c2){const _0x288b0c=_0x242f85['spawnSync'](_0x3266bc,{'shell':!![],'encoding':'utf-8','stdio':stdioStatuses['pipe'],..._0x1778c2});let _0x2304ad='';return _0x288b0c['stdout']&&(_0x2304ad+=_0x288b0c['stdout']['toString']()),_0x288b0c['stderr']&&(_0x2304ad+=_0x288b0c['stderr']['toString']()),_0x288b0c['error']&&(_0x2304ad+=formatSpawnFailureMessage(_0x288b0c['error']['message'])),{'output':_0x2304ad['trim'](),'status':_0x288b0c['status']??-0x9ab+0x2633+-0x1c87};}__name(executeCommandWithCombinedOutput,'executeCommandWithCombinedOutput');function normalizePathForCli(_0x4a4c79){return _0x4a4c79['replace'](/\\/g,'/');}__name(normalizePathForCli,'normalizePathForCli');function isLintableFile(_0x21f671){const _0x1ff338=normalizePathForCli(_0x21f671),_0x3aa76f=_0x1ff338['split'](_0x1c3e3a['posix']['sep']);return lintableFilePattern['test'](_0x1ff338)&&!_0x3aa76f['includes'](folders['nodeModules']);}__name(isLintableFile,'isLintableFile');function filterLintableFiles(_0x454d0f){return _0x454d0f['filter'](isLintableFile);}__name(filterLintableFiles,'filterLintableFiles');function resolveEslintConfigForFile(_0x1a9751,_0x4eacd4=process['cwd']()){const _0x3e4455=_0x1c3e3a['resolve'](_0x4eacd4);let _0x54f131=_0x1c3e3a['dirname'](_0x1c3e3a['resolve'](_0x1a9751));while(_0x54f131['startsWith'](_0x3e4455)){const _0x1b86d7=_0x1c3e3a['join'](_0x54f131,files['eslintConfigTs']);if(_0x2c891a['existsSync'](_0x1b86d7))return normalizePathForCli(_0x1b86d7);const _0x2c7303=_0x1c3e3a['dirname'](_0x54f131);if(_0x2c7303===_0x54f131)break;_0x54f131=_0x2c7303;}return normalizePathForCli(_0x1c3e3a['join'](_0x3e4455,files['eslintConfigTs']));}__name(resolveEslintConfigForFile,'resolveEslintConfigForFile');function groupFilesByEslintConfig(_0x570ae1,_0x5ef908=process['cwd']()){const _0x32a12c=new Map();for(const _0x41e624 of _0x570ae1){const _0x44a18d=normalizePathForCli(_0x1c3e3a['resolve'](_0x41e624)),_0x208856=resolveEslintConfigForFile(_0x44a18d,_0x5ef908),_0x479cee=_0x32a12c['get'](_0x208856);_0x479cee?_0x479cee['push'](_0x44a18d):_0x32a12c['set'](_0x208856,[_0x44a18d]);}return _0x32a12c;}__name(groupFilesByEslintConfig,'groupFilesByEslintConfig');function buildEslintRulesOnce(_0x349a50=eslint['build'],_0x3c8154=![]){const _0x15f1d9=process['cwd']()+'::'+_0x349a50;if(!_0x3c8154&&cachedEslintRulesBuildResult&&cachedEslintRulesBuildResult['cacheKey']===_0x15f1d9)return {'output':cachedEslintRulesBuildResult['output'],'status':cachedEslintRulesBuildResult['status']};const _0x1623ac=executeCommandWithCombinedOutput(_0x349a50);return cachedEslintRulesBuildResult={'cacheKey':_0x15f1d9,'output':_0x1623ac['output'],'status':_0x1623ac['status']},_0x1623ac;}__name(buildEslintRulesOnce,'buildEslintRulesOnce');function runEslintBatches(_0x21b957,_0x3c2850){const _0x5f2e94={'buildCommand':eslint['build'],'batchSize':0x32,'eslintConfigFileName':files['eslintConfigTs'],'forceRebuild':![]},_0x119076={..._0x5f2e94,..._0x3c2850};let _0x1283e3=![],_0x3f43e6='';const _0x1ad9ad=buildEslintRulesOnce(_0x119076['buildCommand'],_0x119076['forceRebuild']);_0x3f43e6+=_0x1ad9ad['output']+'\x0a';_0x1ad9ad['status']!==0x2*-0x25b+0x1*0x7bb+0x1*-0x305&&(_0x1283e3=!![]);if(!_0x1283e3){const _0x2ea60b=groupFilesByEslintConfig(_0x21b957);for(const [_0x27c068,_0x48c5fc]of _0x2ea60b){const _0x269ef2=normalizePathForCli(_0x1c3e3a['dirname'](_0x27c068));for(let _0x48a798=0xf5b+-0xd9*0x1+-0xe82;_0x48a798<_0x48c5fc['length'];_0x48a798+=_0x119076['batchSize']){const _0x5d147e=_0x48c5fc['slice'](_0x48a798,_0x48a798+_0x119076['batchSize']),_0x3f5675=_0x5d147e['map'](_0x206dbb=>normalizePathForCli(_0x1c3e3a['relative'](_0x269ef2,_0x206dbb)))['map'](_0xc4053f=>'\x22'+_0xc4053f+'\x22')['join']('\x20'),_0x525330='npx\x20cross-env\x20NODE_OPTIONS=--max-old-space-size=4096\x20eslint\x20-c\x20\x22'+_0x119076['eslintConfigFileName']+'\x22\x20'+_0x3f5675+'\x20--no-error-on-unmatched-pattern',_0x589696=executeCommandWithCombinedOutput(_0x525330,{'cwd':_0x269ef2});_0x3f43e6+=_0x589696['output']+'\x0a',_0x589696['status']!==0xf4e+-0x2*0x116a+0x1386&&(_0x1283e3=!![]);}}}return {'fullLintOutput':_0x3f43e6,'hasFailures':_0x1283e3};}__name(runEslintBatches,'runEslintBatches');

export { buildEslintRulesOnce, executeCommandWithCombinedOutput, filterLintableFiles, formatSpawnFailureMessage, groupFilesByEslintConfig, isLintableFile, normalizePathForCli, resolveEslintConfigForFile, runEslintBatches };
