cli: internal refactor of backend start implementation
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -67,10 +67,3 @@ export type BackendBundlingOptions = {
|
||||
inspectBrkEnabled: boolean;
|
||||
require?: string;
|
||||
};
|
||||
|
||||
export type BackendServeOptions = BundlingPathsOptions & {
|
||||
checksEnabled: boolean;
|
||||
inspectEnabled: boolean;
|
||||
inspectBrkEnabled: boolean;
|
||||
require?: string;
|
||||
};
|
||||
|
||||
@@ -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';
|
||||
@@ -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';
|
||||
+13
-5
@@ -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';
|
||||
Reference in New Issue
Block a user