Skip to content

Commit 63ce40e

Browse files
committed
fix(perf): fewer adapter classes
1 parent 84a0630 commit 63ce40e

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

src/resolve/adapters/baseSourceAdapter.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
7777
return this.populate(path, component, isResolvingSource);
7878
}
7979

80-
/**
81-
* Control whether metadata and content metadata files are allowed for an adapter.
82-
*/
83-
public allowMetadataWithContent(): boolean {
84-
return this.metadataWithContent;
85-
}
86-
8780
/**
8881
* If the path given to `getComponent` is the root metadata xml file for a component,
8982
* parse the name and return it. This is an optimization to not make a child adapter do
@@ -114,7 +107,7 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
114107
return folderMetadataXml;
115108
}
116109

117-
if (!this.allowMetadataWithContent()) {
110+
if (!this.metadataWithContent) {
118111
return parseAsContentMetadataXml(this.type)(path);
119112
}
120113
}

src/resolve/metadataResolver.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ export class MetadataResolver {
125125
}
126126
const type = resolveType(this.registry)(this.tree)(fsPath);
127127
if (type) {
128-
const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore);
129128
// short circuit the component resolution unless this is a resolve for a
130129
// source path or allowed content-only path, otherwise the adapter
131130
// knows how to handle it
132-
const shouldResolve =
133-
isResolvingSource ||
134-
parseAsRootMetadataXml(fsPath) ||
135-
!parseAsContentMetadataXml(this.registry)(fsPath) ||
136-
!adapter.allowMetadataWithContent();
137-
return shouldResolve ? adapter.getComponent(fsPath, isResolvingSource) : undefined;
131+
if (
132+
!isResolvingSource &&
133+
!parseAsRootMetadataXml(fsPath) &&
134+
parseAsContentMetadataXml(this.registry)(fsPath) &&
135+
typeAllowsMetadataWithContent(type)
136+
) {
137+
return;
138+
}
139+
const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore);
140+
return adapter.getComponent(fsPath, isResolvingSource);
138141
}
139142

140143
if (isProbablyPackageManifest(this.tree)(fsPath)) return undefined;
@@ -439,3 +442,9 @@ const pathIncludesDirName =
439442
* @param fsPath File path of a potential metadata xml file
440443
*/
441444
const parseAsRootMetadataXml = (fsPath: string): boolean => Boolean(parseMetadataXml(fsPath));
445+
446+
/** decomposed and default types are `false`, everything else is true */
447+
const typeAllowsMetadataWithContent = (type: MetadataType): boolean =>
448+
type.strategies?.adapter !== undefined && // another way of saying default
449+
type.strategies.adapter !== 'decomposed' &&
450+
type.strategies.adapter !== 'default';

src/resolve/types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,4 @@ export type SourceAdapter = {
5252
* @param isResolvingSource Whether the path to resolve is a single file
5353
*/
5454
getComponent(fsPath: SourcePath, isResolvingSource?: boolean): SourceComponent | undefined;
55-
56-
/**
57-
* Whether the adapter allows content-only metadata definitions.
58-
*/
59-
allowMetadataWithContent(): boolean;
6055
};

test/resolve/registryTestUtil.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export class RegistryTestUtil {
4848
}
4949
getAdapterStub.withArgs(entry.type).returns({
5050
getComponent: (path: SourcePath) => componentMap[path],
51-
allowMetadataWithContent: () => entry.allowContent ?? false,
5251
});
5352
}
5453
}

0 commit comments

Comments
 (0)