From 6e211fa110c1a26aef8d2455937a68b870320851 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 16 Apr 2024 13:50:46 +0200 Subject: [PATCH] Revert "workspace(todo): deprecate packages" Signed-off-by: Patrik Oldsberg --- .changeset/migrate-1712843347091.md | 6 -- plugins/todo-backend/README.md | 79 +++++++++++++++++++- plugins/todo-backend/package.json | 6 +- plugins/todo/README.md | 108 +++++++++++++++++++++++++++- plugins/todo/package.json | 6 +- 5 files changed, 187 insertions(+), 18 deletions(-) delete mode 100644 .changeset/migrate-1712843347091.md diff --git a/.changeset/migrate-1712843347091.md b/.changeset/migrate-1712843347091.md deleted file mode 100644 index cd37254fb7..0000000000 --- a/.changeset/migrate-1712843347091.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -'@backstage/plugin-todo': patch -'@backstage/plugin-todo-backend': patch ---- - -These packages have been migrated to the [backstage/community-plugins](https://github.com/backstage/community-plugins) repository. diff --git a/plugins/todo-backend/README.md b/plugins/todo-backend/README.md index 3e2558bb51..0aec607b93 100644 --- a/plugins/todo-backend/README.md +++ b/plugins/todo-backend/README.md @@ -1,3 +1,78 @@ -# Deprecated +# @backstage/plugin-todo-backend -This package has been moved to the [backstage-community/plugins](https://github.com/backstage/community-plugins) repository. Migrate to using `@backstage-community/plugin-todo-backend` instead. +Backend for the `@backstage/plugin-todo` plugin. Assists in scanning for and listing `// TODO` comments in source code repositories. + +## Installation + +Install the `@backstage/plugin-todo-backend` package in your backend packages, and then integrate the plugin using the following default setup for `src/plugins/todo.ts`: + +```ts +import { Router } from 'express'; +import { CatalogClient } from '@backstage/catalog-client'; +import { + createRouter, + TodoReaderService, + TodoScmReader, +} from '@backstage/plugin-todo-backend'; +import { PluginEnvironment } from '../types'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + const todoReader = TodoScmReader.fromConfig(env.config, { + logger: env.logger, + reader: env.reader, + }); + + const catalogClient = new CatalogClient({ + discoveryApi: env.discovery, + }); + + const todoService = new TodoReaderService({ + todoReader, + catalogClient, + }); + + return await createRouter({ todoService }); +} +``` + +And then add to `packages/backend/src/index.ts`: + +```js +// In packages/backend/src/index.ts +import todo from './plugins/todo'; +// ... +async function main() { + // ... + const todoEnv = useHotMemoize(module, () => createEnv('todo')); + // ... + apiRouter.use('/todo', await todo(todoEnv)); +``` + +## Scanned Files + +The included `TodoReaderService` and `TodoScmReader` works by getting the entity source location from the catalog. + +The location source code is determined automatically. In case of the source code of the component is not in the same place of the entity YAML file, you can explicitly set the value of the [`backstage.io/source-location`](https://backstage.io/docs/features/software-catalog/well-known-annotations#backstageiosource-location) annotation of the entity, and if that is missing it falls back to the [`backstage.io/managed-by-location `](https://backstage.io/docs/features/software-catalog/well-known-annotations#backstageiomanaged-by-location) annotation. Only `url` locations are currently supported, meaning locally configured `file` locations won't work. Also note that dot-files and folders are ignored. + +## Parser Configuration + +The `TodoScmReader` accepts a `TodoParser` option, which can be used to configure your own parser. The default one is based on [Leasot](https://github.com/pgilad/leasot) and supports a wide range of languages. You can add to the list of supported tags by configuring your own version of the built-in parser, for example: + +```ts +import { + TodoScmReader, + createTodoParser, +} from '@backstage/plugin-todo-backend'; + +// ... + +const todoReader = TodoScmReader.fromConfig(env.config, { + logger: env.logger, + reader: env.reader, + parser: createTodoParser({ + additionalTags: ['NOTE', 'XXX'], + }), +}); +``` diff --git a/plugins/todo-backend/package.json b/plugins/todo-backend/package.json index a82f2622f3..ae540ff100 100644 --- a/plugins/todo-backend/package.json +++ b/plugins/todo-backend/package.json @@ -3,8 +3,7 @@ "version": "0.3.16-next.1", "description": "A Backstage backend plugin that lets you browse TODO comments in your source code", "backstage": { - "role": "backend-plugin", - "moved": "@backstage-community/plugin-todo-backend" + "role": "backend-plugin" }, "publishConfig": { "access": "public", @@ -54,6 +53,5 @@ "@backstage/repo-tools": "workspace:^", "@types/supertest": "^2.0.8", "supertest": "^6.1.3" - }, - "deprecated": "This package has been moved to the backstage/community-plugins repository. You should migrate to using @backstage-community/plugin-todo-backend instead." + } } diff --git a/plugins/todo/README.md b/plugins/todo/README.md index 01be891a42..fd3a7f4733 100644 --- a/plugins/todo/README.md +++ b/plugins/todo/README.md @@ -1,3 +1,107 @@ -# Deprecated +# @backstage/plugin-todo -This package has been moved to the [backstage-community/plugins](https://github.com/backstage/community-plugins) repository. Migrate to using `@backstage-community/plugin-todo` instead. +This plugin lists `// TODO` comments in source code. It currently exports a single component extension for use on entity pages. + +## Setup + +1. Run: + +```bash +# From your Backstage root directory +yarn --cwd packages/app add @backstage/plugin-todo +yarn --cwd packages/backend add @backstage/plugin-todo-backend +``` + +2. Add the plugin backend: + +In a new file named `todo.ts` under `backend/src/plugins`: + +```js +import { Router } from 'express'; +import { CatalogClient } from '@backstage/catalog-client'; +import { + createRouter, + TodoReaderService, + TodoScmReader, +} from '@backstage/plugin-todo-backend'; +import { PluginEnvironment } from '../types'; + +export default async function createPlugin( + env: PluginEnvironment, +): Promise { + const todoReader = TodoScmReader.fromConfig(env.config, { + logger: env.logger, + reader: env.reader, + }); + + const catalogClient = new CatalogClient({ + discoveryApi: env.discovery, + }); + + const todoService = new TodoReaderService({ + todoReader, + catalogClient, + }); + + return await createRouter({ todoService }); +} +``` + +And then add to `packages/backend/src/index.ts`: + +```js +// In packages/backend/src/index.ts +import todo from './plugins/todo'; +// ... +async function main() { + // ... + const todoEnv = useHotMemoize(module, () => createEnv('todo')); + // ... + apiRouter.use('/todo', await todo(todoEnv)); +``` + +3. Add the plugin as a tab to your service entities: + +```jsx +// In packages/app/src/components/catalog/EntityPage.tsx +import { EntityTodoContent } from '@backstage/plugin-todo'; + +const serviceEntityPage = ( + + {/* other tabs... */} + + + +``` + +## Format + +The default parser uses [Leasot](https://github.com/pgilad/leasot), which supports a wide range of languages. By default it supports the `TODO` and `FIXME` tags, along with `@` prefix and author reference through with either a `()` suffix or trailing `/`. For more information on how to configure the parser, see `@backstage/plugin-todo-backend`. + +Below are some examples of formats that are supported by default: + +```ts +// TODO: Ideally this would be working + +// TODO(Rugvip): Not sure why this works, investigate + +// @todo: This worked last Monday /Rugvip + +// FIXME Nobody knows why this is here +``` + +Note that trailing comments are not supported, the following TODO would not be listed: + +```ts +function reverse(str: string) { + return str.reverse(); // TODO: optimize +} +``` + +The scanner also ignores all dot-files and directories, meaning TODOs inside of those will not be listed. + +## Extensions + +| name | description | +| ------------------- | ------------------------------------------------------------------------------- | +| `EntityTodoContent` | Content for an entity page, showing a table of TODO items for the given entity. | diff --git a/plugins/todo/package.json b/plugins/todo/package.json index 8a41e4b898..9af500fa96 100644 --- a/plugins/todo/package.json +++ b/plugins/todo/package.json @@ -3,8 +3,7 @@ "version": "0.2.38-next.1", "description": "A Backstage plugin that lets you browse TODO comments in your source code", "backstage": { - "role": "frontend-plugin", - "moved": "@backstage-community/plugin-todo" + "role": "frontend-plugin" }, "publishConfig": { "access": "public", @@ -55,6 +54,5 @@ "react": "^16.13.1 || ^17.0.0 || ^18.0.0", "react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0", "react-router-dom": "6.0.0-beta.0 || ^6.3.0" - }, - "deprecated": "This package has been moved to the backstage/community-plugins repository. You should migrate to using @backstage-community/plugin-todo instead." + } }