Skip to content

Commit

Permalink
fix: hacky correction to xml comment newline/indent behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 30, 2024
1 parent cd5ce83 commit 40b6eef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/convert/streams.ts
Expand Up @@ -257,14 +257,16 @@ export class JsToXml extends Readable {
cdataPropName: '__cdata',
commentPropName: XML_COMMENT_PROP_NAME,
});

const builtXml = String(builder.build(this.xmlObject));
const xmlContent = XML_DECL.concat(handleSpecialEntities(builtXml));
const xmlContent = correctComments(XML_DECL.concat(handleSpecialEntities(builtXml)));
this.push(xmlContent);
this.push(null);
}
}

/** xmlBuilder likes to add newline and indent before/after the comment (hypothesis: it uses `<` as a hint to newlint/indent) */
const correctComments = (xml: string): string =>
xml.includes('<!--') ? xml.replace(/\s+<!--(.*?)-->\s+/g, '<!--$1-->') : xml;
/**
* use this function to handle special html entities.
* XmlBuilder will otherwise replace ex: `&#160;` with `'&amp;#160;'` (escape the &)
Expand Down
Expand Up @@ -2,24 +2,16 @@
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata">
<gender></gender>
<fields>
<help>
<!-- Please choose an option -->
</help>
<label>
<!-- Example -->
</label>
<help><!-- Please choose an option --></help>
<label><!-- Example --></label>
<name>Example__c</name>
<picklistValues>
<masterLabel>One</masterLabel>
<translation>
<!-- One -->
</translation>
<translation><!-- One --></translation>
</picklistValues>
<picklistValues>
<masterLabel>Two</masterLabel>
<translation>
<!-- Two -->
</translation>
<translation><!-- Two --></translation>
</picklistValues>
</fields>
</CustomObjectTranslation>
@@ -1,22 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomFieldTranslation xmlns="http://soap.sforce.com/2006/04/metadata">
<help>
<!-- Please choose an option -->
</help>
<label>
<!-- Example -->
</label>
<help><!-- Please choose an option --></help>
<label><!-- Example --></label>
<name>Example__c</name>
<picklistValues>
<masterLabel>One</masterLabel>
<translation>
<!-- One -->
</translation>
<translation><!-- One --></translation>
</picklistValues>
<picklistValues>
<masterLabel>Two</masterLabel>
<translation>
<!-- Two -->
</translation>
<translation><!-- Two --></translation>
</picklistValues>
</CustomFieldTranslation>

2 comments on commit 40b6eef

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 40b6eef Previous: cd5ce83 Ratio
eda-componentSetCreate-linux 178 ms 183 ms 0.97
eda-sourceToMdapi-linux 1949 ms 2025 ms 0.96
eda-sourceToZip-linux 1409 ms 1497 ms 0.94
eda-mdapiToSource-linux 2917 ms 2831 ms 1.03
lotsOfClasses-componentSetCreate-linux 365 ms 473 ms 0.77
lotsOfClasses-sourceToMdapi-linux 3706 ms 3712 ms 1.00
lotsOfClasses-sourceToZip-linux 3064 ms 3146 ms 0.97
lotsOfClasses-mdapiToSource-linux 3496 ms 3559 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 629 ms 658 ms 0.96
lotsOfClassesOneDir-sourceToMdapi-linux 6549 ms 6610 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5825 ms 5855 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6425 ms 6424 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 40b6eef Previous: cd5ce83 Ratio
eda-componentSetCreate-win32 379 ms 378 ms 1.00
eda-sourceToMdapi-win32 3456 ms 3484 ms 0.99
eda-sourceToZip-win32 2151 ms 2096 ms 1.03
eda-mdapiToSource-win32 5614 ms 5633 ms 1.00
lotsOfClasses-componentSetCreate-win32 826 ms 883 ms 0.94
lotsOfClasses-sourceToMdapi-win32 7460 ms 7480 ms 1.00
lotsOfClasses-sourceToZip-win32 4606 ms 4649 ms 0.99
lotsOfClasses-mdapiToSource-win32 7411 ms 7487 ms 0.99
lotsOfClassesOneDir-componentSetCreate-win32 1482 ms 1470 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-win32 13684 ms 13747 ms 1.00
lotsOfClassesOneDir-sourceToZip-win32 8525 ms 8610 ms 0.99
lotsOfClassesOneDir-mdapiToSource-win32 13554 ms 13520 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.