From 3f49724db809c81b6a6f53772d7ca10e534477fd Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 5 Sep 2023 18:07:27 +0200 Subject: [PATCH] cli,frontend-app-api: more cleanup Signed-off-by: Patrik Oldsberg --- packages/app-next/app-config.yaml | 1 + packages/cli/src/lib/bundler/bundle.ts | 4 ++-- packages/cli/src/lib/bundler/packageDetection.ts | 4 ++-- packages/cli/src/lib/bundler/server.ts | 4 +++- packages/frontend-app-api/src/wiring/discovery.test.ts | 7 +++++-- packages/frontend-app-api/src/wiring/discovery.ts | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/app-next/app-config.yaml b/packages/app-next/app-config.yaml index c798420c39..c94d900b21 100644 --- a/packages/app-next/app-config.yaml +++ b/packages/app-next/app-config.yaml @@ -2,6 +2,7 @@ app: experimental: packages: 'all' # ✨ + # scmAuthExtension: >- # createScmAuthExtension({ # id: 'apis.scmAuth.addons.ghe', diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 11330df5b2..11e18320f1 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -27,7 +27,7 @@ import { createConfig, resolveBaseUrl } from './config'; import { BuildOptions } from './types'; import { resolveBundlingPaths } from './paths'; import chalk from 'chalk'; -import { createDetectedModulesEntrypoint } from './packageDetection'; +import { createDetectedModulesEntryPoint } from './packageDetection'; // TODO(Rugvip): Limits from CRA, we might want to tweak these though. const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; @@ -42,7 +42,7 @@ export async function buildBundle(options: BuildOptions) { const paths = resolveBundlingPaths(options); - const detectedModulesEntryPoint = await createDetectedModulesEntrypoint({ + const detectedModulesEntryPoint = await createDetectedModulesEntryPoint({ config: options.fullConfig, targetPath: paths.targetPath, }); diff --git a/packages/cli/src/lib/bundler/packageDetection.ts b/packages/cli/src/lib/bundler/packageDetection.ts index bcc10a358b..293ef74f81 100644 --- a/packages/cli/src/lib/bundler/packageDetection.ts +++ b/packages/cli/src/lib/bundler/packageDetection.ts @@ -32,7 +32,7 @@ function readPackageDetectionConfig( config: Config, ): PackageDetectionConfig | undefined { const packages = config.getOptional('app.experimental.packages'); - if (!packages) { + if (packages === undefined || packages === null) { return undefined; } @@ -100,7 +100,7 @@ async function writeDetectedPackagesModule(packageNames: string[]) { ); } -export async function createDetectedModulesEntrypoint(options: { +export async function createDetectedModulesEntryPoint(options: { config: Config; targetPath: string; watch?: () => void; diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index afd7a015bf..78f6bb7823 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -31,12 +31,13 @@ import { paths as libPaths } from '../../lib/paths'; import { loadCliConfig } from '../config'; import { Lockfile } from '../versioning'; import { createConfig, resolveBaseUrl } from './config'; -import { createDetectedModulesEntrypoint as createDetectedModulesEntryPoint } from './packageDetection'; +import { createDetectedModulesEntryPoint } from './packageDetection'; import { resolveBundlingPaths } from './paths'; import { ServeOptions } from './types'; export async function serveBundle(options: ServeOptions) { const paths = resolveBundlingPaths(options); + const targetPkg = await fs.readJson(paths.targetPackageJson); if (options.verifyVersions) { const lockfile = await Lockfile.load( @@ -170,6 +171,7 @@ export async function serveBundle(options: ServeOptions) { : false, host, port, + proxy: targetPkg.proxy, // When the dev server is behind a proxy, the host and public hostname differ allowedHosts: [url.hostname], client: { diff --git a/packages/frontend-app-api/src/wiring/discovery.test.ts b/packages/frontend-app-api/src/wiring/discovery.test.ts index 249f9dcea9..a93f853c1b 100644 --- a/packages/frontend-app-api/src/wiring/discovery.test.ts +++ b/packages/frontend-app-api/src/wiring/discovery.test.ts @@ -57,14 +57,14 @@ describe('getAvailablePlugins', () => { { module: { testPlugin, - a: 1, + a: 'a', b: null, c: undefined, d: Symbol('wat'), e: () => {}, f: [], g: {}, - h: 'h', + h: class {}, i: NaN, j: Infinity, k: -Infinity, @@ -80,6 +80,9 @@ describe('getAvailablePlugins', () => { u: false, v: true, w: 0, + x: 1, + y: -1, + z: '', }, }, ], diff --git a/packages/frontend-app-api/src/wiring/discovery.ts b/packages/frontend-app-api/src/wiring/discovery.ts index 5ef15f77cb..7b0f4a50e4 100644 --- a/packages/frontend-app-api/src/wiring/discovery.ts +++ b/packages/frontend-app-api/src/wiring/discovery.ts @@ -30,7 +30,7 @@ export function getAvailablePlugins(): BackstagePlugin[] { return ( discovered?.modules.flatMap(({ module: mod }) => - Object.values(mod).flatMap(val => (isBackstagePlugin(val) ? [val] : [])), + Object.values(mod).filter(isBackstagePlugin), ) ?? [] ); }