Skip to content

Commit

Permalink
fix: preserve xml comments in decomposed files
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 19, 2024
1 parent 5b9f10d commit 54c60d4
Show file tree
Hide file tree
Showing 44 changed files with 1,717 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common/constants.ts
Expand Up @@ -11,3 +11,4 @@ export const META_XML_SUFFIX = '-meta.xml';
export const XML_DECL = '<?xml version="1.0" encoding="UTF-8"?>\n';
export const XML_NS_URL = 'http://soap.sforce.com/2006/04/metadata';
export const XML_NS_KEY = '@_xmlns';
export const XML_COMMENT_PROP_NAME = '#xml__comment';
3 changes: 2 additions & 1 deletion src/convert/streams.ts
Expand Up @@ -15,7 +15,7 @@ import { XMLBuilder } from 'fast-xml-parser';
import { Logger } from '@salesforce/core';
import { SourceComponent } from '../resolve/sourceComponent';
import { SourcePath } from '../common/types';
import { XML_DECL } from '../common/constants';
import { XML_COMMENT_PROP_NAME, XML_DECL } from '../common/constants';
import { ComponentSet } from '../collections/componentSet';
import { RegistryAccess } from '../registry/registryAccess';
import { ensureFileExists } from '../utils/fileSystemHandler';
Expand Down Expand Up @@ -255,6 +255,7 @@ export class JsToXml extends Readable {
indentBy: ' ',
ignoreAttributes: false,
cdataPropName: '__cdata',
commentPropName: XML_COMMENT_PROP_NAME,
});

const builtXml = String(builder.build(this.xmlObject));
Expand Down
2 changes: 2 additions & 0 deletions src/resolve/sourceComponent.ts
Expand Up @@ -9,6 +9,7 @@ import { Messages, SfError } from '@salesforce/core';
import { XMLParser, XMLValidator } from 'fast-xml-parser';
import { get, getString, JsonMap } from '@salesforce/ts-types';
import { ensureArray } from '@salesforce/kit';
import { XML_COMMENT_PROP_NAME } from '../common/constants';
import { getXmlElement } from '../utils/decomposed';
import { baseName, baseWithoutSuffixes, parseMetadataXml, calculateRelativePath } from '../utils/path';
import { replacementIterations } from '../convert/replacements';
Expand Down Expand Up @@ -271,6 +272,7 @@ export class SourceComponent implements MetadataComponent {
cdataPropName: '__cdata',
ignoreDeclaration: true,
numberParseOptions: { leadingZeros: false, hex: false },
commentPropName: XML_COMMENT_PROP_NAME,
});
const parsed = parser.parse(String(contents)) as T;
const [firstElement] = Object.keys(parsed);
Expand Down
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObjectTranslation xmlns="http://soap.sforce.com/2006/04/metadata">
<fields>
<help>
<!-- Please choose an option -->
</help>
<label>
<!-- Example -->
</label>
<name>Example__c</name>
<picklistValues>
<masterLabel>One</masterLabel>
<translation>
<!-- One -->
</translation>
</picklistValues>
<picklistValues>
<masterLabel>Two</masterLabel>
<translation>
<!-- Two -->
</translation>
</picklistValues>
</fields>
</CustomObjectTranslation>

2 comments on commit 54c60d4

@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: 54c60d4 Previous: da990b2 Ratio
eda-componentSetCreate-linux 183 ms 184 ms 0.99
eda-sourceToMdapi-linux 1912 ms 1969 ms 0.97
eda-sourceToZip-linux 1458 ms 1500 ms 0.97
eda-mdapiToSource-linux 2720 ms 2756 ms 0.99
lotsOfClasses-componentSetCreate-linux 381 ms 465 ms 0.82
lotsOfClasses-sourceToMdapi-linux 3462 ms 3526 ms 0.98
lotsOfClasses-sourceToZip-linux 3132 ms 3185 ms 0.98
lotsOfClasses-mdapiToSource-linux 3356 ms 3353 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 640 ms 643 ms 1.00
lotsOfClassesOneDir-sourceToMdapi-linux 6220 ms 6281 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5856 ms 5960 ms 0.98
lotsOfClassesOneDir-mdapiToSource-linux 6094 ms 6265 ms 0.97

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: 54c60d4 Previous: da990b2 Ratio
eda-componentSetCreate-win32 379 ms 385 ms 0.98
eda-sourceToMdapi-win32 3524 ms 3506 ms 1.01
eda-sourceToZip-win32 2156 ms 2134 ms 1.01
eda-mdapiToSource-win32 5731 ms 5730 ms 1.00
lotsOfClasses-componentSetCreate-win32 827 ms 907 ms 0.91
lotsOfClasses-sourceToMdapi-win32 7465 ms 7475 ms 1.00
lotsOfClasses-sourceToZip-win32 4841 ms 4727 ms 1.02
lotsOfClasses-mdapiToSource-win32 7482 ms 7476 ms 1.00
lotsOfClassesOneDir-componentSetCreate-win32 1535 ms 1504 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-win32 13774 ms 13704 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 8662 ms 8714 ms 0.99
lotsOfClassesOneDir-mdapiToSource-win32 13263 ms 13828 ms 0.96

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

Please sign in to comment.