Skip to content

Commit

Permalink
Make sure destructiveChanges.xml does not contains package.xml element (
Browse files Browse the repository at this point in the history
#113)

Implement a post processing filtering to exclude element in
destructiveChanges.xml also present in package.xml
  • Loading branch information
scolladon authored Apr 2, 2021
1 parent 0362837 commit 9729e2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions __tests__/functional.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const lines = [
'D force-app/main/default/staticressources/Added/deleted.png',
'A force-app/main/default/documents/Added/doc.document',
'A force-app/main/default/lwc/Added/component.js`',
'D force-app/main/sample/objects/Account/fields/changed.field-meta.xml',
]

describe(`test if the appli`, () => {
Expand Down Expand Up @@ -65,4 +66,22 @@ describe(`test if the appli`, () => {
}).warnings
).not.toHaveLength(0)
})

test('do not generate destructiveChanges.xml and package.xml with same element', () => {
child_process.spawnSync.mockImplementation(() => ({
stdout: lines.join(os.EOL),
}))
const work = app({
output: 'output',
repo: '',
to: 'test',
apiVersion: '46',
generateDelta: true,
})

expect(work.diffs.package.fields).toContain('Account.changed')
expect(work.diffs.destructiveChanges.fields).not.toContain(
'Account.changed'
)
})
})
14 changes: 14 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const treatDiff = (config, lines, metadata) => {
}

const treatPackages = (dcJson, config, metadata) => {
cleanPackages(dcJson)
const pc = new PackageConstructor(config, metadata)
;[
{
Expand All @@ -91,3 +92,16 @@ const treatPackages = (dcJson, config, metadata) => {
fse.outputFileSync(location, op.xmlContent)
})
}

const cleanPackages = dcJson => {
const additive = dcJson[PACKAGE_FILE_NAME]
const destructive = dcJson[DESTRUCTIVE_CHANGES_FILE_NAME]
Object.keys(additive)
.filter(type => Object.prototype.hasOwnProperty.call(destructive, type))
.forEach(
type =>
(destructive[type] = new Set(
[...destructive[type]].filter(element => !additive[type].has(element))
))
)
}

0 comments on commit 9729e2f

Please sign in to comment.