diff --git a/package.json b/package.json index 078b317..b5660df 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "@oclif/core": "^4", "@oclif/multi-stage-output": "^0.8.30", "@oclif/table": "^0.5.1", - "@salesforce/core": "^8.24.0", + "@salesforce/core": "^8.26.3", "@salesforce/kit": "^3.2.4", - "@salesforce/metadata-enrichment": "^0.0.6", + "@salesforce/metadata-enrichment": "^0.0.8", "@salesforce/sf-plugins-core": "^12", "@salesforce/source-deploy-retrieve": "^12.0.1" }, @@ -23,7 +23,7 @@ "eslint-plugin-sf-plugin": "^1.20.33", "oclif": "^4.22.59", "ts-node": "^10.9.2", - "typescript": "^5.5.4" + "typescript": "^5.9.2" }, "engines": { "node": ">=20.0.0" diff --git a/src/commands/metadata/enrich.ts b/src/commands/metadata/enrich.ts index 87b85cf..75a1b52 100644 --- a/src/commands/metadata/enrich.ts +++ b/src/commands/metadata/enrich.ts @@ -18,7 +18,7 @@ import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Messages, SfProject } from '@salesforce/core'; import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core'; import { ComponentSetBuilder } from '@salesforce/source-deploy-retrieve'; -import { SourceComponentProcessor, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, EnrichmentStatus, FileProcessor } from '@salesforce/metadata-enrichment'; +import { SourceComponentProcessor, EnrichmentHandler, EnrichmentMetrics, EnrichmentRecords, FileProcessor } from '@salesforce/metadata-enrichment'; Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); const commandMessages = Messages.loadMessages('@salesforce/plugin-metadata-enrichment', 'metadata.enrich'); @@ -74,9 +74,7 @@ export default class MetadataEnrich extends SfCommand { metadataEntries, project.getPath() ); - enrichmentRecords.addSkippedComponents(componentsToSkip); - enrichmentRecords.updateWithStatus(componentsToSkip, EnrichmentStatus.SKIPPED); - enrichmentRecords.generateSkipReasons(componentsToSkip, projectSourceComponents); + enrichmentRecords.addRecords(componentsToSkip); const componentsEligibleToProcess = projectSourceComponents.filter((component) => { const componentName = component.fullName ?? component.name; diff --git a/test/unit/componentProcessor.test.ts b/test/unit/componentProcessor.test.ts index f185225..c8a0f97 100644 --- a/test/unit/componentProcessor.test.ts +++ b/test/unit/componentProcessor.test.ts @@ -53,7 +53,7 @@ describe('ComponentProcessor', () => { const result = SourceComponentProcessor.getComponentsToSkip(source, ['ApexClass:MyClass'], undefined); expect(result.size).to.be.greaterThan(0); const skipEntries = Array.from(result); - expect(skipEntries.some((r) => r.componentName === 'MyClass' && r.typeName === 'ApexClass')).to.be.true; + expect(skipEntries.some((r) => r.componentName === 'MyClass' && r.componentType.name === 'ApexClass')).to.be.true; }); it('should include LWC without xml in skip set', () => { diff --git a/test/unit/enrichmentRecords.test.ts b/test/unit/enrichmentRecords.test.ts index cb983dd..39ba276 100644 --- a/test/unit/enrichmentRecords.test.ts +++ b/test/unit/enrichmentRecords.test.ts @@ -48,7 +48,6 @@ describe('EnrichmentRecords', () => { expect(record.requestBody).to.not.be.null; expect(record.requestBody!.contentBundles).to.deep.equal([]); expect(record.requestBody!.metadataType).to.equal('Generic'); - expect(record.requestBody!.maxTokens).to.equal(50); }); it('should not create record when component has no name', () => { @@ -64,10 +63,17 @@ describe('EnrichmentRecords', () => { }); }); - describe('addSkippedComponents', () => { + describe('addRecords', () => { it('should add SKIPPED record for component not in recordSet', () => { const records = new EnrichmentRecords([]); - records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'SkippedCmp' }])); + records.addRecords(new Set([{ + componentName: 'SkippedCmp', + componentType: { name: 'LightningComponentBundle' } as SourceComponent['type'], + requestBody: { contentBundles: [], metadataType: 'Generic' }, + response: null, + message: null, + status: EnrichmentStatus.SKIPPED, + }])); expect(records.recordSet.size).to.equal(1); const record = Array.from(records.recordSet)[0]; expect(record.componentName).to.equal('SkippedCmp'); @@ -75,13 +81,19 @@ describe('EnrichmentRecords', () => { expect(record.requestBody).to.not.be.null; expect(record.requestBody!.contentBundles).to.deep.equal([]); expect(record.requestBody!.metadataType).to.equal('Generic'); - expect(record.requestBody!.maxTokens).to.equal(50); }); it('should not duplicate when record already exists', () => { const source = [createSourceComponent('Existing', 'LightningComponentBundle')]; const records = new EnrichmentRecords(source); - records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Existing' }])); + records.addRecords(new Set([{ + componentName: 'Existing', + componentType: { name: 'LightningComponentBundle' } as SourceComponent['type'], + requestBody: { contentBundles: [], metadataType: 'Generic' }, + response: null, + message: null, + status: EnrichmentStatus.SKIPPED, + }])); expect(records.recordSet.size).to.equal(1); }); }); @@ -189,39 +201,4 @@ describe('EnrichmentRecords', () => { }); }); - describe('generateSkipReasons', () => { - it('should set message for skipped record when component not in source', () => { - const records = new EnrichmentRecords([]); - records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Missing' }])); - records.generateSkipReasons(new Set([{ typeName: 'LightningComponentBundle', componentName: 'Missing' }]), []); - const record = Array.from(records.recordSet)[0]; - expect(record.message).to.equal('Component not found in project.'); - }); - - it('should set LWC-only message for skipped non-LWC component', () => { - const source = [createSourceComponent('MyClass', 'ApexClass')]; - const records = new EnrichmentRecords(source); - records.addSkippedComponents(new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }])); - records.updateWithStatus( - new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }]), - EnrichmentStatus.SKIPPED - ); - records.generateSkipReasons(new Set([{ typeName: 'ApexClass', componentName: 'MyClass' }]), source); - const record = Array.from(records.recordSet)[0]; - expect(record.message).to.equal('Component type \'ApexClass\' is not currently supported for enrichment.'); - }); - - it('should set lwc.configuration.not.found for LWC without xml', () => { - const source = [createSourceComponent('NoMeta', 'LightningComponentBundle')]; - const records = new EnrichmentRecords(source); - records.addSkippedComponents(new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }])); - records.updateWithStatus( - new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }]), - EnrichmentStatus.SKIPPED - ); - records.generateSkipReasons(new Set([{ typeName: 'LightningComponentBundle', componentName: 'NoMeta' }]), source); - const record = Array.from(records.recordSet)[0]; - expect(record.message).to.equal('The component\'s metadata configuration file doesn\'t exist.'); - }); - }); });