Removed type list from cli-node
Signed-off-by: Harrison Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -12,15 +12,6 @@ export type BackstagePackage = {
|
||||
packageJson: BackstagePackageJson;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type BackstagePackageFeature = {
|
||||
path?: string;
|
||||
type: BackstagePackageFeatureType;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type BackstagePackageFeatureType = (typeof packageFeatureTypes)[number];
|
||||
|
||||
// @public
|
||||
export interface BackstagePackageJson {
|
||||
// (undocumented)
|
||||
@@ -31,7 +22,6 @@ export interface BackstagePackageJson {
|
||||
pluginId?: string | null;
|
||||
pluginPackage?: string;
|
||||
pluginPackages?: string[];
|
||||
features?: BackstagePackageFeature[];
|
||||
};
|
||||
// (undocumented)
|
||||
bundled?: boolean;
|
||||
@@ -98,31 +88,6 @@ export class GitUtils {
|
||||
// @public
|
||||
export function isMonoRepo(): Promise<boolean>;
|
||||
|
||||
// @public
|
||||
export const isValidPackageFeatureType: (
|
||||
value: string,
|
||||
) => value is
|
||||
| '@backstage/TranslationResource'
|
||||
| '@backstage/TranslationMessages'
|
||||
| '@backstage/TranslationRef'
|
||||
| '@backstage/RouteRef'
|
||||
| '@backstage/SubRouteRef'
|
||||
| '@backstage/ExternalRouteRef'
|
||||
| '@backstage/ExtensionDataValue'
|
||||
| '@backstage/ExtensionDataRef'
|
||||
| '@backstage/ExtensionInput'
|
||||
| '@backstage/ExtensionDefinition'
|
||||
| '@backstage/Extension'
|
||||
| '@backstage/ExtensionOverrides'
|
||||
| '@backstage/FrontendPlugin'
|
||||
| '@backstage/BackstagePlugin'
|
||||
| '@backstage/FrontendModule'
|
||||
| '@backstage/BackendFeatureFactory'
|
||||
| '@backstage/BackendFeature'
|
||||
| '@backstage/ServiceRef'
|
||||
| '@backstage/BackstageCredentials'
|
||||
| '@backstage/ExtensionPoint';
|
||||
|
||||
// @public
|
||||
export class Lockfile {
|
||||
createSimplifiedDependencyGraph(): Map<string, Set<string>>;
|
||||
@@ -144,30 +109,6 @@ export type LockfileDiffEntry = {
|
||||
range: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export const packageFeatureTypes: readonly [
|
||||
'@backstage/BackendFeature',
|
||||
'@backstage/BackendFeatureFactory',
|
||||
'@backstage/BackstageCredentials',
|
||||
'@backstage/BackstagePlugin',
|
||||
'@backstage/Extension',
|
||||
'@backstage/ExtensionDataRef',
|
||||
'@backstage/ExtensionDataValue',
|
||||
'@backstage/ExtensionDefinition',
|
||||
'@backstage/ExtensionInput',
|
||||
'@backstage/ExtensionOverrides',
|
||||
'@backstage/ExtensionPoint',
|
||||
'@backstage/ExternalRouteRef',
|
||||
'@backstage/FrontendPlugin',
|
||||
'@backstage/FrontendModule',
|
||||
'@backstage/RouteRef',
|
||||
'@backstage/ServiceRef',
|
||||
'@backstage/SubRouteRef',
|
||||
'@backstage/TranslationMessages',
|
||||
'@backstage/TranslationRef',
|
||||
'@backstage/TranslationResource',
|
||||
];
|
||||
|
||||
// @public
|
||||
export class PackageGraph extends Map<string, PackageGraphNode> {
|
||||
collectPackageNames(
|
||||
|
||||
@@ -22,52 +22,6 @@ import { GitUtils } from '../git';
|
||||
import { Lockfile } from './Lockfile';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* All Backstage system features
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const packageFeatureTypes = [
|
||||
'@backstage/BackendFeature',
|
||||
'@backstage/BackendFeatureFactory',
|
||||
'@backstage/BackstageCredentials',
|
||||
'@backstage/BackstagePlugin',
|
||||
'@backstage/Extension',
|
||||
'@backstage/ExtensionDataRef',
|
||||
'@backstage/ExtensionDataValue',
|
||||
'@backstage/ExtensionDefinition',
|
||||
'@backstage/ExtensionInput',
|
||||
'@backstage/ExtensionOverrides',
|
||||
'@backstage/ExtensionPoint',
|
||||
'@backstage/ExternalRouteRef',
|
||||
'@backstage/FrontendPlugin',
|
||||
'@backstage/FrontendModule',
|
||||
'@backstage/RouteRef',
|
||||
'@backstage/ServiceRef',
|
||||
'@backstage/SubRouteRef',
|
||||
'@backstage/TranslationMessages',
|
||||
'@backstage/TranslationRef',
|
||||
'@backstage/TranslationResource',
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* Checks if a string is a valid package feature type.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const isValidPackageFeatureType = (
|
||||
value: string,
|
||||
): value is BackstagePackageFeatureType => {
|
||||
return packageFeatureTypes.includes(value as any);
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of a Backstage system feature
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type BackstagePackageFeatureType = (typeof packageFeatureTypes)[number];
|
||||
|
||||
/**
|
||||
* Known fields in Backstage package.json files.
|
||||
*
|
||||
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
export { isMonoRepo } from './isMonoRepo';
|
||||
export {
|
||||
packageFeatureTypes,
|
||||
isValidPackageFeatureType,
|
||||
PackageGraph,
|
||||
type PackageGraphNode,
|
||||
type BackstagePackage,
|
||||
type BackstagePackageJson,
|
||||
type BackstagePackageFeatureType,
|
||||
} from './PackageGraph';
|
||||
export {
|
||||
Lockfile,
|
||||
|
||||
@@ -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