From 11764eff336a68e8881ff2089d7a8181384123c2 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 2 Mar 2026 20:50:26 +0100 Subject: [PATCH] cli: remove stale lib/lazy.ts from previous stash Signed-off-by: Patrik Oldsberg Made-with: Cursor --- packages/cli/src/lib/lazy.ts | 46 ------------------------------------ 1 file changed, 46 deletions(-) delete mode 100644 packages/cli/src/lib/lazy.ts diff --git a/packages/cli/src/lib/lazy.ts b/packages/cli/src/lib/lazy.ts deleted file mode 100644 index 8919ed8c28..0000000000 --- a/packages/cli/src/lib/lazy.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 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 { assertError } from '@backstage/errors'; -import { exitWithError } from '../lib/errors'; - -type ActionFunc = (...args: any[]) => Promise; -type ActionExports = { - [KName in keyof TModule as TModule[KName] extends ActionFunc - ? KName - : never]: TModule[KName]; -}; - -// Wraps an action function so that it always exits and handles errors -export function lazy( - moduleLoader: () => Promise, - exportName: keyof ActionExports, -): (...args: any[]) => Promise { - return async (...args: any[]) => { - try { - const mod = await moduleLoader(); - const actualModule = ((mod as any).default ?? - mod) as ActionExports; - const actionFunc = actualModule[exportName] as ActionFunc; - await actionFunc(...args); - - process.exit(0); - } catch (error) { - assertError(error); - exitWithError(error); - } - }; -}