Skip to content

Commit

Permalink
fix: handle scenario of no process.env value for New Relic plugins
Browse files Browse the repository at this point in the history
* Require env.config object after copying it into MFE
  • Loading branch information
jsnwesson committed Mar 1, 2024
1 parent 26de6b7 commit a3cc567
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions config/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ const HtmlWebpackNewRelicPlugin = require('../lib/plugins/html-webpack-new-relic
const commonConfig = require('./webpack.common.config');
const presets = require('../lib/presets');

/** This condition confirms whether the MFE has a JS-based configuration file and creates a copy of the file based
* on the filepath given. If the environment variable exists, then an env.config.js(x) file will be created at the root
* directory and its env variables can be accessed with getConfig().
/** This condition confirms whether the configuration for the MFE has switched to a JS-based configuration
* as previously implemented in frontend-build and frontend-platform. If the environment variable exists, then
* an env.config.js file will be created at the root directory and its env variables can be accessed with getConfig().
*
* https://github.com/openedx/frontend-build/blob/master/docs/0002-js-environment-config.md
* https://github.com/openedx/frontend-platform/blob/master/docs/decisions/0007-javascript-file-configuration.rst
*/

const envConfigPath = process.env.JS_CONFIG_FILEPATH;
let envConfig = {};

if (envConfigPath) {
// This handles the possibility that env.config will have either a JS or JSX extension
const envConfigFilename = envConfigPath.slice(envConfigPath.indexOf('env.config'));
fs.copyFileSync(envConfigPath, envConfigFilename);

fs.copyFile(envConfigPath, envConfigFilename, (err) => {
if (err) { throw err; }
});
}
let newConfigFilepath = path.resolve(process.cwd(), envConfigFilename);
envConfig = require(newConfigFilepath);
};

// Add process env vars. Currently used only for setting the PUBLIC_PATH.
dotenv.config({
Expand All @@ -63,12 +65,12 @@ if (process.env.ENABLE_NEW_RELIC !== 'false') {
agentID: process.env.NEW_RELIC_AGENT_ID || 'undefined_agent_id',
trustKey: process.env.NEW_RELIC_TRUST_KEY || 'undefined_trust_key',
licenseKey: process.env.NEW_RELIC_LICENSE_KEY || 'undefined_license_key',
applicationID: process.env.NEW_RELIC_APP_ID || 'undefined_application_id',
applicationID: envConfig.NEW_RELIC_APP_ID || process.env.NEW_RELIC_APP_ID || 'undefined_application_id',
}));
extraPlugins.push(new NewRelicSourceMapPlugin({
applicationId: process.env.NEW_RELIC_APP_ID,
applicationId: envConfig.NEW_RELIC_APP_ID || process.env.NEW_RELIC_APP_ID,
apiKey: process.env.NEW_RELIC_ADMIN_KEY,
staticAssetUrl: process.env.BASE_URL,
staticAssetUrl: envConfig.BASE_URL || process.env.BASE_URL,
// upload source maps in prod builds only
noop: typeof process.env.NEW_RELIC_ADMIN_KEY === 'undefined',
}));
Expand Down

0 comments on commit a3cc567

Please sign in to comment.