diff --git a/.changeset/brown-cameras-marry.md b/.changeset/brown-cameras-marry.md new file mode 100644 index 0000000000..cfa6911842 --- /dev/null +++ b/.changeset/brown-cameras-marry.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Added the ability to specify the listen address for the `--inspect` and `--inspect-brk` command. You can now set the `ip` and port of the `inspect` and `inspectBrk` by adding for example `--inspect=0.0.0.0:9229` diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 6323eb0035..9d6ffd3f69 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -278,8 +278,8 @@ Options: --config --role --check - --inspect - --inspect-brk + --inspect [host] + --inspect-brk [host] -h, --help ``` diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 283a15bcb0..ce4a4d2bae 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -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 ', '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))); diff --git a/packages/cli/src/commands/start/command.ts b/packages/cli/src/commands/start/command.ts index 9306ab247c..48122d5ac0 100644 --- a/packages/cli/src/commands/start/command.ts +++ b/packages/cli/src/commands/start/command.ts @@ -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 { const role = await findRoleFromCommand(opts); @@ -25,8 +25,8 @@ export async function command(opts: OptionValues): Promise { 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) { diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index c9238e7e48..ed20fe385a 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -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(); 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 { diff --git a/packages/cli/src/lib/experimental/startBackendExperimental.ts b/packages/cli/src/lib/experimental/startBackendExperimental.ts index f4875ce1e5..3bc603a9da 100644 --- a/packages/cli/src/lib/experimental/startBackendExperimental.ts +++ b/packages/cli/src/lib/experimental/startBackendExperimental.ts @@ -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(); 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