cli: add optional auth entry point for apps

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-01-13 12:38:52 +01:00
parent 0c8fa7198c
commit c624938226
3 changed files with 40 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Add support for optional `auth` app entry point.
+20 -1
View File
@@ -127,6 +127,8 @@ export async function createConfig(
plugins.push(
new HtmlWebpackPlugin({
chunks: ['main'],
filename: 'index.html',
template: paths.targetHtml,
templateParameters: {
publicPath,
@@ -135,6 +137,20 @@ export async function createConfig(
}),
);
if (paths.targetAuthEntry) {
plugins.push(
new HtmlWebpackPlugin({
chunks: ['auth'],
filename: 'auth/index.html',
template: paths.targetHtml,
templateParameters: {
publicPath,
config: frontendConfig,
},
}),
);
}
const buildInfo = await readBuildInfo();
plugins.push(
new webpack.DefinePlugin({
@@ -172,7 +188,10 @@ export async function createConfig(
},
devtool: isDev ? 'eval-cheap-module-source-map' : 'source-map',
context: paths.targetPath,
entry: [...(options.additionalEntryPoints ?? []), paths.targetEntry],
entry: {
main: [...(options.additionalEntryPoints ?? []), paths.targetEntry],
...(paths.targetAuthEntry ? { auth: paths.targetAuthEntry } : {}),
},
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json', '.wasm'],
mainFields: ['browser', 'module', 'main'],
+15
View File
@@ -38,6 +38,14 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) {
return resolvePath(targetDir, `${pathString}.js`);
};
const resolveTargetOptionalModule = (pathString: string) => {
try {
return resolveTargetModule(pathString);
} catch {
return undefined;
}
};
let targetPublic = undefined;
let targetHtml = resolvePath(targetDir, 'public/index.html');
@@ -51,12 +59,18 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) {
}
}
let targetAuthHtml = targetHtml;
if (fs.pathExistsSync(resolvePath(targetDir, 'public/auth.html'))) {
targetAuthHtml = resolvePath(targetDir, 'public/auth.html');
}
// Backend plugin dev run file
const targetRunFile = resolvePath(targetDir, 'src/run.ts');
const runFileExists = fs.pathExistsSync(targetRunFile);
return {
targetHtml,
targetAuthHtml,
targetPublic,
targetPath: resolvePath(targetDir, '.'),
targetRunFile: runFileExists ? targetRunFile : undefined,
@@ -65,6 +79,7 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) {
targetSrc: resolvePath(targetDir, 'src'),
targetDev: resolvePath(targetDir, 'dev'),
targetEntry: resolveTargetModule(entry),
targetAuthEntry: resolveTargetOptionalModule('src/auth'),
targetTsConfig: paths.resolveTargetRoot('tsconfig.json'),
targetPackageJson: resolvePath(targetDir, 'package.json'),
rootNodeModules: paths.resolveTargetRoot('node_modules'),