From 01f67198f36eccb553b0e8d2196293dfd82768e7 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 15:05:59 +0100 Subject: [PATCH 1/6] cli: show legacy warning when starting standalone plugin Signed-off-by: Vincenzo Scamporlino --- packages/cli/src/commands/start/command.ts | 5 +- .../cli/src/commands/start/startBackend.ts | 54 +++++++++++++++---- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/commands/start/command.ts b/packages/cli/src/commands/start/command.ts index 48122d5ac0..427f8b6efb 100644 --- a/packages/cli/src/commands/start/command.ts +++ b/packages/cli/src/commands/start/command.ts @@ -16,7 +16,7 @@ import { OptionValues } from 'commander'; import { findRoleFromCommand } from '../../lib/role'; -import { startBackend } from './startBackend'; +import { startBackend, startBackendPlugin } from './startBackend'; import { startFrontend } from './startFrontend'; export async function command(opts: OptionValues): Promise { @@ -31,10 +31,11 @@ export async function command(opts: OptionValues): Promise { switch (role) { case 'backend': + return startBackend(options); case 'backend-plugin': case 'backend-plugin-module': case 'node-library': - return startBackend(options); + return startBackendPlugin(options); case 'frontend': return startFrontend({ ...options, diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index 967a1108a0..acbcbe6b7a 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -26,17 +26,7 @@ interface StartBackendOptions { } export async function startBackend(options: StartBackendOptions) { - const hasDev = await fs.pathExists(paths.resolveTarget('dev')); - if (hasDev) { - const waitForExit = await startBackendExperimental({ - entry: 'dev/index', - checksEnabled: false, // not supported - inspectEnabled: options.inspectEnabled, - inspectBrkEnabled: options.inspectBrkEnabled, - }); - - await waitForExit(); - } else if (!process.env.LEGACY_BACKEND_START) { + if (!process.env.LEGACY_BACKEND_START) { const waitForExit = await startBackendExperimental({ entry: 'src/index', checksEnabled: false, // not supported @@ -61,3 +51,45 @@ export async function startBackend(options: StartBackendOptions) { await waitForExit(); } } + +export async function startBackendPlugin(options: StartBackendOptions) { + if (!process.env.LEGACY_BACKEND_START) { + const hasEntry = await fs.pathExists(paths.resolveTarget('dev')); + if (!hasEntry) { + console.warn( + `dev directory doesn't exist. \ +It looks like this plugin hasn't been migrated to the new backend system. \ +Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, + ); + return; + } + + const waitForExit = await startBackendExperimental({ + entry: 'dev/index', + checksEnabled: false, // not supported + inspectEnabled: options.inspectEnabled, + inspectBrkEnabled: options.inspectBrkEnabled, + }); + + await waitForExit(); + } else { + const hasEntry = await fs.pathExists(paths.resolveTarget('src', 'run.ts')); + if (!hasEntry) { + console.log(`src/run.ts is missing.`); + return; + } + // Cleaning dist/ before we start the dev process helps work around an issue + // where we end up with the entrypoint executing multiple times, causing + // a port bind conflict among other things. + await fs.remove(paths.resolveTarget('dist')); + + const waitForExit = await serveBackend({ + entry: 'src/run', + checksEnabled: options.checksEnabled, + inspectEnabled: options.inspectEnabled, + inspectBrkEnabled: options.inspectBrkEnabled, + }); + + await waitForExit(); + } +} From 6cd245bfcade20960a9cfa25957fd17cdc023724 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 15:06:32 +0100 Subject: [PATCH 2/6] cli: refactor clean dist directory Signed-off-by: Vincenzo Scamporlino --- .../cli/src/commands/start/startBackend.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index acbcbe6b7a..a87d40fe76 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -36,12 +36,7 @@ export async function startBackend(options: StartBackendOptions) { await waitForExit(); } else { - // Cleaning dist/ before we start the dev process helps work around an issue - // where we end up with the entrypoint executing multiple times, causing - // a port bind conflict among other things. - await fs.remove(paths.resolveTarget('dist')); - - const waitForExit = await serveBackend({ + const waitForExit = await cleanDistAndServeBackend({ entry: 'src/index', checksEnabled: options.checksEnabled, inspectEnabled: options.inspectEnabled, @@ -78,12 +73,8 @@ Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, console.log(`src/run.ts is missing.`); return; } - // Cleaning dist/ before we start the dev process helps work around an issue - // where we end up with the entrypoint executing multiple times, causing - // a port bind conflict among other things. - await fs.remove(paths.resolveTarget('dist')); - const waitForExit = await serveBackend({ + const waitForExit = await cleanDistAndServeBackend({ entry: 'src/run', checksEnabled: options.checksEnabled, inspectEnabled: options.inspectEnabled, @@ -93,3 +84,17 @@ Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, await waitForExit(); } } + +async function cleanDistAndServeBackend(options: { + entry: string; + checksEnabled: boolean; + inspectEnabled: boolean; + inspectBrkEnabled: boolean; +}) { + // Cleaning dist/ before we start the dev process helps work around an issue + // where we end up with the entrypoint executing multiple times, causing + // a port bind conflict among other things. + await fs.remove(paths.resolveTarget('dist')); + + return serveBackend(options); +} From c6f3743172d6c30e33bea0256e70e23173d89f0d Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 15:09:00 +0100 Subject: [PATCH 3/6] cli: add warning changeset Signed-off-by: Vincenzo Scamporlino --- .changeset/honest-houses-hide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/honest-houses-hide.md diff --git a/.changeset/honest-houses-hide.md b/.changeset/honest-houses-hide.md new file mode 100644 index 0000000000..7f2508184f --- /dev/null +++ b/.changeset/honest-houses-hide.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Added a warning when starting a standalone backend plugin that hasn't been updated to the new backend system. From 0555cc9d002c549c0e88a38e405d72af6c064c2b Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 15:19:34 +0100 Subject: [PATCH 4/6] cli: improve log message Signed-off-by: Vincenzo Scamporlino --- packages/cli/src/commands/start/startBackend.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index a87d40fe76..36218fe70c 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -52,9 +52,7 @@ export async function startBackendPlugin(options: StartBackendOptions) { const hasEntry = await fs.pathExists(paths.resolveTarget('dev')); if (!hasEntry) { console.warn( - `dev directory doesn't exist. \ -It looks like this plugin hasn't been migrated to the new backend system. \ -Please run "LEGACY_BACKEND_START=1 yarn start" instead.`, + `The 'dev' directory is missing. This plugin might not be updated for the new backend system. To run, use "LEGACY_BACKEND_START=1 yarn start".`, ); return; } From 2be3d465f833e9e0ddc2540f462a3ae55ca776ca Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 16:53:37 +0100 Subject: [PATCH 5/6] cli: add more warnings Signed-off-by: Vincenzo Scamporlino --- packages/cli/src/commands/start/startBackend.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index 36218fe70c..f5dfecdd21 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -49,10 +49,16 @@ export async function startBackend(options: StartBackendOptions) { export async function startBackendPlugin(options: StartBackendOptions) { if (!process.env.LEGACY_BACKEND_START) { - const hasEntry = await fs.pathExists(paths.resolveTarget('dev')); - if (!hasEntry) { + const hasDevEntry = await fs.pathExists(paths.resolveTarget('dev')); + const hasSrcIndexEntry = await fs.pathExists( + paths.resolveTarget('src', 'run.ts'), + ); + + if (!hasDevEntry && !hasSrcIndexEntry) { console.warn( - `The 'dev' directory is missing. This plugin might not be updated for the new backend system. To run, use "LEGACY_BACKEND_START=1 yarn start".`, + hasSrcIndexEntry + ? `The 'dev' directory is missing. The plugin might not be updated for the new backend system. To run, use "LEGACY_BACKEND_START=1 yarn start".` + : `The 'dev' directory is missing. Please create a proper dev/index.ts in order to start the plugin.`, ); return; } @@ -68,7 +74,9 @@ export async function startBackendPlugin(options: StartBackendOptions) { } else { const hasEntry = await fs.pathExists(paths.resolveTarget('src', 'run.ts')); if (!hasEntry) { - console.log(`src/run.ts is missing.`); + console.warn( + `src/run.ts is missing. Please create the file or run the command without LEGACY_BACKEND_START`, + ); return; } From 4665709122cffcc5d757cc3e696f1b371c73ad5f Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Fri, 24 Nov 2023 16:55:48 +0100 Subject: [PATCH 6/6] cli: check for dev/index.ts Signed-off-by: Vincenzo Scamporlino --- packages/cli/src/commands/start/startBackend.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/start/startBackend.ts b/packages/cli/src/commands/start/startBackend.ts index f5dfecdd21..25758a0939 100644 --- a/packages/cli/src/commands/start/startBackend.ts +++ b/packages/cli/src/commands/start/startBackend.ts @@ -49,12 +49,14 @@ export async function startBackend(options: StartBackendOptions) { export async function startBackendPlugin(options: StartBackendOptions) { if (!process.env.LEGACY_BACKEND_START) { - const hasDevEntry = await fs.pathExists(paths.resolveTarget('dev')); + const hasDevIndexEntry = await fs.pathExists( + paths.resolveTarget('dev', 'index.ts'), + ); const hasSrcIndexEntry = await fs.pathExists( paths.resolveTarget('src', 'run.ts'), ); - if (!hasDevEntry && !hasSrcIndexEntry) { + if (!hasDevIndexEntry && !hasSrcIndexEntry) { console.warn( hasSrcIndexEntry ? `The 'dev' directory is missing. The plugin might not be updated for the new backend system. To run, use "LEGACY_BACKEND_START=1 yarn start".`