Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bastilian committed May 18, 2024
1 parent fc7ad4c commit 213d671
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/config-utils/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const proxy = ({
routes,
routesPath,
useProxy,
// TODO It should be possible to set this as well from the outside.
proxyURL = 'http://squid.corp.redhat.com:3128',
standalone,
port,
Expand Down Expand Up @@ -223,6 +224,8 @@ const proxy = ({
}

let standaloneConfig: ReturnType<typeof getConfig>;
// TODO do we need this "standalone" mode still?
// We should at least extract this into it's own module
if (standalone) {
standaloneConfig = getConfig(standalone, localChrome, env, port);
// Create network for services.
Expand Down Expand Up @@ -362,6 +365,7 @@ const proxy = ({
...(proxy.length > 0 && { proxy }),
onListening(server) {
if (useProxy || standaloneConfig) {
// TODO Refactor to use the hostname provided from a config/option higher up.
const host = useProxy ? `${majorEnv}.foo.redhat.com` : 'localhost';
const origin = `http${server.options.https ? 's' : ''}://${host}:${server.options.port}`;
fecLogger(LogType.info, '');
Expand All @@ -371,6 +375,7 @@ const proxy = ({
fecLogger(LogType.info, '');
}
},
// TODO Deprecated: needs to be replaced with `setupMiddleware`
onBeforeSetupMiddleware({ app, compiler, options }) {
app?.enable('strict routing'); // trailing slashes are mean

Expand All @@ -383,6 +388,7 @@ const proxy = ({
* Allow serving chrome assets
* This will allow running chrome as a host application
*/
// TODO Most of this should be ...not here.
if (!isChrome) {
let chromePath = localChrome;
if (standaloneConfig) {
Expand All @@ -394,6 +400,7 @@ const proxy = ({

onBeforeSetupMiddleware({ chromePath });

// TODO What is this?
if (app && chromePath) {
registerChrome({
app,
Expand All @@ -405,6 +412,7 @@ const proxy = ({
}
}

// TODO and this?
registry.forEach((cb) =>
cb({
app,
Expand Down
6 changes: 6 additions & 0 deletions packages/config/src/bin/dev-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ async function devScript(
process.exit(1);
}
} else {
// TODO This is neat,
// but we should just default to stage-stable, which is what we need in dev 99% of the time.
await setEnv(cwd);
}

Expand Down Expand Up @@ -153,12 +155,16 @@ async function devScript(
process.env.OUTPUT_CONFIGS = argv.outputConfigs;
}

// TODO Move to WebpackDevServer API instead of spawning a process
// Spawning a process does act weird when quitting the process, due to devservers way of quitting.
// It would also allow us to not have to (ab)use env variable to pass settings
spawn(`npm exec -- webpack serve -c ${configPath}`, [], {
stdio: [process.stdout, process.stdout, process.stdout],
cwd,
shell: true,
});

// TODO Move this to be middleware that won't need a separate process.
if (fecConfig.interceptChromeConfig === true) {
const interceptorServerPath = resolve(__dirname, './csc-interceptor-server.js');
const interceptorServerArgs = [interceptorServerPath];
Expand Down
4 changes: 3 additions & 1 deletion packages/config/src/lib/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const createConfig = ({
const devServerPort = typeof port === 'number' ? port : useProxy || standalone ? 1337 : 8002;
return {
mode: mode || (isProd ? 'production' : 'development'),
devtool: false,
devtool: isProd ? false : 'eval',
infrastructureLogging: {
colors: true,
console: fecWebpackLogger(),
Expand Down Expand Up @@ -259,6 +259,7 @@ export const createConfig = ({
directory: `${rootFolder || ''}/dist`,
},
port: devServerPort,
// TODO deprecated and should be replaced with `server` when fully moving to webpack(devserver) v5
https: https || Boolean(useProxy),
host: '0.0.0.0', // This shares on local network. Needed for docker.host.internal
hot: internalHotReload, // Use livereload instead of HMR which is spotty with federated modules
Expand All @@ -279,6 +280,7 @@ export const createConfig = ({
disableDotRule: true,
},
devMiddleware: {
// TODO Figure out if this helps in any way or if it is required for something
writeToDisk: true,
},
client,
Expand Down
18 changes: 9 additions & 9 deletions packages/config/src/lib/createPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ export const createPlugins = ({
const hasTsConfig = glob.sync(path.resolve(rootFolder, './{tsconfig.json,!(node_modules)/**/tsconfig.json}')).length > 0;
const fileHash = !internalHotReload && useFileHash;
return [
...(generateSourceMaps
? [
new SourceMapDevToolPlugin({
test: 'js',
exclude: /(node_modules|bower_components)/i,
filename: !fileHash ? 'sourcemaps/[name].js.map' : 'sourcemaps/[name].[contenthash].js.map',
}),
]
: []),
// ...(generateSourceMaps
// ? [
// new SourceMapDevToolPlugin({
// test: 'js',
// exclude: /(node_modules|bower_components)/i,
// filename: !fileHash ? 'sourcemaps/[name].js.map' : 'sourcemaps/[name].[contenthash].js.map',
// }),
// ]
// : []),
new MiniCssExtractPlugin({
chunkFilename: !fileHash ? 'css/[name].css' : 'css/[name].[contenthash].css',
filename: !fileHash ? 'css/[name].css' : 'css/[name].[contenthash].css',
Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ const createFecConfig = (
config: ReturnType<typeof createConfig>;
plugins: ReturnType<typeof createPlugins>;
} => {
// TODO ... sus.
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
let gitBranch;
try {
gitBranch = process.env.TRAVIS_BRANCH || process.env.BRANCH || gitRevisionPlugin.branch();
Expand Down

0 comments on commit 213d671

Please sign in to comment.