From c6249382260d3351132bc8d54c28b8f9d2fa6da7 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 13 Jan 2024 12:38:52 +0100 Subject: [PATCH 1/7] cli: add optional auth entry point for apps Signed-off-by: Patrik Oldsberg --- .changeset/large-tables-wonder.md | 5 +++++ packages/cli/src/lib/bundler/config.ts | 21 ++++++++++++++++++++- packages/cli/src/lib/bundler/paths.ts | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/large-tables-wonder.md diff --git a/.changeset/large-tables-wonder.md b/.changeset/large-tables-wonder.md new file mode 100644 index 0000000000..05ab456543 --- /dev/null +++ b/.changeset/large-tables-wonder.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Add support for optional `auth` app entry point. diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index a9d5c2aa67..1361849063 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -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'], diff --git a/packages/cli/src/lib/bundler/paths.ts b/packages/cli/src/lib/bundler/paths.ts index 3d4925c66b..33936137c5 100644 --- a/packages/cli/src/lib/bundler/paths.ts +++ b/packages/cli/src/lib/bundler/paths.ts @@ -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'), From 8968cda34f99d053f2f35336733f15fb68089bda Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 13 Jan 2024 12:43:40 +0100 Subject: [PATCH 2/7] example-app: add separate auth entry point Signed-off-by: Patrik Oldsberg --- packages/app/src/auth.tsx | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/app/src/auth.tsx diff --git a/packages/app/src/auth.tsx b/packages/app/src/auth.tsx new file mode 100644 index 0000000000..e06df51754 --- /dev/null +++ b/packages/app/src/auth.tsx @@ -0,0 +1,71 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createApp } from '@backstage/app-defaults'; +import { AppRouter } from '@backstage/core-app-api'; +import { + AlertDisplay, + OAuthRequestDialog, + SignInPage, +} from '@backstage/core-components'; +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import { providers } from '../src/identityProviders'; +import { + configApiRef, + createApiFactory, + discoveryApiRef, +} from '@backstage/core-plugin-api'; +import { AuthProxyDiscoveryApi } from '../src/AuthProxyDiscoveryApi'; + +const app = createApp({ + apis: [ + createApiFactory({ + api: discoveryApiRef, + deps: { configApi: configApiRef }, + factory: ({ configApi }) => AuthProxyDiscoveryApi.fromConfig(configApi), + }), + ], + components: { + SignInPage: props => { + return ( + + ); + }, + }, +}); + +function RedirectToRoot() { + window.location.pathname += '/..'; + return
; +} + +const App = app.createRoot( + <> + + + + + + , +); + +ReactDOM.createRoot(document.getElementById('root')!).render(); From 47c686e4a127c3e08f63b9758ce32e300dd35f79 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 13 Jan 2024 15:00:55 +0100 Subject: [PATCH 3/7] cli: switch app auth entry to be a separate compilation Signed-off-by: Patrik Oldsberg --- packages/cli/src/lib/bundler/bundle.ts | 44 ++++++++++++++++++++------ packages/cli/src/lib/bundler/config.ts | 21 +----------- packages/cli/src/lib/bundler/paths.ts | 29 ++++++++--------- packages/cli/src/lib/bundler/server.ts | 16 ++++++++-- 4 files changed, 62 insertions(+), 48 deletions(-) diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 11e18320f1..79f58e8532 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -25,7 +25,7 @@ import { import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages'; import { createConfig, resolveBaseUrl } from './config'; import { BuildOptions } from './types'; -import { resolveBundlingPaths } from './paths'; +import { resolveBundlingPaths, resolveOptionalBundlingPaths } from './paths'; import chalk from 'chalk'; import { createDetectedModulesEntryPoint } from './packageDetection'; @@ -47,18 +47,34 @@ export async function buildBundle(options: BuildOptions) { targetPath: paths.targetPath, }); - const config = await createConfig(paths, { + const commonConfigOptions = { ...options, checksEnabled: false, isDev: false, baseUrl: resolveBaseUrl(options.frontendConfig), getFrontendAppConfigs: () => options.frontendAppConfigs, - additionalEntryPoints: detectedModulesEntryPoint, + }; + const configs = [ + await createConfig(paths, { + ...commonConfigOptions, + additionalEntryPoints: detectedModulesEntryPoint, + }), + ]; + + const authPaths = await resolveOptionalBundlingPaths({ + entry: 'src/auth', + dist: 'dist/auth', }); + if (authPaths) { + configs.push(await createConfig(authPaths, commonConfigOptions)); + } const isCi = yn(process.env.CI, { default: false }); const previousFileSizes = await measureFileSizesBeforeBuild(paths.targetDist); + const previousAuthSizes = authPaths + ? await measureFileSizesBeforeBuild(authPaths.targetDist) + : undefined; await fs.emptyDir(paths.targetDist); if (paths.targetPublic) { @@ -76,33 +92,43 @@ export async function buildBundle(options: BuildOptions) { ); } - const { stats } = await build(config, isCi); + const { stats } = await build(configs, isCi); if (!stats) { throw new Error('No stats returned'); } + const [mainStats, authStats] = stats.stats; if (statsJsonEnabled) { // No @types/bfj await require('bfj').write( resolvePath(paths.targetDist, 'bundle-stats.json'), - stats.toJson(), + mainStats.toJson(), ); } printFileSizesAfterBuild( - stats, + mainStats, previousFileSizes, paths.targetDist, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE, ); + if (authPaths && previousAuthSizes) { + printFileSizesAfterBuild( + authStats, + previousAuthSizes, + authPaths.targetDist, + WARN_AFTER_BUNDLE_GZIP_SIZE, + WARN_AFTER_CHUNK_GZIP_SIZE, + ); + } } -async function build(config: webpack.Configuration, isCi: boolean) { - const stats = await new Promise( +async function build(configs: webpack.Configuration[], isCi: boolean) { + const stats = await new Promise( (resolve, reject) => { - webpack(config, (err, buildStats) => { + webpack(configs, (err, buildStats) => { if (err) { if (err.message) { const { errors } = formatWebpackMessages({ diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index 1361849063..a9d5c2aa67 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -127,8 +127,6 @@ export async function createConfig( plugins.push( new HtmlWebpackPlugin({ - chunks: ['main'], - filename: 'index.html', template: paths.targetHtml, templateParameters: { publicPath, @@ -137,20 +135,6 @@ 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({ @@ -188,10 +172,7 @@ export async function createConfig( }, devtool: isDev ? 'eval-cheap-module-source-map' : 'source-map', context: paths.targetPath, - entry: { - main: [...(options.additionalEntryPoints ?? []), paths.targetEntry], - ...(paths.targetAuthEntry ? { auth: paths.targetAuthEntry } : {}), - }, + entry: [...(options.additionalEntryPoints ?? []), paths.targetEntry], resolve: { extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json', '.wasm'], mainFields: ['browser', 'module', 'main'], diff --git a/packages/cli/src/lib/bundler/paths.ts b/packages/cli/src/lib/bundler/paths.ts index 33936137c5..572a96337f 100644 --- a/packages/cli/src/lib/bundler/paths.ts +++ b/packages/cli/src/lib/bundler/paths.ts @@ -23,6 +23,8 @@ export type BundlingPathsOptions = { entry: string; // Target directory, defaulting to paths.targetDir targetDir?: string; + // Relative dist directory, defaulting to 'dist' + dist?: string; }; export function resolveBundlingPaths(options: BundlingPathsOptions) { @@ -38,14 +40,6 @@ 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'); @@ -59,27 +53,20 @@ 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, - targetDist: resolvePath(targetDir, 'dist'), + targetDist: resolvePath(targetDir, options.dist ?? 'dist'), targetAssets: resolvePath(targetDir, 'assets'), 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'), @@ -87,4 +74,14 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) { }; } +export async function resolveOptionalBundlingPaths( + options: BundlingPathsOptions, +) { + const resolvedPaths = resolveBundlingPaths(options); + if (await fs.pathExists(resolvedPaths.targetEntry)) { + return resolvedPaths; + } + return undefined; +} + export type BundlingPaths = ReturnType; diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index 2fd1385584..f9d6f3590d 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -32,7 +32,7 @@ import { loadCliConfig } from '../config'; import { Lockfile } from '../versioning'; import { createConfig, resolveBaseUrl } from './config'; import { createDetectedModulesEntryPoint } from './packageDetection'; -import { resolveBundlingPaths } from './paths'; +import { resolveBundlingPaths, resolveOptionalBundlingPaths } from './paths'; import { ServeOptions } from './types'; import { hasReactDomClient } from './hasReactDomClient'; @@ -147,7 +147,7 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be }, }); - const config = await createConfig(paths, { + const commonConfigOptions = { ...options, checksEnabled: options.checksEnabled, isDev: true, @@ -156,6 +156,10 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be getFrontendAppConfigs: () => { return latestFrontendAppConfigs; }, + }; + + const config = await createConfig(paths, { + ...commonConfigOptions, additionalEntryPoints: detectedModulesEntryPoint, }); @@ -199,7 +203,13 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be root: paths.targetPath, }); } else { - const compiler = webpack(config); + const authPaths = await resolveOptionalBundlingPaths({ + entry: 'src/auth', + dist: 'dist/auth', + }); + const compiler = authPaths + ? webpack([config, await createConfig(authPaths, commonConfigOptions)]) + : webpack(config); webpackServer = new WebpackDevServer( { From 3a46297ddf46270c8379ad0ba336ccecfde51f9a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 22 Jan 2024 13:42:41 +0100 Subject: [PATCH 4/7] app: fix auth entry point redirect Signed-off-by: Patrik Oldsberg --- packages/app/src/auth.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/app/src/auth.tsx b/packages/app/src/auth.tsx index e06df51754..9e5f89b4c2 100644 --- a/packages/app/src/auth.tsx +++ b/packages/app/src/auth.tsx @@ -28,9 +28,20 @@ import { configApiRef, createApiFactory, discoveryApiRef, + useApi, } from '@backstage/core-plugin-api'; import { AuthProxyDiscoveryApi } from '../src/AuthProxyDiscoveryApi'; +// TODO(Rugvip): make this available via some util, or maybe Utility API? +function readBasePath(configApi: typeof configApiRef.T) { + let { pathname } = new URL( + configApi.getOptionalString('app.baseUrl') ?? '/', + 'http://sample.dev', // baseUrl can be specified as just a path + ); + pathname = pathname.replace(/\/*$/, ''); + return pathname; +} + const app = createApp({ apis: [ createApiFactory({ @@ -54,7 +65,7 @@ const app = createApp({ }); function RedirectToRoot() { - window.location.pathname += '/..'; + window.location.pathname = readBasePath(useApi(configApiRef)); return
; } From e7316e76fcedc3901b02944b9e70942882ef87a8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 22 Jan 2024 13:44:15 +0100 Subject: [PATCH 5/7] cli: use correct public path for /auth entry point bundles Signed-off-by: Patrik Oldsberg --- packages/cli/src/lib/bundler/bundle.ts | 7 ++++++- packages/cli/src/lib/bundler/config.ts | 8 ++++++-- packages/cli/src/lib/bundler/server.ts | 8 +++++++- packages/cli/src/lib/bundler/types.ts | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 79f58e8532..72931ec3e0 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -66,7 +66,12 @@ export async function buildBundle(options: BuildOptions) { dist: 'dist/auth', }); if (authPaths) { - configs.push(await createConfig(authPaths, commonConfigOptions)); + configs.push( + await createConfig(authPaths, { + ...commonConfigOptions, + publicSubPath: '/auth', + }), + ); } const isCi = yn(process.env.CI, { default: false }); diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index a9d5c2aa67..7c72dc81f7 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -92,7 +92,7 @@ export async function createConfig( paths: BundlingPaths, options: BundlingOptions, ): Promise { - const { checksEnabled, isDev, frontendConfig } = options; + const { checksEnabled, isDev, frontendConfig, publicSubPath = '' } = options; const { plugins, loaders } = transforms(options); // Any package that is part of the monorepo but outside the monorepo root dir need @@ -102,7 +102,11 @@ export async function createConfig( const baseUrl = frontendConfig.getString('app.baseUrl'); const validBaseUrl = new URL(baseUrl); - const publicPath = validBaseUrl.pathname.replace(/\/$/, ''); + let publicPath = validBaseUrl.pathname.replace(/\/$/, ''); + if (publicSubPath) { + publicPath = `${publicPath}${publicSubPath}`.replace('//', '/'); + } + if (checksEnabled) { plugins.push( new ForkTsCheckerWebpackPlugin({ diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index f9d6f3590d..3954c1ee03 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -208,7 +208,13 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be dist: 'dist/auth', }); const compiler = authPaths - ? webpack([config, await createConfig(authPaths, commonConfigOptions)]) + ? webpack([ + config, + await createConfig(authPaths, { + ...commonConfigOptions, + publicSubPath: '/auth', + }), + ]) : webpack(config); webpackServer = new WebpackDevServer( diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index 414414fa81..c836fd7a29 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -26,6 +26,8 @@ export type BundlingOptions = { baseUrl: URL; parallelism?: number; additionalEntryPoints?: string[]; + // Path to append to the detected public path, e.g. '/auth' + publicSubPath?: string; }; export type ServeOptions = BundlingPathsOptions & { From 9b7c6c8dd5f2d3bbfcbcca80b622fc0dd6e070ae Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 22 Jan 2024 13:47:32 +0100 Subject: [PATCH 6/7] cli: add experimental warning for auth entry point build Signed-off-by: Patrik Oldsberg --- .changeset/large-tables-wonder.md | 2 +- packages/cli/src/lib/bundler/bundle.ts | 5 +++++ packages/cli/src/lib/bundler/server.ts | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.changeset/large-tables-wonder.md b/.changeset/large-tables-wonder.md index 05ab456543..f54402dbd4 100644 --- a/.changeset/large-tables-wonder.md +++ b/.changeset/large-tables-wonder.md @@ -2,4 +2,4 @@ '@backstage/cli': patch --- -Add support for optional `auth` app entry point. +Add experimental support for optional `auth` app entry point. diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 72931ec3e0..2c3311cb39 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -66,6 +66,11 @@ export async function buildBundle(options: BuildOptions) { dist: 'dist/auth', }); if (authPaths) { + console.log( + chalk.yellow( + `⚠️ WARNING: The app /auth entry point is an experimental feature that may receive immediate breaking changes.`, + ), + ); configs.push( await createConfig(authPaths, { ...commonConfigOptions, diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index 3954c1ee03..5b3bd22720 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -207,6 +207,13 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be entry: 'src/auth', dist: 'dist/auth', }); + if (authPaths) { + console.log( + chalk.yellow( + `⚠️ WARNING: The app /auth entry point is an experimental feature that may receive immediate breaking changes.`, + ), + ); + } const compiler = authPaths ? webpack([ config, From f518683b97e1521de1fe074f4bf6e56d428dd78f Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 23 Jan 2024 13:39:48 +0100 Subject: [PATCH 7/7] cli: switch experimental /auth entry to index-public-experimental at /public instead Signed-off-by: Patrik Oldsberg --- ...auth.tsx => index-public-experimental.tsx} | 0 packages/cli/src/lib/bundler/bundle.ts | 20 +++++++++---------- packages/cli/src/lib/bundler/server.ts | 16 +++++++-------- packages/cli/src/lib/bundler/types.ts | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) rename packages/app/src/{auth.tsx => index-public-experimental.tsx} (100%) diff --git a/packages/app/src/auth.tsx b/packages/app/src/index-public-experimental.tsx similarity index 100% rename from packages/app/src/auth.tsx rename to packages/app/src/index-public-experimental.tsx diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 2c3311cb39..d0624c93ff 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -61,20 +61,20 @@ export async function buildBundle(options: BuildOptions) { }), ]; - const authPaths = await resolveOptionalBundlingPaths({ - entry: 'src/auth', - dist: 'dist/auth', + const publicPaths = await resolveOptionalBundlingPaths({ + entry: 'src/index-public-experimental', + dist: 'dist/public', }); - if (authPaths) { + if (publicPaths) { console.log( chalk.yellow( `⚠️ WARNING: The app /auth entry point is an experimental feature that may receive immediate breaking changes.`, ), ); configs.push( - await createConfig(authPaths, { + await createConfig(publicPaths, { ...commonConfigOptions, - publicSubPath: '/auth', + publicSubPath: '/public', }), ); } @@ -82,8 +82,8 @@ export async function buildBundle(options: BuildOptions) { const isCi = yn(process.env.CI, { default: false }); const previousFileSizes = await measureFileSizesBeforeBuild(paths.targetDist); - const previousAuthSizes = authPaths - ? await measureFileSizesBeforeBuild(authPaths.targetDist) + const previousAuthSizes = publicPaths + ? await measureFileSizesBeforeBuild(publicPaths.targetDist) : undefined; await fs.emptyDir(paths.targetDist); @@ -124,11 +124,11 @@ export async function buildBundle(options: BuildOptions) { WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE, ); - if (authPaths && previousAuthSizes) { + if (publicPaths && previousAuthSizes) { printFileSizesAfterBuild( authStats, previousAuthSizes, - authPaths.targetDist, + publicPaths.targetDist, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE, ); diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index 5b3bd22720..f1eb2e923d 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -203,23 +203,23 @@ DEPRECATION WARNING: React Router Beta is deprecated and support for it will be root: paths.targetPath, }); } else { - const authPaths = await resolveOptionalBundlingPaths({ - entry: 'src/auth', - dist: 'dist/auth', + const publicPaths = await resolveOptionalBundlingPaths({ + entry: 'src/index-public-experimental', + dist: 'dist/public', }); - if (authPaths) { + if (publicPaths) { console.log( chalk.yellow( - `⚠️ WARNING: The app /auth entry point is an experimental feature that may receive immediate breaking changes.`, + `⚠️ WARNING: The app /public entry point is an experimental feature that may receive immediate breaking changes.`, ), ); } - const compiler = authPaths + const compiler = publicPaths ? webpack([ config, - await createConfig(authPaths, { + await createConfig(publicPaths, { ...commonConfigOptions, - publicSubPath: '/auth', + publicSubPath: '/public', }), ]) : webpack(config); diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index c836fd7a29..4a9424dedb 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -26,7 +26,7 @@ export type BundlingOptions = { baseUrl: URL; parallelism?: number; additionalEntryPoints?: string[]; - // Path to append to the detected public path, e.g. '/auth' + // Path to append to the detected public path, e.g. '/public' publicSubPath?: string; };