feat(start) allow overriding inspector on start

Signed-off-by: jrwpatterson <jrwpatterson@gmail.com>
This commit is contained in:
jrwpatterson
2023-09-11 16:46:32 +10:00
parent 7e8f10e199
commit a49824feae
4 changed files with 49 additions and 31 deletions
+3 -3
View File
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import { assertError } from '@backstage/errors';
import { Command } from 'commander';
import { assertError } from '@backstage/errors';
import { exitWithError } from '../lib/errors';
const configOption = [
@@ -115,9 +115,9 @@ export function registerScriptCommand(program: Command) {
.option(...configOption)
.option('--role <name>', 'Run the command with an explicit package role')
.option('--check', 'Enable type checking and linting if available')
.option('--inspect', 'Enable debugger in Node.js environments')
.option('--inspect [host]', 'Enable debugger in Node.js environments')
.option(
'--inspect-brk',
'--inspect-brk [host]',
'Enable debugger in Node.js environments, breaking before code starts',
)
.action(lazy(() => import('./start').then(m => m.command)));
+3 -3
View File
@@ -15,9 +15,9 @@
*/
import { OptionValues } from 'commander';
import { findRoleFromCommand } from '../../lib/role';
import { startBackend } from './startBackend';
import { startFrontend } from './startFrontend';
import { findRoleFromCommand } from '../../lib/role';
export async function command(opts: OptionValues): Promise<void> {
const role = await findRoleFromCommand(opts);
@@ -25,8 +25,8 @@ export async function command(opts: OptionValues): Promise<void> {
const options = {
configPaths: opts.config as string[],
checksEnabled: Boolean(opts.check),
inspectEnabled: Boolean(opts.inspect),
inspectBrkEnabled: Boolean(opts.inspectBrk),
inspectEnabled: opts.inspect,
inspectBrkEnabled: opts.inspectBrk,
};
switch (role) {
+28 -19
View File
@@ -14,30 +14,31 @@
* limitations under the License.
*/
import fs from 'fs-extra';
import { resolve as resolvePath, posix as posixPath } from 'path';
import { BackendBundlingOptions, BundlingOptions } from './types';
import { posix as posixPath, resolve as resolvePath } from 'path';
import webpack, { ProvidePlugin } from 'webpack';
import { BackstagePackage } from '@backstage/cli-node';
import { BundlingPaths } from './paths';
import { Config } from '@backstage/config';
import ESLintPlugin from 'eslint-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { LinkedPackageResolvePlugin } from './LinkedPackageResolvePlugin';
import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin';
import { RunScriptWebpackPlugin } from 'run-script-webpack-plugin';
import webpack, { ProvidePlugin } from 'webpack';
import nodeExternals from 'webpack-node-externals';
import { isChildPath } from '@backstage/cli-common';
import { getPackages } from '@manypkg/get-packages';
import { optimization } from './optimization';
import { Config } from '@backstage/config';
import { BundlingPaths } from './paths';
import { transforms } from './transforms';
import { LinkedPackageResolvePlugin } from './LinkedPackageResolvePlugin';
import { BundlingOptions, BackendBundlingOptions } from './types';
import { version } from '../../lib/version';
import { paths as cliPaths } from '../../lib/paths';
import { BackstagePackage } from '@backstage/cli-node';
import { runPlain } from '../run';
import ESLintPlugin from 'eslint-webpack-plugin';
import fs from 'fs-extra';
import { getPackages } from '@manypkg/get-packages';
import { isChildPath } from '@backstage/cli-common';
import nodeExternals from 'webpack-node-externals';
import { optimization } from './optimization';
import pickBy from 'lodash/pickBy';
import yn from 'yn';
import { readEntryPoints } from '../entryPoints';
import { runPlain } from '../run';
import { transforms } from './transforms';
import { version } from '../../lib/version';
import yn from 'yn';
const BUILD_CACHE_ENV_VAR = 'BACKSTAGE_CLI_EXPERIMENTAL_BUILD_CACHE';
@@ -244,9 +245,17 @@ export async function createBackendConfig(
const runScriptNodeArgs = new Array<string>();
if (options.inspectEnabled) {
runScriptNodeArgs.push('--inspect');
const inspect =
typeof options.inspectEnabled === 'string'
? `--inspect=${options.inspectEnabled}`
: '--inspect';
runScriptNodeArgs.push(inspect);
} else if (options.inspectBrkEnabled) {
runScriptNodeArgs.push('--inspect-brk');
const inspect =
typeof options.inspectBrkEnabled === 'string'
? `--inspect-brk=${options.inspectBrkEnabled}`
: '--inspect-brk';
runScriptNodeArgs.push(inspect);
}
return {
@@ -14,16 +14,17 @@
* limitations under the License.
*/
import { FSWatcher, watch } from 'chokidar';
import { BackendServeOptions } from '../bundler/types';
import type { ChildProcess } from 'child_process';
import { fileURLToPath } from 'url';
import { isAbsolute as isAbsolutePath } from 'path';
import { FSWatcher, watch } from 'chokidar';
import { IpcServer } from './IpcServer';
import { ServerDataStore } from './ServerDataStore';
import debounce from 'lodash/debounce';
import spawn from 'cross-spawn';
import { fileURLToPath } from 'url';
import { isAbsolute as isAbsolutePath } from 'path';
import { paths } from '../paths';
import spawn from 'cross-spawn';
const loaderArgs = [
'--require',
@@ -68,9 +69,17 @@ export async function startBackendExperimental(options: BackendServeOptions) {
const optionArgs = new Array<string>();
if (options.inspectEnabled) {
optionArgs.push('--inspect');
const inspect =
typeof options.inspectEnabled === 'string'
? `--inspect=${options.inspectEnabled}`
: '--inspect';
optionArgs.push(inspect);
} else if (options.inspectBrkEnabled) {
optionArgs.push('--inspect-brk');
const inspect =
typeof options.inspectBrkEnabled === 'string'
? `--inspect-brk=${options.inspectBrkEnabled}`
: '--inspect-brk';
optionArgs.push(inspect);
}
const userArgs = process.argv