scaffolder: got rid of most backend-common usages

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2025-03-01 12:47:04 +01:00
parent 92de48f1ce
commit 09cf03890c
39 changed files with 414 additions and 110 deletions
+1 -1
View File
@@ -54,7 +54,6 @@
"test": "backstage-cli package test"
},
"dependencies": {
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/catalog-model": "workspace:^",
"@backstage/errors": "workspace:^",
@@ -69,6 +68,7 @@
"p-limit": "^3.1.0",
"tar": "^6.1.12",
"winston": "^3.2.1",
"winston-transport": "^4.7.0",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.20.4"
},
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { Git } from '../scm';
import {
commitAndPushRepo,
@@ -25,6 +24,7 @@ import {
cloneRepo,
} from './gitHelpers';
import { mockServices } from '@backstage/backend-test-utils';
import { loggerToWinstonLogger } from './loggerToWinstonLogger';
jest.mock('../scm', () => ({
Git: {
@@ -0,0 +1,67 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { LoggerService } from '@backstage/backend-plugin-api';
import { JsonObject } from '@backstage/types';
import { Logger as WinstonLogger, createLogger } from 'winston';
import Transport, { TransportStreamOptions } from 'winston-transport';
class BackstageLoggerTransport extends Transport {
constructor(
private readonly backstageLogger: LoggerService,
opts?: TransportStreamOptions,
) {
super(opts);
}
log(info: unknown, callback: VoidFunction) {
if (typeof info !== 'object' || info === null) {
callback();
return;
}
const { level, message, ...meta } = info as JsonObject;
switch (level) {
case 'error':
this.backstageLogger.error(String(message), meta);
break;
case 'warn':
this.backstageLogger.warn(String(message), meta);
break;
case 'info':
this.backstageLogger.info(String(message), meta);
break;
case 'debug':
this.backstageLogger.debug(String(message), meta);
break;
default:
this.backstageLogger.info(String(message), meta);
}
callback();
}
}
/**
* A helper function to convert a Backstage LoggerService to a Winston Logger.
* @internal
*/
export function loggerToWinstonLogger(
logger: LoggerService,
opts?: TransportStreamOptions,
): WinstonLogger {
return createLogger({
transports: [new BackstageLoggerTransport(logger, opts)],
});
}