Merge pull request #22800 from backstage/rugvip/repofix

cli: add repository field check to the repo fix command
This commit is contained in:
Ben Lambert
2024-02-08 08:11:50 +01:00
committed by GitHub
52 changed files with 338 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Added check for the `repository` field in the `repo fix` command.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli-node': patch
---
Added `repository` field to `BackstagePackageJson` type.
+46
View File
@@ -0,0 +1,46 @@
---
'@backstage/plugin-catalog-backend-module-scaffolder-entity-model': patch
'@backstage/plugin-search-backend-module-stack-overflow-collator': patch
'@backstage/plugin-permission-backend-module-allow-all-policy': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch
'@backstage/plugin-auth-backend-module-oauth2-proxy-provider': patch
'@backstage/plugin-auth-backend-module-vmware-cloud-provider': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket-cloud': patch
'@backstage/plugin-catalog-backend-module-backstage-openapi': patch
'@backstage/plugin-auth-backend-module-atlassian-provider': patch
'@backstage/plugin-auth-backend-module-microsoft-provider': patch
'@backstage/plugin-auth-backend-module-pinniped-provider': patch
'@backstage/plugin-auth-backend-module-github-provider': patch
'@backstage/plugin-auth-backend-module-gitlab-provider': patch
'@backstage/plugin-auth-backend-module-oauth2-provider': patch
'@backstage/plugin-scaffolder-backend-module-bitbucket': patch
'@backstage/plugin-analytics-module-newrelic-browser': patch
'@backstage/plugin-auth-backend-module-oidc-provider': patch
'@backstage/plugin-auth-backend-module-okta-provider': patch
'@backstage/plugin-catalog-backend-module-github-org': patch
'@backstage/backend-dynamic-feature-service': patch
'@backstage/plugin-scaffolder-backend-module-gerrit': patch
'@backstage/plugin-scaffolder-backend-module-github': patch
'@backstage/plugin-scaffolder-backend-module-azure': patch
'@backstage/plugin-notifications-backend': patch
'@backstage/frontend-test-utils': patch
'@backstage/plugin-analytics-module-ga4': patch
'@backstage/plugin-notifications-common': patch
'@backstage/plugin-notifications-node': patch
'@backstage/frontend-app-api': patch
'@backstage/plugin-kubernetes-react': patch
'@backstage/e2e-test-utils': patch
'@backstage/plugin-kubernetes-node': patch
'@backstage/plugin-signals-backend': patch
'@backstage/plugin-app-visualizer': patch
'@backstage/plugin-notifications': patch
'@backstage/plugin-signals-react': patch
'@backstage/plugin-vault-backend': patch
'@backstage/plugin-signals-node': patch
'@backstage/plugin-vault-node': patch
'@backstage/plugin-app-node': patch
'@backstage/plugin-opencost': patch
'@backstage/plugin-signals': patch
---
Added or fixed the `repository` field in `package.json`.
+4
View File
@@ -44,6 +44,10 @@
"prepare": "husky",
"postinstall": "husky || true"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage"
},
"workspaces": {
"packages": [
"packages/*",
+5
View File
@@ -2,6 +2,11 @@
"name": "example-app-next",
"version": "0.0.6-next.2",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/app-next"
},
"backstage": {
"role": "frontend"
},
@@ -9,6 +9,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/backend-dynamic-feature-service"
},
"backstage": {
"role": "node-library"
},
+8
View File
@@ -55,6 +55,14 @@ export interface BackstagePackageJson {
registry?: string;
};
// (undocumented)
repository?:
| string
| {
type: string;
url: string;
directory: string;
};
// (undocumented)
scripts?: {
[key: string]: string;
};
@@ -58,6 +58,14 @@ export interface BackstagePackageJson {
registry?: string;
};
repository?:
| string
| {
type: string;
url: string;
directory: string;
};
dependencies?: {
[key: string]: string;
};
+57 -1
View File
@@ -22,7 +22,11 @@ import {
} from '@backstage/cli-node';
import { OptionValues } from 'commander';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import {
resolve as resolvePath,
join as joinPath,
relative as relativePath,
} from 'path';
import { paths } from '../../lib/paths';
/**
@@ -189,12 +193,64 @@ export function fixSideEffects(pkg: FixablePackage) {
pkg.changed = true;
}
export function createRepositoryFieldFixer() {
const rootPkg = require(paths.resolveTargetRoot('package.json'));
const rootRepoField = rootPkg.repository;
if (!rootRepoField) {
return () => {};
}
const rootType = rootRepoField.type || 'git';
const rootUrl = rootRepoField.url;
const rootDir = rootRepoField.directory || '';
return (pkg: FixablePackage) => {
const expectedPath = joinPath(
rootDir,
relativePath(paths.targetRoot, pkg.dir),
);
const repoField = pkg.packageJson.repository;
if (!repoField || typeof repoField === 'string') {
const pkgEntries = Object.entries(pkg.packageJson);
pkgEntries.splice(
// Place it just above the backstage field
pkgEntries.findIndex(([name]) => name === 'backstage'),
0,
[
'repository',
{
type: rootType,
url: rootUrl,
directory: expectedPath,
},
],
);
pkg.packageJson = Object.fromEntries(pkgEntries) as BackstagePackageJson;
pkg.changed = true;
return;
}
// If there's a type or URL mismatch, leave the field as is
if (repoField.type !== rootType || repoField.url !== rootUrl) {
return;
}
if (repoField.directory !== expectedPath) {
repoField.directory = expectedPath;
pkg.changed = true;
}
};
}
export async function command(opts: OptionValues): Promise<void> {
const packages = await readFixablePackages();
const fixRepositoryField = createRepositoryFieldFixer();
for (const pkg of packages) {
fixPackageExports(pkg);
fixSideEffects(pkg);
fixRepositoryField(pkg);
}
if (opts.check) {
+5
View File
@@ -22,6 +22,11 @@
]
}
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/e2e-test-utils"
},
"backstage": {
"role": "node-library"
},
+5
View File
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/frontend-app-api"
},
"backstage": {
"role": "web-library"
},
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "packages/frontend-test-utils"
},
"backstage": {
"role": "web-library"
},
+1 -1
View File
@@ -16,7 +16,7 @@
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/plugins/analytics-module-ga4"
"directory": "plugins/analytics-module-ga4"
},
"sideEffects": false,
"scripts": {
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/analytics-module-newrelic-browser"
},
"backstage": {
"role": "frontend-plugin-module"
},
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/app-node"
},
"backstage": {
"role": "node-library"
},
+5
View File
@@ -5,6 +5,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/app-visualizer"
},
"backstage": {
"role": "frontend-plugin"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-atlassian-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-github-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-gitlab-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-microsoft-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-oauth2-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-oauth2-proxy-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-oidc-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-okta-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-pinniped-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/auth-backend-module-vmware-cloud-provider"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -9,6 +9,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/catalog-backend-module-backstage-openapi"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/catalog-backend-module-github-org"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -19,6 +19,11 @@
]
}
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/catalog-backend-module-scaffolder-entity-model"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -12,7 +12,7 @@
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/plugins/example-todo-list-backend"
"directory": "plugins/example-todo-list-backend"
},
"publishConfig": {
"access": "public",
@@ -17,7 +17,7 @@
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/plugins/example-todo-list-common"
"directory": "plugins/example-todo-list-common"
},
"sideEffects": false,
"scripts": {
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/kubernetes-node"
},
"backstage": {
"role": "node-library"
},
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/kubernetes-react"
},
"backstage": {
"role": "web-library"
},
@@ -9,6 +9,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/notifications-backend"
},
"backstage": {
"role": "backend-plugin"
},
@@ -11,6 +11,11 @@
"module": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/notifications-common"
},
"backstage": {
"role": "common-library"
},
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/notifications-node"
},
"backstage": {
"role": "node-library"
},
+5
View File
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/notifications"
},
"backstage": {
"role": "frontend-plugin"
},
+5
View File
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/opencost"
},
"backstage": {
"role": "frontend-plugin"
},
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/permission-backend-module-policy-allow-all"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -8,6 +8,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-azure"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -8,6 +8,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-bitbucket-cloud"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -8,6 +8,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-bitbucket-server"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -9,6 +9,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-bitbucket"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -8,6 +8,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-gerrit"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -8,6 +8,11 @@
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/scaffolder-backend-module-github"
},
"backstage": {
"role": "backend-plugin-module"
},
@@ -17,7 +17,7 @@
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/search-backend-module-stack-overflow"
"directory": "plugins/search-backend-module-stack-overflow-collator"
},
"scripts": {
"start": "backstage-cli package start",
+5
View File
@@ -9,6 +9,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/signals-backend"
},
"backstage": {
"role": "backend-plugin"
},
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/signals-node"
},
"backstage": {
"role": "node-library"
},
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/signals-react"
},
"backstage": {
"role": "web-library"
},
+5
View File
@@ -9,6 +9,11 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/signals"
},
"backstage": {
"role": "frontend-plugin"
},
+1 -1
View File
@@ -17,7 +17,7 @@
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/vault"
"directory": "plugins/vault-backend"
},
"keywords": [
"backstage",
+5
View File
@@ -10,6 +10,11 @@
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugins/vault-node"
},
"backstage": {
"role": "node-library"
},