Merge pull request #7708 from julioz/file-location-custom-parser

Use CatalogProcessorParser to read file location
This commit is contained in:
Patrik Oldsberg
2021-10-20 19:49:38 +02:00
committed by GitHub
4 changed files with 22 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Take CatalogParser in account when processing file locations.
+1
View File
@@ -966,6 +966,7 @@ export class FileReaderProcessor implements CatalogProcessor {
location: LocationSpec,
optional: boolean,
emit: CatalogProcessorEmit,
parser: CatalogProcessorParser,
): Promise<boolean>;
}
@@ -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<CatalogProcessorResult>(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<CatalogProcessorResult>(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);
@@ -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<boolean> {
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);
}