diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index c9b6496bb0..4f62044de7 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { paths } from '../../lib/paths'; -import { startBackendExperimental } from '../../lib/experimental/startBackendExperimental'; +import { runBackend } from '../../lib/runner'; interface StartBackendOptions { checksEnabled: boolean; @@ -26,9 +26,8 @@ interface StartBackendOptions { } export async function startBackend(options: StartBackendOptions) { - const waitForExit = await startBackendExperimental({ + const waitForExit = await runBackend({ entry: 'src/index', - checksEnabled: false, // not supported inspectEnabled: options.inspectEnabled, inspectBrkEnabled: options.inspectBrkEnabled, require: options.require, @@ -48,9 +47,8 @@ export async function startBackendPlugin(options: StartBackendOptions) { return; } - const waitForExit = await startBackendExperimental({ + const waitForExit = await runBackend({ entry: 'dev/index', - checksEnabled: false, // not supported inspectEnabled: options.inspectEnabled, inspectBrkEnabled: options.inspectBrkEnabled, require: options.require, diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index f8e228c5c4..3f52e4f765 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -67,10 +67,3 @@ export type BackendBundlingOptions = { inspectBrkEnabled: boolean; require?: string; }; - -export type BackendServeOptions = BundlingPathsOptions & { - checksEnabled: boolean; - inspectEnabled: boolean; - inspectBrkEnabled: boolean; - require?: string; -}; diff --git a/packages/cli/src/lib/experimental/IpcServer.ts b/packages/cli/src/lib/ipc/IpcServer.ts similarity index 100% rename from packages/cli/src/lib/experimental/IpcServer.ts rename to packages/cli/src/lib/ipc/IpcServer.ts diff --git a/packages/cli/src/lib/experimental/ServerDataStore.ts b/packages/cli/src/lib/ipc/ServerDataStore.ts similarity index 100% rename from packages/cli/src/lib/experimental/ServerDataStore.ts rename to packages/cli/src/lib/ipc/ServerDataStore.ts diff --git a/packages/cli/src/lib/ipc/index.ts b/packages/cli/src/lib/ipc/index.ts new file mode 100644 index 0000000000..78ee98a942 --- /dev/null +++ b/packages/cli/src/lib/ipc/index.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export { IpcServer } from './IpcServer'; +export { ServerDataStore } from './ServerDataStore'; diff --git a/packages/cli/src/lib/runner/index.ts b/packages/cli/src/lib/runner/index.ts new file mode 100644 index 0000000000..e00ffaa3e5 --- /dev/null +++ b/packages/cli/src/lib/runner/index.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +export { runBackend } from './runBackend'; diff --git a/packages/cli/src/lib/experimental/startBackendExperimental.ts b/packages/cli/src/lib/runner/runBackend.ts similarity index 90% rename from packages/cli/src/lib/experimental/startBackendExperimental.ts rename to packages/cli/src/lib/runner/runBackend.ts index bd4bb94b17..f0ce971fee 100644 --- a/packages/cli/src/lib/experimental/startBackendExperimental.ts +++ b/packages/cli/src/lib/runner/runBackend.ts @@ -15,12 +15,9 @@ */ import { FSWatcher, watch } from 'chokidar'; - -import { BackendServeOptions } from '../bundler/types'; import type { ChildProcess } from 'child_process'; import { ctrlc } from 'ctrlc-windows'; -import { IpcServer } from './IpcServer'; -import { ServerDataStore } from './ServerDataStore'; +import { IpcServer, ServerDataStore } from '../ipc'; import debounce from 'lodash/debounce'; import { fileURLToPath } from 'url'; import { isAbsolute as isAbsolutePath } from 'path'; @@ -34,7 +31,18 @@ const loaderArgs = [ // TODO: Support modules, although there's currently no way to load them since import() is transpiled tp require() ]; -export async function startBackendExperimental(options: BackendServeOptions) { +export type RunBackendOptions = { + /** relative entry point path without extension, e.g. 'src/index' */ + entry: string; + /** Whether to forward the --inspect flag to the node process */ + inspectEnabled: boolean; + /** Whether to forward the --inspect-brk flag to the node process */ + inspectBrkEnabled: boolean; + /** Additional module to require via the --require flag to the node process */ + require?: string; +}; + +export async function runBackend(options: RunBackendOptions) { const envEnv = process.env as { NODE_ENV: string }; if (!envEnv.NODE_ENV) { envEnv.NODE_ENV = 'development';