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: handle string replacements for individual custom labels #1257

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading