Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(fec): Fixes, improvements and moar options #2007

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bastilian
Copy link
Member

@bastilian bastilian commented May 18, 2024

This PR adds a (few) fix(es) and improvements to the fec command:

  • Enables npm run start commands for the config packages
    
Just for convenience. I got tired of manually building all the time.
  • Fixes the port setting
    
The —port flag was not fully working I thought that the PORT var was recognised by fec/webpack, but I realised it is something we have implemented in the apps’ fec config.
  • Adds an option to expose the “LOCAL_APPS” feature
    This is to make it more convenient to start an app adhoc with routes for another app, without having to use a ENV var. The code to build the routes has also been slightly refactored and now also allows to setup routes for /api as well via an --api option
  • Adds more cli flags for fec options
    
These are flags for options that we have often configured in fec.config.js via ENV vars to allow them to be variable then calling fec. For example, in many apps we use a PROXY=true env variable to toggle useProxy int the fec config.
  • Rewrites downloading insights-chrome’s index.html
    This is to try and make the onBeforeSetupMiddleware obsolete, or at least reduce its responsibilities to make migrating to setupMiddleware easier or even unnecessary. It's also a cleaner implementation using the HTMLWebpackPlugin. At least a tiny bit. The cloning of the repo is removed as well. We really only need the index.html file, but if we realise we need more we can easily restore this.
  • Cleans up logging
    Where I touched code I replaced the console.log calls with fecLogger. Even webpack now logs via fecLogger. For consistency.
  • Adds an option to dump configs
    It has been very useful at times when debugging issues to inspect the fec config and webpack config. 
This new option will make it more convenient without having to hack in some console.logs somewhere, and will show the full "fec" config passed in and the full resulting webpack config.

@bastilian bastilian changed the title Fec cli fixes refactor(fec): Fixes, improvements and moar options May 18, 2024
}

return {
...console,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... it works, but I'm a bit unsure if that's right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its fine.

}

return {
...console,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its fine.

routes: internalProxyRoutes,
appUrl,
...(fecConfig.appUrl ? { appUrl: createAppUrl(fecConfig.appUrl) } : {}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the app URL is not setup, the dev proxy won't really work. We should throw error rather than using fallback.

@@ -13,6 +14,10 @@ const createIncludes = (eager = false): { [module: string]: WebpackSharedConfig
'@redhat-cloud-services/chrome': { singleton: true },
axios: {},
lodash: {},
// TODO I would propose to remove this from the shared deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should remove anything that is not a singleton. And generate the shared dependencies form that package.json.

With the exception to PF as we are generating the shared modules individually.

We should also avoid sharing anything without a version requirement.

process.exit();
if (!skipProxyCheck && hasCurlInstalled()) {
if (!checkLocalAppHost(appName, appUrl, appPort)) {
process.exit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add an exit code. We read it in other processes sometimes.

}

if (customProxy) {
proxy.push(...customProxy);
}

let standaloneConfig: ReturnType<typeof getConfig>;
// TODO do we need this "standalone" mode still?
// We should at least extract this into it's own module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some are using it, but I am not a fan of it. I don't think we can remove it just yet.

However, it was never maintained by us. At minimum I would deprecate the option and a log a warning.

@@ -267,6 +282,7 @@ export const createConfig = ({
disableDotRule: true,
},
devMiddleware: {
// TODO Figure out if this helps in any way or if it is required for something
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to be able to modify the build files in dev env.

@@ -287,14 +303,12 @@ export const createConfig = ({
proxyVerbose,
target,
registry,
onBeforeSetupMiddleware: ({ chromePath }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to stay. Apps do not have their own HTML templates.

@@ -11,12 +12,19 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'
const { glob } = require('glob');
const path = require('path');

const chromeIndexHtmlUrl = (env = 'dev-stable') => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use this. We will be removing the build repositories. Old build pipeline is coming to an end. We will be suing the container images as the source of truth for local chrome.


export interface FECConfiguration
extends Partial<Omit<CreateConfigOptions, 'appUrl' | 'appName' | 'env' | 'rootFolder'>>,
Partial<Omit<CreatePluginsOptions, 'rootFolder' | 'appName'>> {
appName: never;
appUrl: string | string[] | (string | RegExp)[];
appUrl?: string | string[] | (string | RegExp)[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mandatory.

configurations.isProd = configurations.isProd || process.env.NODE_ENV === 'production';
const isProd = configurations.isProd;
const { insights } = require(`${configurations.rootFolder}/package.json`);

// TODO We should deprecated building based upon git branches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Remove only once all apps are on the current build pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants