From 63ce40ecb3c98e423b5137b09c0d5e126df1bc62 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 25 Jun 2024 11:40:27 -0500 Subject: [PATCH] fix(perf): fewer adapter classes --- src/resolve/adapters/baseSourceAdapter.ts | 9 +-------- src/resolve/metadataResolver.ts | 23 ++++++++++++++++------- src/resolve/types.ts | 5 ----- test/resolve/registryTestUtil.ts | 1 - 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/resolve/adapters/baseSourceAdapter.ts b/src/resolve/adapters/baseSourceAdapter.ts index 2e232a1a9b..9f37ee05af 100644 --- a/src/resolve/adapters/baseSourceAdapter.ts +++ b/src/resolve/adapters/baseSourceAdapter.ts @@ -77,13 +77,6 @@ export abstract class BaseSourceAdapter implements SourceAdapter { return this.populate(path, component, isResolvingSource); } - /** - * Control whether metadata and content metadata files are allowed for an adapter. - */ - public allowMetadataWithContent(): boolean { - return this.metadataWithContent; - } - /** * If the path given to `getComponent` is the root metadata xml file for a component, * 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 { return folderMetadataXml; } - if (!this.allowMetadataWithContent()) { + if (!this.metadataWithContent) { return parseAsContentMetadataXml(this.type)(path); } } diff --git a/src/resolve/metadataResolver.ts b/src/resolve/metadataResolver.ts index 622f2c61f8..59cb6cef3f 100644 --- a/src/resolve/metadataResolver.ts +++ b/src/resolve/metadataResolver.ts @@ -125,16 +125,19 @@ export class MetadataResolver { } const type = resolveType(this.registry)(this.tree)(fsPath); if (type) { - const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore); // short circuit the component resolution unless this is a resolve for a // source path or allowed content-only path, otherwise the adapter // knows how to handle it - const shouldResolve = - isResolvingSource || - parseAsRootMetadataXml(fsPath) || - !parseAsContentMetadataXml(this.registry)(fsPath) || - !adapter.allowMetadataWithContent(); - return shouldResolve ? adapter.getComponent(fsPath, isResolvingSource) : undefined; + if ( + !isResolvingSource && + !parseAsRootMetadataXml(fsPath) && + parseAsContentMetadataXml(this.registry)(fsPath) && + typeAllowsMetadataWithContent(type) + ) { + return; + } + const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore); + return adapter.getComponent(fsPath, isResolvingSource); } if (isProbablyPackageManifest(this.tree)(fsPath)) return undefined; @@ -439,3 +442,9 @@ const pathIncludesDirName = * @param fsPath File path of a potential metadata xml file */ const parseAsRootMetadataXml = (fsPath: string): boolean => Boolean(parseMetadataXml(fsPath)); + +/** decomposed and default types are `false`, everything else is true */ +const typeAllowsMetadataWithContent = (type: MetadataType): boolean => + type.strategies?.adapter !== undefined && // another way of saying default + type.strategies.adapter !== 'decomposed' && + type.strategies.adapter !== 'default'; diff --git a/src/resolve/types.ts b/src/resolve/types.ts index 644dd1b7a4..6b1c23c8d0 100644 --- a/src/resolve/types.ts +++ b/src/resolve/types.ts @@ -52,9 +52,4 @@ export type SourceAdapter = { * @param isResolvingSource Whether the path to resolve is a single file */ getComponent(fsPath: SourcePath, isResolvingSource?: boolean): SourceComponent | undefined; - - /** - * Whether the adapter allows content-only metadata definitions. - */ - allowMetadataWithContent(): boolean; }; diff --git a/test/resolve/registryTestUtil.ts b/test/resolve/registryTestUtil.ts index 57dc23d8ef..ac9fbcb50c 100644 --- a/test/resolve/registryTestUtil.ts +++ b/test/resolve/registryTestUtil.ts @@ -48,7 +48,6 @@ export class RegistryTestUtil { } getAdapterStub.withArgs(entry.type).returns({ getComponent: (path: SourcePath) => componentMap[path], - allowMetadataWithContent: () => entry.allowContent ?? false, }); } }