refator(backend-common): extract path utilities to plugin api

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2024-04-30 14:03:56 +02:00
parent a394b66c3e
commit d229dc49ad
47 changed files with 151 additions and 86 deletions
+24
View File
@@ -0,0 +1,24 @@
---
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
'@backstage/plugin-scaffolder-backend-module-cookiecutter': patch
'@backstage/backend-dynamic-feature-service': patch
'@backstage/plugin-scaffolder-backend-module-github': patch
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
'@backstage/plugin-search-backend-module-pg': patch
'@backstage/plugin-notifications-backend': patch
'@backstage/plugin-user-settings-backend': patch
'@backstage/backend-plugin-api': patch
'@backstage/backend-test-utils': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/backend-app-api': patch
'@backstage/backend-common': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-scaffolder-node': patch
'@backstage/backend-tasks': patch
'@backstage/plugin-techdocs-node': patch
'@backstage/plugin-auth-backend': patch
'@backstage/repo-tools': patch
'@backstage/plugin-app-backend': patch
---
Extract path utilities from `backend-common` to the `backend-plugin-api` package.
@@ -14,11 +14,14 @@
* limitations under the License.
*/
import { DatabaseService, LoggerService } from '@backstage/backend-plugin-api';
import {
DatabaseService,
LoggerService,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
import { DateTime } from 'luxon';
import { Knex } from 'knex';
import { JsonObject } from '@backstage/types';
import { resolvePackagePath } from '@backstage/backend-common';
import { KeyStore } from './types';
const MIGRATIONS_TABLE = 'backstage_backend_public_keys__knex_migrations';
+27
View File
@@ -14,6 +14,12 @@
* limitations under the License.
*/
import {
resolvePackagePath as _resolvePackagePath,
resolveSafeChildPath as _resolveSafeChildPath,
isChildPath as _isChildPath,
} from '@backstage/backend-plugin-api';
import {
overridePackagePathResolution as _overridePackagePathResolution,
OverridePackagePathResolutionOptions as _OverridePackagePathResolutionOptions,
@@ -41,3 +47,24 @@ export type OverridePackagePathResolutionOptions =
* Please use the `PackagePathResolutionOverride` type from the `@backstage/backend-plugin-api/testUtils` package instead.
*/
export type PackagePathResolutionOverride = _PackagePathResolutionOverride;
/**
* @public
* @deprecated This type is deprecated and will be removed in a future release, see https://github.com/backstage/backstage/issues/24493.
* Please use the `resolvePackagePath` function from the `@backstage/backend-plugin-api` package instead.
*/
export const resolvePackagePath = _resolvePackagePath;
/**
* @public
* @deprecated This type is deprecated and will be removed in a future release, see
* Please use the `resolveSafeChildPath` function from the `@backstage/backend-plugin-api` package instead.
*/
export const resolveSafeChildPath = _resolveSafeChildPath;
/**
* @public
* @deprecated This type is deprecated and will be removed in a future release, see
* Please use the `isChildPath` function from the `@backstage/cli-common` package instead.
*/
export const isChildPath = _isChildPath;
+5 -1
View File
@@ -25,12 +25,16 @@ export type { LegacyCreateRouter } from './legacy';
export * from './auth';
export * from './cache';
export { loadBackendConfig } from './config';
export {
resolvePackagePath,
resolveSafeChildPath,
isChildPath,
} from './deprecated';
export * from './database';
export * from './discovery';
export * from './hot';
export * from './logging';
export * from './middleware';
export * from './paths';
export * from './reading';
export * from './scm';
export * from './service';
@@ -25,7 +25,7 @@ import {
ReadTreeResponseFile,
} from '../types';
import { streamToBuffer } from './util';
import { resolveSafeChildPath } from '../../paths';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
/**
* Wraps a zip archive stream into a tree response reader.
@@ -17,13 +17,13 @@
import {
coreServices,
createBackendModule,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
import { dynamicPluginsSchemasServiceRef } from './schemas';
import {
configSchemaExtensionPoint,
loadCompiledConfigSchema,
} from '@backstage/plugin-app-node';
import { resolvePackagePath } from '@backstage/backend-common';
/** @public */
export const dynamicPluginsFrontendSchemas = createBackendModule({
+3
View File
@@ -53,7 +53,9 @@
},
"dependencies": {
"@backstage/backend-tasks": "workspace:^",
"@backstage/cli-common": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@backstage/types": "workspace:^",
@@ -62,6 +64,7 @@
"knex": "^3.0.0"
},
"devDependencies": {
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^"
}
}
+1
View File
@@ -22,4 +22,5 @@
export * from './services';
export type { BackendFeature } from './types';
export * from './paths';
export * from './wiring';
+1 -1
View File
@@ -16,7 +16,7 @@
// TODO: Remove this relative import when extrating the path utilities to this package
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { packagePathMocks } from '../../backend-common/src/paths';
import { packagePathMocks } from './paths';
import { posix as posixPath, resolve as resolvePath } from 'path';
/** @public */
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { Knex } from 'knex';
import { DB_MIGRATIONS_TABLE } from './tables';
@@ -15,7 +15,7 @@
*/
import os from 'os';
import { isChildPath } from '@backstage/backend-common';
import { isChildPath } from '@backstage/backend-plugin-api';
import fs from 'fs-extra';
import textextensions from 'textextensions';
import {
+22 -22
View File
@@ -8,31 +8,42 @@
"backstage": {
"role": "cli"
},
"keywords": [
"backstage"
],
"homepage": "https://backstage.io",
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/repo-tools"
},
"keywords": [
"backstage"
],
"license": "Apache-2.0",
"main": "dist/index.cjs.js",
"scripts": {
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"start": "nodemon --"
},
"bin": {
"backstage-repo-tools": "bin/backstage-repo-tools"
},
"files": [
"bin",
"dist/**/*.js",
"templates",
"openapitools.json"
],
"scripts": {
"build": "backstage-cli package build",
"clean": "backstage-cli package clean",
"lint": "backstage-cli package lint",
"start": "nodemon --",
"test": "backstage-cli package test"
},
"nodemonConfig": {
"exec": "bin/backstage-repo-tools",
"ext": "ts",
"watch": "./src"
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@apisyouwonthate/style-guide": "^1.4.0",
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/catalog-model": "workspace:^",
"@backstage/cli-common": "workspace:^",
"@backstage/cli-node": "workspace:^",
@@ -84,16 +95,5 @@
"prettier": {
"optional": true
}
},
"files": [
"bin",
"dist/**/*.js",
"templates",
"openapitools.json"
],
"nodemonConfig": {
"watch": "./src",
"exec": "bin/backstage-repo-tools",
"ext": "ts"
}
}
@@ -24,7 +24,7 @@ import { paths as cliPaths } from '../../../../../lib/paths';
import { mkdirpSync } from 'fs-extra';
import fs from 'fs-extra';
import { exec } from '../../../../../lib/exec';
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { getPathToCurrentOpenApiSpec } from '../../../../../lib/openapi/helpers';
async function generate(outputDirectory: string) {
@@ -14,15 +14,15 @@
* limitations under the License.
*/
import {
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { Knex } from 'knex';
import { DateTime } from 'luxon';
import partition from 'lodash/partition';
import { StaticAsset, StaticAssetInput, StaticAssetProvider } from './types';
import { LoggerService } from '@backstage/backend-plugin-api';
import {
LoggerService,
resolvePackagePath,
} from '@backstage/backend-plugin-api';
const migrationsDir = resolvePackagePath(
'@backstage/plugin-app-backend',
@@ -17,7 +17,7 @@
import fs from 'fs-extra';
import globby from 'globby';
import { StaticAssetInput } from './types';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
/**
* Finds all static assets within a directory
+1 -1
View File
@@ -17,8 +17,8 @@
import {
notFoundHandler,
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { AppConfig, Config } from '@backstage/config';
import helmet from 'helmet';
import express from 'express';
@@ -17,8 +17,8 @@
import {
DatabaseManager,
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
import { Knex } from 'knex';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { Knex } from 'knex';
import { DB_MIGRATIONS_TABLE } from './tables';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { Knex } from 'knex';
export async function applyDatabaseMigrations(knex: Knex): Promise<void> {
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import {
NotificationGetOptions,
NotificationModifyOptions,
@@ -14,11 +14,8 @@
* limitations under the License.
*/
import {
ContainerRunner,
UrlReader,
resolveSafeChildPath,
} from '@backstage/backend-common';
import { ContainerRunner, UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { JsonObject, JsonValue } from '@backstage/types';
import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
@@ -27,11 +27,13 @@ import {
} from '@backstage/plugin-scaffolder-node';
import { Octokit } from 'octokit';
import { CustomErrorBase, InputError } from '@backstage/errors';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { createPullRequest } from 'octokit-plugin-create-pull-request';
import { getOctokitOptions } from './helpers';
import { examples } from './githubPullRequest.examples';
import { LoggerService } from '@backstage/backend-plugin-api';
import {
LoggerService,
resolveSafeChildPath,
} from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
export type Encoding = 'utf-8' | 'base64';
@@ -23,7 +23,7 @@ import { Types } from '@gitbeaker/core';
import path from 'path';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { InputError } from '@backstage/errors';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { createGitlabApi } from './helpers';
import { examples } from './gitlabMergeRequest.examples';
@@ -23,7 +23,7 @@ import { Types } from '@gitbeaker/core';
import path from 'path';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { InputError } from '@backstage/errors';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { createGitlabApi } from './helpers';
import { examples } from './gitlabRepoPush.examples';
@@ -15,7 +15,7 @@
*/
import { Isolate } from 'isolated-vm';
import { resolvePackagePath } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import {
TemplateFilter as _TemplateFilter,
TemplateGlobal as _TemplateGlobal,
@@ -17,7 +17,7 @@
import fs from 'fs-extra';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import * as yaml from 'yaml';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { z } from 'zod';
import { examples } from './write.examples';
@@ -14,7 +14,8 @@
* limitations under the License.
*/
import { UrlReader, resolveSafeChildPath } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { ScmIntegrations } from '@backstage/integration';
import { examples } from './plain.examples';
@@ -14,7 +14,8 @@
* limitations under the License.
*/
import { UrlReader, resolveSafeChildPath } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { ScmIntegrations } from '@backstage/integration';
import { examples } from './plainFile.examples';
import {
@@ -16,7 +16,8 @@
import { join as joinPath, sep as pathSep } from 'path';
import fs from 'fs-extra';
import { resolvePackagePath, UrlReader } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { ScmIntegrations } from '@backstage/integration';
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
import { createFetchTemplateAction } from './template';
@@ -21,7 +21,8 @@ jest.mock('@backstage/plugin-scaffolder-node', () => {
import { join as joinPath, sep as pathSep } from 'path';
import fs from 'fs-extra';
import { resolvePackagePath, UrlReader } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { ScmIntegrations } from '@backstage/integration';
import { createFetchTemplateAction } from './template';
import {
@@ -15,7 +15,8 @@
*/
import { extname } from 'path';
import { resolveSafeChildPath, UrlReader } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import {
@@ -16,7 +16,7 @@
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { InputError } from '@backstage/errors';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import fs from 'fs-extra';
import { examples } from './delete.examples';
@@ -15,7 +15,7 @@
*/
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { InputError } from '@backstage/errors';
import fs from 'fs-extra';
import { examples } from './rename.examples';
@@ -33,9 +33,11 @@ import { TemplateActionRegistry } from '../actions';
import { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';
import { DecoratedActionsRegistry } from './DecoratedActionsRegistry';
import fs from 'fs-extra';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { BackstageCredentials } from '@backstage/backend-plugin-api';
import {
BackstageCredentials,
resolveSafeChildPath,
} from '@backstage/backend-plugin-api';
interface DryRunInput {
spec: TaskSpec;
@@ -15,10 +15,8 @@
*/
import { JsonObject } from '@backstage/types';
import {
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { ConflictError, NotFoundError } from '@backstage/errors';
import { Knex } from 'knex';
import { v4 as uuid } from 'uuid';
+2 -1
View File
@@ -14,7 +14,8 @@
* limitations under the License.
*/
import { resolveSafeChildPath, UrlReader } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { InputError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import fs from 'fs-extra';
+1 -1
View File
@@ -15,7 +15,7 @@
*/
import { InputError } from '@backstage/errors';
import { isChildPath } from '@backstage/backend-common';
import { isChildPath } from '@backstage/backend-plugin-api';
import { join as joinPath, normalize as normalizePath } from 'path';
import { ScmIntegrationRegistry } from '@backstage/integration';
@@ -16,7 +16,7 @@
import fs from 'fs-extra';
import { dirname } from 'path';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { SerializedFile } from './types';
/**
@@ -17,7 +17,7 @@
import { promises as fs } from 'fs';
import globby from 'globby';
import limiterFactory from 'p-limit';
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { SerializedFile } from './types';
import { isError } from '@backstage/errors';
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { IndexableDocument } from '@backstage/plugin-search-common';
import { Knex } from 'knex';
import {
+2 -1
View File
@@ -14,7 +14,8 @@
* limitations under the License.
*/
import { resolveSafeChildPath, UrlReader } from '@backstage/backend-common';
import { UrlReader } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import {
Entity,
getEntitySourceLocation,
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { isChildPath } from '@backstage/backend-common';
import { isChildPath } from '@backstage/backend-plugin-api';
import { Entity } from '@backstage/catalog-model';
import { assertError, ForwardedError } from '@backstage/errors';
import { ScmIntegrationRegistry } from '@backstage/integration';
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import {
PluginEndpointDiscovery,
resolvePackagePath,
resolveSafeChildPath,
} from '@backstage/backend-common';
} from '@backstage/backend-plugin-api';
import {
Entity,
CompoundEntityRef,
@@ -14,10 +14,8 @@
* limitations under the License.
*/
import {
PluginDatabaseManager,
resolvePackagePath,
} from '@backstage/backend-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { resolvePackagePath } from '@backstage/backend-plugin-api';
import { NotFoundError } from '@backstage/errors';
import { JsonValue } from '@backstage/types';
import { Knex } from 'knex';
+4 -1
View File
@@ -3506,8 +3506,11 @@ __metadata:
resolution: "@backstage/backend-plugin-api@workspace:packages/backend-plugin-api"
dependencies:
"@backstage/backend-tasks": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/cli-common": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/errors": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-permission-common": "workspace:^"
"@backstage/types": "workspace:^"
@@ -7669,7 +7672,7 @@ __metadata:
dependencies:
"@apidevtools/swagger-parser": ^10.1.0
"@apisyouwonthate/style-guide": ^1.4.0
"@backstage/backend-common": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
"@backstage/catalog-model": "workspace:^"
"@backstage/cli": "workspace:^"