From b33f6b22ba7e99524ee905536d38a11127e8a53c Mon Sep 17 00:00:00 2001 From: Harrison Hogg Date: Thu, 12 Sep 2024 17:00:59 +0100 Subject: [PATCH] Removed type list from cli-node Signed-off-by: Harrison Hogg --- .changeset/clever-paws-stare.md | 3 +- .changeset/healthy-moose-tease.md | 63 ------------------- packages/cli-node/api-report.md | 59 ----------------- .../cli-node/src/monorepo/PackageGraph.ts | 46 -------------- packages/cli-node/src/monorepo/index.ts | 3 - .../__testUtils__/createFeatureEnvironment.ts | 7 ++- packages/cli/src/lib/typeDistProject.test.ts | 42 +++++-------- packages/cli/src/lib/typeDistProject.ts | 43 +++++++------ 8 files changed, 43 insertions(+), 223 deletions(-) delete mode 100644 .changeset/healthy-moose-tease.md diff --git a/.changeset/clever-paws-stare.md b/.changeset/clever-paws-stare.md index b3cb421723..ad56a5306e 100644 --- a/.changeset/clever-paws-stare.md +++ b/.changeset/clever-paws-stare.md @@ -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. diff --git a/.changeset/healthy-moose-tease.md b/.changeset/healthy-moose-tease.md deleted file mode 100644 index 1f9ba3952f..0000000000 --- a/.changeset/healthy-moose-tease.md +++ /dev/null @@ -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 diff --git a/packages/cli-node/api-report.md b/packages/cli-node/api-report.md index 519fe12bf9..f22583dd25 100644 --- a/packages/cli-node/api-report.md +++ b/packages/cli-node/api-report.md @@ -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; -// @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>; @@ -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 { collectPackageNames( diff --git a/packages/cli-node/src/monorepo/PackageGraph.ts b/packages/cli-node/src/monorepo/PackageGraph.ts index 0394fd34ca..69ec99c2dd 100644 --- a/packages/cli-node/src/monorepo/PackageGraph.ts +++ b/packages/cli-node/src/monorepo/PackageGraph.ts @@ -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. * diff --git a/packages/cli-node/src/monorepo/index.ts b/packages/cli-node/src/monorepo/index.ts index b4ed921613..fdb8395c16 100644 --- a/packages/cli-node/src/monorepo/index.ts +++ b/packages/cli-node/src/monorepo/index.ts @@ -16,13 +16,10 @@ export { isMonoRepo } from './isMonoRepo'; export { - packageFeatureTypes, - isValidPackageFeatureType, PackageGraph, type PackageGraphNode, type BackstagePackage, type BackstagePackageJson, - type BackstagePackageFeatureType, } from './PackageGraph'; export { Lockfile, diff --git a/packages/cli/src/lib/__testUtils__/createFeatureEnvironment.ts b/packages/cli/src/lib/__testUtils__/createFeatureEnvironment.ts index 7d7eeeeeaf..51848a9d68 100644 --- a/packages/cli/src/lib/__testUtils__/createFeatureEnvironment.ts +++ b/packages/cli/src/lib/__testUtils__/createFeatureEnvironment.ts @@ -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: '.', diff --git a/packages/cli/src/lib/typeDistProject.test.ts b/packages/cli/src/lib/typeDistProject.test.ts index f3168dd9be..dfe3e68ec0 100644 --- a/packages/cli/src/lib/typeDistProject.test.ts +++ b/packages/cli/src/lib/typeDistProject.test.ts @@ -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 = { - // 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 = + { + // 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], diff --git a/packages/cli/src/lib/typeDistProject.ts b/packages/cli/src/lib/typeDistProject.ts index 4fa970957d..573f8a059e 100644 --- a/packages/cli/src/lib/typeDistProject.ts +++ b/packages/cli/src/lib/typeDistProject.ts @@ -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(/(?@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) + ); +}