add fast-xml-parser dependency management
This commit is contained in:
@@ -22,7 +22,6 @@ const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const { execSync } = require('child_process');
|
||||
const { existsSync } = require('fs');
|
||||
const { XMLParser } = require('fast-xml-parser');
|
||||
|
||||
// Import xml-formatter (try multiple locations)
|
||||
let xmlFormatter;
|
||||
@@ -45,6 +44,27 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// Import fast-xml-parser (try multiple locations)
|
||||
let fastXmlParser;
|
||||
try {
|
||||
// Try local node_modules first
|
||||
fastXmlParser = require('fast-xml-parser');
|
||||
} catch (err) {
|
||||
try {
|
||||
// Try to find npm global prefix and load from there
|
||||
const npmPrefix = execSync('npm config get prefix', { encoding: 'utf-8' }).trim();
|
||||
const globalFastXmlParser = path.join(npmPrefix, 'node_modules', 'fast-xml-parser');
|
||||
fastXmlParser = require(globalFastXmlParser);
|
||||
} catch (err2) {
|
||||
console.error(
|
||||
'\n❌ Missing dependency: fast-xml-parser\n' +
|
||||
'Please install globally with: npm install -g fast-xml-parser\n' +
|
||||
'Or locally in the current directory with: npm install fast-xml-parser\n'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// CONFIGURATION
|
||||
// ============================================================================
|
||||
@@ -119,12 +139,10 @@ const XML_PARSE_OPTIONS = {
|
||||
trimValues: false,
|
||||
};
|
||||
|
||||
const xmlParser = new XMLParser(XML_PARSE_OPTIONS);
|
||||
|
||||
function parseXmlDocument(xmlString) {
|
||||
if (typeof xmlString !== 'string') return null;
|
||||
try {
|
||||
return xmlParser.parse(xmlString);
|
||||
return new fastXmlParser.XMLParser(XML_PARSE_OPTIONS).parse(xmlString);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user