Removed type list from cli-node

Signed-off-by: Harrison Hogg <hhogg@spotify.com>
This commit is contained in:
Harrison Hogg
2024-09-12 17:00:59 +01:00
parent 48100b59bd
commit b33f6b22ba
8 changed files with 43 additions and 223 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
---
'@backstage/cli-node': patch
'@backstage/cli': patch
---
Added a new step to the `backstage-cli repo fix --publish` command that will annotate default export features to the 'backstage' metadata within plugin package.json. This is to help with identifying the declarative integration points for plugins without needing to fetch or run the plugins first.
Added functionality to the prepack script that will append the default export type for entry points to the `exports` object before publishing. This is to help with identifying the declarative integration points for plugins without needing to fetch or run the plugins first.
-63
View File
@@ -1,63 +0,0 @@
---
'@backstage/plugin-scaffolder-backend-module-confluence-to-markdown': patch
'@backstage/plugin-catalog-backend-module-scaffolder-entity-model': patch
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket-cloud': patch
'@backstage/plugin-catalog-backend-module-bitbucket-server': patch
'@backstage/plugin-catalog-backend-module-bitbucket-cloud': patch
'@backstage/plugin-scaffolder-backend-module-cookiecutter': patch
'@backstage/plugin-events-backend-module-bitbucket-cloud': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket': patch
'@backstage/plugin-search-backend-module-elasticsearch': patch
'@backstage/plugin-scaffolder-backend-module-gerrit': patch
'@backstage/plugin-scaffolder-backend-module-github': patch
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
'@backstage/plugin-scaffolder-backend-module-sentry': patch
'@backstage/plugin-scaffolder-backend-module-yeoman': patch
'@backstage/plugin-catalog-backend-module-puppetdb': patch
'@backstage/plugin-scaffolder-backend-module-azure': patch
'@backstage/plugin-scaffolder-backend-module-gitea': patch
'@backstage/plugin-scaffolder-backend-module-rails': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-search-backend-module-techdocs': patch
'@backstage/plugin-catalog-backend-module-gerrit': patch
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-gitlab': patch
'@backstage/plugin-events-backend-module-aws-sqs': patch
'@backstage/plugin-scaffolder-backend-module-gcp': patch
'@backstage/plugin-search-backend-module-catalog': patch
'@backstage/plugin-search-backend-module-explore': patch
'@backstage/plugin-catalog-backend-module-azure': patch
'@backstage/plugin-events-backend-module-gerrit': patch
'@backstage/plugin-events-backend-module-github': patch
'@backstage/plugin-events-backend-module-gitlab': patch
'@backstage/plugin-events-backend-module-azure': patch
'@backstage/plugin-catalog-backend-module-aws': patch
'@backstage/plugin-catalog-backend-module-gcp': patch
'@backstage/plugin-search-backend-module-pg': patch
'@backstage/plugin-user-settings-backend': patch
'@backstage/plugin-kubernetes-backend': patch
'@backstage/plugin-permission-backend': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/plugin-techdocs-backend': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-catalog-import': patch
'@backstage/plugin-events-backend': patch
'@backstage/plugin-search-backend': patch
'@backstage/plugin-catalog-graph': patch
'@backstage/plugin-proxy-backend': patch
'@backstage/plugin-user-settings': patch
'@backstage/plugin-app-backend': patch
'@backstage/plugin-kubernetes': patch
'@backstage/plugin-scaffolder': patch
'@backstage/plugin-api-docs': patch
'@backstage/plugin-devtools': patch
'@backstage/plugin-techdocs': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-search': patch
'@backstage/plugin-home': patch
'@backstage/plugin-org': patch
---
Added `features` metadata to Package JSON
-59
View File
@@ -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.
*
-3
View File
@@ -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: '.',
+16 -26
View File
@@ -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],
+21 -22
View File
@@ -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)
);
}