Removed type list from cli-node
Signed-off-by: Harrison Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -14,11 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BackstagePackageFeatureType, PackageRole } from '@backstage/cli-node';
|
||||
import { PackageRole } from '@backstage/cli-node';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { Project } from 'ts-morph';
|
||||
import { EntryPoint } from '../entryPoints';
|
||||
import { getDistTypeRoot } from '../typeDistProject';
|
||||
import {
|
||||
getDistTypeRoot,
|
||||
BackstagePackageFeatureType,
|
||||
} from '../typeDistProject';
|
||||
|
||||
const mockEntryPoint = {
|
||||
mount: '.',
|
||||
|
||||
@@ -14,9 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { BackstagePackageFeatureType, PackageRole } from '@backstage/cli-node';
|
||||
import { PackageRole } from '@backstage/cli-node';
|
||||
import createFeatureEnvironment from './__testUtils__/createFeatureEnvironment';
|
||||
import { getEntryPointDefaultFeatureType } from './typeDistProject';
|
||||
import {
|
||||
getEntryPointDefaultFeatureType,
|
||||
BackstagePackageFeatureType,
|
||||
} from './typeDistProject';
|
||||
|
||||
describe('typeDistProject', () => {
|
||||
describe('for package role', () => {
|
||||
@@ -67,30 +70,17 @@ describe('typeDistProject', () => {
|
||||
|
||||
describe('for feature $$type', () => {
|
||||
// This Record makes sure we're checking all feature types
|
||||
const featureTypes: Record<BackstagePackageFeatureType, boolean> = {
|
||||
// Allowed
|
||||
'@backstage/BackendFeature': true,
|
||||
'@backstage/BackstagePlugin': true,
|
||||
'@backstage/FrontendPlugin': true,
|
||||
'@backstage/FrontendModule': true,
|
||||
// Disallowed
|
||||
'@backstage/BackendFeatureFactory': false,
|
||||
'@backstage/BackstageCredentials': false,
|
||||
'@backstage/Extension': false,
|
||||
'@backstage/ExtensionDataRef': false,
|
||||
'@backstage/ExtensionDataValue': false,
|
||||
'@backstage/ExtensionDefinition': false,
|
||||
'@backstage/ExtensionInput': false,
|
||||
'@backstage/ExtensionOverrides': false,
|
||||
'@backstage/ExtensionPoint': false,
|
||||
'@backstage/ExternalRouteRef': false,
|
||||
'@backstage/RouteRef': false,
|
||||
'@backstage/ServiceRef': false,
|
||||
'@backstage/SubRouteRef': false,
|
||||
'@backstage/TranslationMessages': false,
|
||||
'@backstage/TranslationRef': false,
|
||||
'@backstage/TranslationResource': false,
|
||||
};
|
||||
const featureTypes: Record<BackstagePackageFeatureType | string, boolean> =
|
||||
{
|
||||
// Allowed
|
||||
'@backstage/BackendFeature': true,
|
||||
'@backstage/BackstagePlugin': true,
|
||||
'@backstage/FrontendPlugin': true,
|
||||
'@backstage/FrontendModule': true,
|
||||
// Disallowed
|
||||
'@backstage/Extension': false,
|
||||
'@backstage/RouteRef': false,
|
||||
};
|
||||
|
||||
const allowedFeatureTypes = Object.keys(featureTypes).filter(
|
||||
$$type => featureTypes[$$type as BackstagePackageFeatureType],
|
||||
|
||||
@@ -14,12 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
import {
|
||||
BackstagePackageFeatureType,
|
||||
isValidPackageFeatureType,
|
||||
PackageGraph,
|
||||
PackageRole,
|
||||
} from '@backstage/cli-node';
|
||||
import { PackageGraph, PackageRole } from '@backstage/cli-node';
|
||||
import { builtinModules } from 'module';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { Project, SourceFile, SyntaxKind, ts, Type } from 'ts-morph';
|
||||
@@ -134,12 +129,14 @@ const targetPackageRoles: PackageRole[] = [
|
||||
|
||||
// A list of the feature types we want to extract from the project
|
||||
// and include in the metadata
|
||||
const targetFeatureTypes: BackstagePackageFeatureType[] = [
|
||||
const targetFeatureTypes = [
|
||||
'@backstage/BackendFeature',
|
||||
'@backstage/BackstagePlugin',
|
||||
'@backstage/FrontendPlugin',
|
||||
'@backstage/FrontendModule',
|
||||
];
|
||||
] as const;
|
||||
|
||||
export type BackstagePackageFeatureType = (typeof targetFeatureTypes)[number];
|
||||
|
||||
export const getEntryPointDefaultFeatureType = (
|
||||
role: PackageRole,
|
||||
@@ -157,7 +154,7 @@ export const getEntryPointDefaultFeatureType = (
|
||||
project.addSourceFileAtPath(dtsPath),
|
||||
);
|
||||
|
||||
if (isTargetFeatureType(defaultFeatureType)) {
|
||||
if (defaultFeatureType) {
|
||||
return defaultFeatureType;
|
||||
}
|
||||
}
|
||||
@@ -165,18 +162,6 @@ export const getEntryPointDefaultFeatureType = (
|
||||
return null;
|
||||
};
|
||||
|
||||
// Condition for a package role matches a target package role
|
||||
function isTargetPackageRole(role: PackageRole): boolean {
|
||||
return !!role && targetPackageRoles.includes(role);
|
||||
}
|
||||
|
||||
// Returns whether an export is a valid Backstage package feature type
|
||||
function isTargetFeatureType(
|
||||
type: BackstagePackageFeatureType | null,
|
||||
): boolean {
|
||||
return !!type && targetFeatureTypes.includes(type);
|
||||
}
|
||||
|
||||
// Returns all exports (default and named) from an entry point
|
||||
// that are valid Backstage package features
|
||||
function getSourceFileDefaultFeatureType(
|
||||
@@ -230,7 +215,7 @@ function getBackstagePackageFeature$$TypeFromType(
|
||||
?.getText()
|
||||
.match(/(?<type>@backstage\/\w+)/)?.groups?.type;
|
||||
|
||||
if ($$type && isValidPackageFeatureType($$type)) {
|
||||
if ($$type && isTargetFeatureType($$type)) {
|
||||
return $$type;
|
||||
}
|
||||
}
|
||||
@@ -238,3 +223,17 @@ function getBackstagePackageFeature$$TypeFromType(
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Condition for a package role matches a target package role
|
||||
function isTargetPackageRole(role: PackageRole): boolean {
|
||||
return !!role && targetPackageRoles.includes(role);
|
||||
}
|
||||
|
||||
// Returns whether an export is a valid Backstage package feature type
|
||||
function isTargetFeatureType(
|
||||
type: string | BackstagePackageFeatureType,
|
||||
): type is BackstagePackageFeatureType {
|
||||
return (
|
||||
!!type && targetFeatureTypes.includes(type as BackstagePackageFeatureType)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user