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

feat: set up dashboard to deploy js configs #304

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
.eslintcache
env.config.js
env.config.*
node_modules
npm-debug.log
coverage
Expand Down
171 changes: 170 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"jest-when": "^3.6.0",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"patch-package": "^8.0.0",
"prop-types": "15.7.2",
"query-string": "7.0.1",
"react": "^17.0.2",
Expand Down
58 changes: 58 additions & 0 deletions patches/@openedx+frontend-build+13.0.28.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
diff --git a/node_modules/@openedx/frontend-build/config/jest.config.js b/node_modules/@openedx/frontend-build/config/jest.config.js
index ac5f730..ddce396 100644
--- a/node_modules/@openedx/frontend-build/config/jest.config.js
+++ b/node_modules/@openedx/frontend-build/config/jest.config.js
@@ -3,11 +3,16 @@ const fs = require('fs');

const presets = require('../lib/presets');

+// This assigns the envConfigPath filepath based on whether env.config exists, otherwise it uses the fallback filepath.
+
let envConfigPath = path.resolve(__dirname, './jest/fallback.env.config.js');
-const appEnvConfigPath = path.resolve(process.cwd(), './env.config.js');
+const appEnvConfigPathJs = path.resolve(process.cwd(), './env.config.js');
+const appEnvConfigPathJsx = path.resolve(process.cwd(), './env.config.jsx');

-if (fs.existsSync(appEnvConfigPath)) {
- envConfigPath = appEnvConfigPath;
+if (fs.existsSync(appEnvConfigPathJs)) {
+ envConfigPath = appEnvConfigPathJs;
+} else if (fs.existsSync(appEnvConfigPathJsx)) {
+ envConfigPath = appEnvConfigPathJsx;
}

module.exports = {
diff --git a/node_modules/@openedx/frontend-build/config/webpack.prod.config.js b/node_modules/@openedx/frontend-build/config/webpack.prod.config.js
index 2879dd9..dd819bc 100644
--- a/node_modules/@openedx/frontend-build/config/webpack.prod.config.js
+++ b/node_modules/@openedx/frontend-build/config/webpack.prod.config.js
@@ -11,6 +11,7 @@ const dotenv = require('dotenv');
const NewRelicSourceMapPlugin = require('@edx/new-relic-source-map-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
+const fs = require('fs');
const path = require('path');
const PostCssAutoprefixerPlugin = require('autoprefixer');
const PostCssRTLCSS = require('postcss-rtlcss');
@@ -23,6 +24,21 @@ 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 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;
+
+if (envConfigPath) {
+ const envConfigFilename = envConfigPath.slice(envConfigPath.indexOf('env.config'));
+ fs.copyFileSync(envConfigPath, envConfigFilename);
+}
+
// Add process env vars. Currently used only for setting the PUBLIC_PATH.
dotenv.config({
path: path.resolve(process.cwd(), '.env'),
6 changes: 6 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { mergeConfig } from '@edx/frontend-platform';
import envConfig from 'env.config';

const configuration = {
// BASE_URL: process.env.BASE_URL,
LMS_BASE_URL: process.env.LMS_BASE_URL,
Expand All @@ -20,6 +23,9 @@ const configuration = {
ENABLE_EDX_PERSONAL_DASHBOARD: process.env.ENABLE_EDX_PERSONAL_DASHBOARD === 'true',
};

// This mergeConfig ensures that any variables assigned by process.env are still overwritten if declared in JS config
mergeConfig(envConfig);

Copy link
Member

Choose a reason for hiding this comment

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

Does this not already happen in frontend-platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it does, and I realize now that I added this additional mergeConfig because at one point I was trying to handle the scenario where the .env.* files would be removed, but I now know that that isn't something I should have to anticipate while adding the risk of variables over-writing each other repeatedly. Removing this logic for now.

const features = {};

export { configuration, features };
17 changes: 0 additions & 17 deletions src/setupTest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,6 @@ jest.mock('@edx/frontend-platform/i18n', () => {
};
});

/*
When .env.test is removed, uncomment the env vars below and add any environment variables for testing with Jest
Context: Snapshot is not currently set up to be able to parse the environment variables in env.config.js
*/

// jest.mock('@edx/frontend-platform', () => ({
// getConfig: jest.fn(() => ({
// LMS_BASE_URL: 'http://localhost:18000',
// LOGOUT_URL: 'http://localhost:18000/logout',
// LOGO_URL: 'https://edx-cdn.org/v3/default/logo.svg',
// MARKETING_SITE_BASE_URL: 'http://localhost:18000',
// SUPPORT_URL: 'http://localhost:18000/support',
// OPTIMIZELY_FULL_STACK_SDK_KEY: 'SDK Key',
// })),
// }));

jest.mock('@openedx/paragon', () => jest.requireActual('testUtils').mockNestedComponents({
Alert: {
Heading: 'Alert.Heading',
Expand Down
Loading