Skip to content

Commit

Permalink
fix: handle string replacements for individual custom labels (#1257)
Browse files Browse the repository at this point in the history
* fix: handle string replacements for individual custom labels

* test: add nut to test single label replacement
  • Loading branch information
shetzel authored Mar 19, 2024
1 parent 570452a commit 70571e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/convert/replacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class ReplacementMarkingStream extends Transform {
if (!chunk.isMarkedForDelete() && this.replacementConfigs?.length) {
try {
chunk.replacements = await getReplacements(chunk, this.replacementConfigs);
if (chunk.replacements && chunk.parent && chunk.type.name === 'CustomLabel') {
// Set replacements on the parent of a CustomLabel as well so that recomposing
// doesn't use the non-replaced content from parent cache.
// See RecompositionFinalizer.recompose() in convertContext.ts
chunk.parent.replacements = chunk.replacements;
}
} catch (e) {
if (!(e instanceof Error)) {
throw e;
Expand Down
25 changes: 24 additions & 1 deletion test/nuts/local/replacements/replacementsLabels.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,37 @@ describe('e2e replacements test (customLabels)', () => {
await extractZip(zipBuffer, path.join(session.project.dir, 'unzipped'));
});

it('label replacements as expected', async () => {
it('label replacements as expected (CustomLabels)', async () => {
const labelsContents = await fs.promises.readFile(
path.join(session.project.dir, 'unzipped', 'labels', 'CustomLabels.labels'),
'utf8'
);
expect(labelsContents).to.not.include('original');
expect(labelsContents).to.include('REPLACED_LABEL');
});

it('label replacements as expected (CustomLabel)', async () => {
const converter = new MetadataConverter();
const cs = await ComponentSetBuilder.build({
metadata: {
metadataEntries: ['CustomLabel:Docs_CabinetId'],
directoryPaths: [path.join(session.project.dir, 'force-app')],
},
});
const { zipBuffer } = await converter.convert(cs, 'metadata', {
type: 'zip',
});
assert(zipBuffer, 'zipBuffer should be defined');
// extract zip files
await extractZip(zipBuffer, path.join(session.project.dir, 'unzipped2'));
const labelsContents = await fs.promises.readFile(
path.join(session.project.dir, 'unzipped2', 'labels', 'CustomLabels.labels'),
'utf8'
);
expect(labelsContents).to.not.include('original');
expect(labelsContents).to.include('REPLACED_LABEL');
});

it('class replacements as expected', async () => {
const classContents = await fs.promises.readFile(
path.join(session.project.dir, 'unzipped', 'classes', 'replaceStuff.cls'),
Expand Down

0 comments on commit 70571e8

Please sign in to comment.