diff --git a/src/resolve/sourceComponent.ts b/src/resolve/sourceComponent.ts index c4e059e33..bc3efec12 100644 --- a/src/resolve/sourceComponent.ts +++ b/src/resolve/sourceComponent.ts @@ -53,7 +53,7 @@ export class SourceComponent implements MetadataComponent { private readonly forceIgnore: ForceIgnore; private markedForDelete = false; private destructiveChangesType?: DestructiveChangesType; - private pathContentMap = new Map(); + private pathContentMap = new Map(); public constructor( props: ComponentProperties, @@ -188,19 +188,18 @@ export class SourceComponent implements MetadataComponent { public async parseXml(xmlFilePath?: string): Promise { const xml = xmlFilePath ?? this.xml; if (xml) { - let contents: string; if (this.pathContentMap.has(xml)) { - contents = this.pathContentMap.get(xml) as string; + return this.pathContentMap.get(xml) as T; } else { - contents = (await this.tree.readFile(xml)).toString(); - this.pathContentMap.set(xml, contents); + const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml]; + const contents = (await this.tree.readFile(xml)).toString(); + const value = this.parseAndValidateXML( + replacements ? await replacementIterations(contents, replacements) : contents, + xml + ); + this.pathContentMap.set(xml, value); + return value; } - - const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml]; - return this.parseAndValidateXML( - replacements ? await replacementIterations(contents, replacements) : contents, - xml - ); } return {} as T; } @@ -208,15 +207,13 @@ export class SourceComponent implements MetadataComponent { public parseXmlSync(xmlFilePath?: string): T { const xml = xmlFilePath ?? this.xml; if (xml) { - let contents: string; if (this.pathContentMap.has(xml)) { - contents = this.pathContentMap.get(xml) as string; + return this.pathContentMap.get(xml) as T; } else { - contents = this.tree.readFileSync(xml).toString(); + const contents = this.parseAndValidateXML(this.tree.readFileSync(xml).toString(), xml); this.pathContentMap.set(xml, contents); + return contents as T; } - - return this.parseAndValidateXML(contents, xml); } return {} as T; } @@ -287,7 +284,7 @@ export class SourceComponent implements MetadataComponent { } private parse(contents: string): T { - const parsed = parser.parse(String(contents)) as T; + const parsed = parser.parse(contents) as T; const [firstElement] = Object.keys(parsed); if (firstElement === this.type.name) { return parsed; diff --git a/test/resolve/forceIgnore.test.ts b/test/resolve/forceIgnore.test.ts index 007ffbd24..f801a1d46 100644 --- a/test/resolve/forceIgnore.test.ts +++ b/test/resolve/forceIgnore.test.ts @@ -71,10 +71,6 @@ describe('ForceIgnore', () => { expect(fi.accepts(join('force-app', 'main', 'default', 'classes'))).to.be.true; }); - /** - * TODO: Rework when approach to default patterns changes. We should be able - * to generally test the defaults system. - */ describe('Defaults with new parser', () => { let forceIgnore: ForceIgnore; const root = join('some', 'path'); @@ -84,7 +80,7 @@ describe('ForceIgnore', () => { forceIgnore = new ForceIgnore(); }); - // the example's index here is specific to the rules order in ForceIgnore.DEFAULT_IGNORE + // these examples test the default behaviors const forceIgnoreExamples = ['abc.dup', '.xyz', 'package2-descriptor.json', 'package2-manifest.json']; forceIgnoreExamples.map((ignore) => { it(`Should ignore files starting with a ${ignore}`, () => {