Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: preserve xml comments in decomposed files #1288

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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>