cli: show legacy warning when starting standalone plugin

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-11-24 15:05:59 +01:00
parent f5de630e45
commit 01f67198f3
2 changed files with 46 additions and 13 deletions
+3 -2
View File
@@ -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<void> {
@@ -31,10 +31,11 @@ export async function command(opts: OptionValues): Promise<void> {
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,
+43 -11
View File
@@ -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();
}
}