Skip to content

Commit

Permalink
refactor: remove runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed May 17, 2024
1 parent 7344b53 commit 9c1a27b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
17 changes: 2 additions & 15 deletions lib/plugins/paragon-webpack-plugin/ParagonWebpackPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { Compilation, sources } = require('webpack');
const dotenv = require('dotenv');
const fs = require('fs');
const path = require('path');
const {
Expand All @@ -8,19 +7,12 @@ const {
} = require('../../../config/data/paragonUtils');
const {
injectMetadataIntoDocument,
// getMfeRuntimeConfig,
getParagonStylesheetUrls,
injectParagonCoreStylesheets,
injectParagonThemeVariantStylesheets,
} = require('./utils');
const resolvePrivateEnvConfig = require('../../resolvePrivateEnvConfig');

// Add process env vars. Currently used only for setting the
// server port and the publicPath
dotenv.config({
path: path.resolve(process.cwd(), '.env.development'),
});

// Allow private/local overrides of env vars from .env.development for config settings
// that you'd like to persist locally during development, without the risk of checking
// in temporary modifications to .env.development.
Expand Down Expand Up @@ -57,21 +49,16 @@ class ParagonWebpackPlugin {
/**
* Resolves the MFE configuration for ``PARAGON_THEME_URLS`` in the following priority order:
*
* 1. ``mfeRuntimeApiConfig.PARAGON_THEME_URLS``
* 2. ``envConfig.PARAGON_THEME_URLS``
* 3. ``process.env.PARAGON_THEME_URLS``
* 1. ``envConfig.PARAGON_THEME_URLS``
* 2. ``process.env.PARAGON_THEME_URLS``
*
* @returns {Object} Metadata about the Paragon and brand theme URLs from configuration.
*/
async resolveParagonThemeUrlsFromConfig() {
// const mfeRuntimeApiConfig = await getMfeRuntimeConfig();
let envConfig;
if (fs.existsSync(envConfigFile)) {
envConfig = require(envConfigFile);
}
// const paragonThemeUrls = mfeRuntimeApiConfig?.PARAGON_THEME_URLS
// ?? envConfig?.PARAGON_THEME_URLS
// ?? process.env.PARAGON_THEME_URLS;

const paragonThemeUrls = envConfig?.PARAGON_THEME_URLS ?? process.env.PARAGON_THEME_URLS;

Expand Down
17 changes: 1 addition & 16 deletions lib/plugins/paragon-webpack-plugin/utils.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
const { sources } = require('webpack');
const parse5 = require('parse5');
const axios = require('axios');

async function getMfeRuntimeConfig() {
const {
APP_ID,
MFE_CONFIG_API_URL,
} = process.env;
const queryParams = new URLSearchParams({
mfe: APP_ID,
});
const url = `${MFE_CONFIG_API_URL}?${queryParams.toString()}`;
const response = await axios.get(url);
return response.data;
}

function getDescendantByTag(node, tag) {
for (let i = 0; i < node.childNodes?.length; i++) {
Expand Down Expand Up @@ -292,7 +278,7 @@ function handleVersionSubstitution({ url, wildcardKeyword, localVersion }) {
if (!url || !url.includes(wildcardKeyword) || !localVersion) {
return url;
}
return url.replace(wildcardKeyword, localVersion);
return url.replaceAll(wildcardKeyword, localVersion);
}

function getParagonStylesheetUrls({ paragonThemeUrls, paragonVersion, brandVersion }) {
Expand Down Expand Up @@ -381,7 +367,6 @@ function injectParagonThemeVariantStylesheets({

module.exports = {
injectMetadataIntoDocument,
getMfeRuntimeConfig,
getParagonStylesheetUrls,
injectParagonCoreStylesheets,
injectParagonThemeVariantStylesheets,
Expand Down

0 comments on commit 9c1a27b

Please sign in to comment.