Skip to content

Commit 586865e

Browse files
chore: cache more info
1 parent ebdff15 commit 586865e

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/resolve/sourceComponent.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class SourceComponent implements MetadataComponent {
5353
private readonly forceIgnore: ForceIgnore;
5454
private markedForDelete = false;
5555
private destructiveChangesType?: DestructiveChangesType;
56-
private pathContentMap = new Map<string, string>();
56+
private pathContentMap = new Map<string, JsonMap>();
5757

5858
public constructor(
5959
props: ComponentProperties,
@@ -188,35 +188,32 @@ export class SourceComponent implements MetadataComponent {
188188
public async parseXml<T extends JsonMap>(xmlFilePath?: string): Promise<T> {
189189
const xml = xmlFilePath ?? this.xml;
190190
if (xml) {
191-
let contents: string;
192191
if (this.pathContentMap.has(xml)) {
193-
contents = this.pathContentMap.get(xml) as string;
192+
return this.pathContentMap.get(xml) as T;
194193
} else {
195-
contents = (await this.tree.readFile(xml)).toString();
196-
this.pathContentMap.set(xml, contents);
194+
const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml];
195+
const contents = (await this.tree.readFile(xml)).toString();
196+
const value = this.parseAndValidateXML<T>(
197+
replacements ? await replacementIterations(contents, replacements) : contents,
198+
xml
199+
);
200+
this.pathContentMap.set(xml, value);
201+
return value;
197202
}
198-
199-
const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml];
200-
return this.parseAndValidateXML<T>(
201-
replacements ? await replacementIterations(contents, replacements) : contents,
202-
xml
203-
);
204203
}
205204
return {} as T;
206205
}
207206

208207
public parseXmlSync<T extends JsonMap>(xmlFilePath?: string): T {
209208
const xml = xmlFilePath ?? this.xml;
210209
if (xml) {
211-
let contents: string;
212210
if (this.pathContentMap.has(xml)) {
213-
contents = this.pathContentMap.get(xml) as string;
211+
return this.pathContentMap.get(xml) as T;
214212
} else {
215-
contents = this.tree.readFileSync(xml).toString();
213+
const contents = this.parseAndValidateXML(this.tree.readFileSync(xml).toString(), xml);
216214
this.pathContentMap.set(xml, contents);
215+
return contents as T;
217216
}
218-
219-
return this.parseAndValidateXML(contents, xml);
220217
}
221218
return {} as T;
222219
}
@@ -287,7 +284,7 @@ export class SourceComponent implements MetadataComponent {
287284
}
288285

289286
private parse<T extends JsonMap>(contents: string): T {
290-
const parsed = parser.parse(String(contents)) as T;
287+
const parsed = parser.parse(contents) as T;
291288
const [firstElement] = Object.keys(parsed);
292289
if (firstElement === this.type.name) {
293290
return parsed;

test/resolve/forceIgnore.test.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ describe('ForceIgnore', () => {
7171
expect(fi.accepts(join('force-app', 'main', 'default', 'classes'))).to.be.true;
7272
});
7373

74-
/**
75-
* TODO: Rework when approach to default patterns changes. We should be able
76-
* to generally test the defaults system.
77-
*/
7874
describe('Defaults with new parser', () => {
7975
let forceIgnore: ForceIgnore;
8076
const root = join('some', 'path');
@@ -84,7 +80,7 @@ describe('ForceIgnore', () => {
8480
forceIgnore = new ForceIgnore();
8581
});
8682

87-
// the example's index here is specific to the rules order in ForceIgnore.DEFAULT_IGNORE
83+
// these examples test the default behaviors
8884
const forceIgnoreExamples = ['abc.dup', '.xyz', 'package2-descriptor.json', 'package2-manifest.json'];
8985
forceIgnoreExamples.map((ignore) => {
9086
it(`Should ignore files starting with a ${ignore}`, () => {

0 commit comments

Comments
 (0)