diff --git a/.changeset/hip-pens-love.md b/.changeset/hip-pens-love.md new file mode 100644 index 0000000000..d1549789bf --- /dev/null +++ b/.changeset/hip-pens-love.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Take CatalogParser in account when processing file locations. diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 6b7d966b28..a3860d2dca 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -966,6 +966,7 @@ export class FileReaderProcessor implements CatalogProcessor { location: LocationSpec, optional: boolean, emit: CatalogProcessorEmit, + parser: CatalogProcessorParser, ): Promise; } diff --git a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts index 8a5f202e5e..c2cce66bc6 100644 --- a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.test.ts @@ -21,6 +21,7 @@ import { CatalogProcessorResult, } from './types'; import path from 'path'; +import { defaultEntityDataParser } from './util/parse'; describe('FileReaderProcessor', () => { const fixturesRoot = path.join(__dirname, '__fixtures__/fileReaderProcessor'); @@ -33,7 +34,7 @@ describe('FileReaderProcessor', () => { }; const generated = (await new Promise(emit => - processor.readLocation(spec, false, emit), + processor.readLocation(spec, false, emit, defaultEntityDataParser), )) as CatalogProcessorEntityResult; expect(generated.type).toBe('entity'); @@ -49,7 +50,7 @@ describe('FileReaderProcessor', () => { }; const generated = (await new Promise(emit => - processor.readLocation(spec, false, emit), + processor.readLocation(spec, false, emit, defaultEntityDataParser), )) as CatalogProcessorErrorResult; expect(generated.type).toBe('error'); @@ -69,6 +70,7 @@ describe('FileReaderProcessor', () => { { type: 'file', target: `${path.join(fixturesRoot, '**', '*.yaml')}` }, false, emit, + defaultEntityDataParser, ); expect(emit).toBeCalledTimes(2); diff --git a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.ts index 5f6e739bdd..9ff3f52ba0 100644 --- a/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/FileReaderProcessor.ts @@ -20,8 +20,11 @@ import g from 'glob'; import path from 'path'; import { promisify } from 'util'; import * as result from './results'; -import { CatalogProcessor, CatalogProcessorEmit } from './types'; -import { parseEntityYaml } from './util/parse'; +import { + CatalogProcessor, + CatalogProcessorEmit, + CatalogProcessorParser, +} from './types'; const glob = promisify(g); @@ -30,6 +33,7 @@ export class FileReaderProcessor implements CatalogProcessor { location: LocationSpec, optional: boolean, emit: CatalogProcessorEmit, + parser: CatalogProcessorParser, ): Promise { if (location.type !== 'file') { return false; @@ -44,9 +48,12 @@ export class FileReaderProcessor implements CatalogProcessor { // The normalize converts to native slashes; the glob library returns // forward slashes even on windows - for (const parseResult of parseEntityYaml(data, { - type: 'file', - target: path.normalize(fileMatch), + for await (const parseResult of parser({ + data: data, + location: { + type: 'file', + target: path.normalize(fileMatch), + }, })) { emit(parseResult); }