Skip to content

Commit 7bf9999

Browse files
committed
refactor: configuration types and file names
There is no need for a distinct ProjectSiteConfig; it is actually less confusing to accept that some config properties are indeed optional, and write code accordingly. The concept of "Project" is also a bit confusing, since the configuration is typed as "SiteConfig". So we're abandoning "Project" in favor of "Site". This renames everything accordingly. Continuing, rename SiteConfig's top-level `appId` to a more fitting `siteId`, leaving `appId` exclusively for the `App` type. In yet another rename, move the `custom` app config to what it's actually for: `standalone` mode. (Plus, "dev.legacy" is better described as "dev.standalone".) Also move test.site.config.tsx into the normal site.config.*.tsx pattern. There is no longer any reason for the distinction, as all site.config files are ok to be committed. Finally, adjust other webpack and site.config file names to a more conformant pattern.
1 parent 026d1a3 commit 7bf9999

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+204
-189
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ jobs:
3333
run: npm run lint
3434
- name: Test
3535
run: npm run test
36-
- name: Test Project
37-
run: npm run test-project
36+
- name: Build Test Site
37+
run: npm run test-site:build

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ scss
99
node_modules
1010
npm-debug.log
1111
docs/api
12-
/openedx-frontend-base-1.0.0.tgz
12+
/*.tgz

docs/decisions/0008-stylesheet-import-in-site-config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ As a best practice, a project should have a top-level SCSS file as a peer to the
1818

1919
## Implementation
2020

21-
The `project.scss` file should import the stylesheet from the shell:
21+
The `site.scss` file should import the stylesheet from the shell:
2222

2323
```diff
2424
+ @import '@openedx/frontend-base/shell/app.scss';
@@ -29,7 +29,7 @@ The `project.scss` file should import the stylesheet from the shell:
2929
The site.config file should then import the top-level SCSS file:
3030

3131
```diff
32-
+ import './project.scss';
32+
+ import './site.scss';
3333

3434
const config = {
3535
// config document

docs/decisions/0009-slot-naming-and-lifecycle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Where:
106106

107107
For example:
108108

109-
* org.openedx.frontend.slot.devProject.foobar (unsupported slot, as version is empty)
109+
* org.openedx.frontend.slot.devSite.foobar (unsupported slot, as version is empty)
110110
* org.openedx.frontend.slot.footer.main.unstable (unstable slot)
111111
* org.openedx.frontend.slot.learning.navigationSidebar.v2 (this slot is on version 2)
112112

docs/how_tos/migrate-frontend-app.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ With the exception of any custom scripts, replace the `scripts` section of your
128128
```
129129
"scripts": {
130130
"build": "PORT=YOUR_PORT openedx build",
131-
"build:legacy": "openedx build:legacy", // TODO: Does this target exist?
131+
"build:standalone": "openedx build:standalone",
132132
"dev": "PORT=YOUR_PORT openedx dev",
133-
"dev:legacy": "PORT=YOUR_PORT openedx dev:legacy",
133+
"dev:standalone": "PORT=YOUR_PORT openedx dev:standalone",
134134
"i18n_extract": "openedx formatjs extract",
135135
"lint": "openedx lint .",
136136
"lint:fix": "openedx lint --fix .",
@@ -182,7 +182,7 @@ Create an `app.d.ts` file in the root of your MFE with the following contents:
182182
/// <reference types="@openedx/frontend-base" />
183183

184184
declare module 'site.config' {
185-
export default ProjectSiteConfig;
185+
export default SiteConfig;
186186
}
187187

188188
declare module '*.svg' {
@@ -210,7 +210,6 @@ Create a `tsconfig.json` file and add the following contents to it:
210210
"babel.config.js",
211211
"eslint.config.js",
212212
"jest.config.js",
213-
"test.site.config.tsx",
214213
"site.config.*.tsx",
215214
],
216215
}
@@ -388,7 +387,7 @@ Description fields are now required on all i18n messages in the repository. Thi
388387
SVGR "ReactComponent" imports have been removed
389388
===============================================
390389

391-
We have removed the `@svgr/webpack` loader because it was incompatible with more modern tooling (it requires Babel). As a result, the ability to import SVG files into JS as the `ReactComponent` export no longer works. We know of a total of 5 places where this is happening today in Open edX MFEs - frontend-app-learning and frontend-app-profile use it. Please replace that export with the default URL export and set the URL as the source of an `<img>` tag, rather than using `ReactComponent`. You can see an example of normal SVG imports in `test-project/src/ExamplePage.tsx`.
390+
We have removed the `@svgr/webpack` loader because it was incompatible with more modern tooling (it requires Babel). As a result, the ability to import SVG files into JS as the `ReactComponent` export no longer works. We know of a total of 5 places where this is happening today in Open edX MFEs - frontend-app-learning and frontend-app-profile use it. Please replace that export with the default URL export and set the URL as the source of an `<img>` tag, rather than using `ReactComponent`. You can see an example of normal SVG imports in `test-site/src/ExamplePage.tsx`.
392391

393392

394393
Import createConfig and getBaseConfig from @openedx/frontend-base/config
@@ -490,7 +489,7 @@ Required config
490489

491490
The required configuration at the time of this writing is:
492491

493-
- appId: string
492+
- siteId: string
494493
- siteName: string
495494
- baseUrl: string
496495
- lmsBaseUrl: string
@@ -538,13 +537,13 @@ const examplePageUrl = getUrlForRouteRole('example');
538537
App-specific config values
539538
--------------------------
540539

541-
App-specific configuration can be expressed by adding a `custom` section to SiteConfig which allows arbitrary config variables.
540+
App-specific configuration can be expressed by adding a `standalone` section to SiteConfig which allows arbitrary config variables.
542541

543542
```
544-
const config: ProjectSiteConfig = {
543+
const config: SiteConfig = {
545544
// ... Other config
546545
547-
custom: {
546+
standalone: {
548547
appId: 'myapp',
549548
myCustomVariableName: 'my custom variable value',
550549
}
@@ -557,30 +556,28 @@ These variables can be used in code with the `getAppConfig` function:
557556
getAppConfig('myapp').myCustomVariableName
558557
```
559558

560-
If you have fully converted your app over to the new module architecture, you can add custom variables to the `config` object in your `App` definition and they will be available via `getAppConfig`.
559+
If you have fully converted your app over to the new architecture, you can add custom variables to the `config` object in your `App` definition and they will be available via `getAppConfig`.
561560

562561

563-
Replace the .env.test file with configuration in test.site.config.tsx file
562+
Replace the .env.test file with configuration in site.config.test.tsx file
564563
==========================================================================
565564

566-
We're moving away from .env files because they're not expressive enough (only string types!) to configure an Open edX frontend. Instead, the test suite has been configured to expect a `test.site.config.tsx` file. If you're initializing an application in your tests, `frontend-base` will pick up this configuration and make it available to `getConfig()`, etc. If you need to manually access the variables, you can import `site.config` in your test files:
567-
568-
Note that test.site.config.tsx has a different naming scheme than `site.config.*.tsx` because it's intended to be checked in, and `site.config.*.tsx` is git-ignored.
565+
We're moving away from .env files because they're not expressive enough (only string types!) to configure an Open edX frontend. Instead, the test suite has been configured to expect a `site.config.test.tsx` file. If you're initializing an application in your tests, `frontend-base` will pick up this configuration and make it available to `getConfig()`, etc. If you need to manually access the variables, you can import `site.config` in your test files:
569566

570567
```diff
571568
+ import config from 'site.config';
572569
```
573570

574-
The Jest configuration has been set up to find `site.config` in a `test.site.config.tsx` file.
571+
The Jest configuration has been set up to find `site.config` in a `site.config.test.tsx` file.
575572

576573
Once you've verified your test suite still works, you should delete the `.env.test` file.
577574

578-
A sample `test.site.config.tsx` file:
575+
A sample `site.config.test.tsx` file:
579576

580577
```
581-
import { ProjectSiteConfig } from '@openedx/frontend-base';
578+
import { SiteConfig } from '@openedx/frontend-base';
582579
583-
const config: ProjectSiteConfig = {
580+
const config: SiteConfig = {
584581
apps: [],
585582
accessTokenCookieName: 'edx-jwt-cookie-header-payload',
586583
baseUrl: 'http://localhost:8080',
@@ -591,9 +588,9 @@ const config: ProjectSiteConfig = {
591588
logoutUrl: 'http://localhost:18000/logout',
592589
refreshAccessTokenApiPath: '/login_refresh',
593590
segmentKey: '',
591+
siteId: 'test',
594592
siteName: 'localhost',
595593
userInfoCookieName: 'edx-user-info',
596-
appId: 'authn',
597594
environment: 'dev',
598595
ignoredErrorRegex: null,
599596
publicPath: '/',
@@ -629,12 +626,12 @@ Remove core-js and regenerator-runtime
629626
We don't need these libraries anymore, remove them from the package.json dependencies and remove any imports of them in the code.
630627

631628

632-
Create a project.scss file
633-
==========================
629+
Create a site.scss file
630+
=======================
634631

635632
This is required if you intend to run builds from the app itself.
636633

637-
Create a new `project.scss` file at the top of your application. It's responsible for:
634+
Create a new `site.scss` file at the top of your application. It's responsible for:
638635

639636
1. Importing the shell's stylesheet, which includes Paragon's core stylesheet.
640637
2. Importing your brand stylesheet.
@@ -643,16 +640,16 @@ Create a new `project.scss` file at the top of your application. It's responsib
643640
You must then import this new stylesheet into your `site.config` file:
644641

645642
```diff
646-
+ import './project.scss';
643+
+ import './site.scss';
647644

648-
const config: ProjectSiteConfig = {
645+
const config: SiteConfig = {
649646
// config document
650647
}
651648

652649
export default config;
653650
```
654651

655-
This file will be ignored via `.gitignore`, as it is part of your 'project', not the module library.
652+
This file will be ignored via `.gitignore`, as it is part of your 'site', not the module library.
656653

657654

658655
Document module-specific configuration needs
@@ -731,7 +728,7 @@ Refactor plugin-slots
731728

732729
First, rename `src/plugin-slots`, if it exists, to `src/slots`. Modify imports and documentation across the codebase accordingly.
733730

734-
Next, the frontend-base equivalent to `<PluginSlot />` is `<Slot />`, and has a different API. This includes a change in the slot ID, according to the [new slot naming ADR](../decisions/0009-slot-naming-and-lifecycle.rst) in this repository. Rename them accordingly. You can refer to the `src/shell/dev-project` in this repository for examples.
731+
Next, the frontend-base equivalent to `<PluginSlot />` is `<Slot />`, and has a different API. This includes a change in the slot ID, according to the [new slot naming ADR](../decisions/0009-slot-naming-and-lifecycle.rst) in this repository. Rename them accordingly. You can refer to the `src/shell/dev-site` in this repository for examples.
735732

736733

737734
Find your module boundaries

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = tseslint.config(
1010
{
1111
ignores: [
1212
'tools/*',
13-
'test-project/*',
13+
'test-site/*',
1414
'config/*',
1515
'docs/*',
1616
],

frontend-base.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
declare module 'site.config' {
2-
export default ProjectSiteConfig;
2+
export default SiteConfig;
33
}
44

55
declare module '*.svg' {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"dev:shell": "npm run build && node ./tools/dist/cli/openedx.js dev:shell",
1818
"docs": "jsdoc -c jsdoc.json",
1919
"docs:watch": "nodemon -w runtime -w docs/template -w README.md -e js,jsx,ts,tsx --exec npm run docs",
20-
"lint": "eslint .; npm run lint:tools; npm --prefix ./test-project run lint",
20+
"lint": "eslint .; npm run lint:tools; npm --prefix ./test-site run lint",
2121
"lint:tools": "cd ./tools && eslint . && cd ..",
2222
"test": "jest",
23-
"test-project": "npm --prefix ./test-project i; npm --prefix ./test-project run build",
24-
"test-project:refresh": "npm run build && npm pack && cd test-project && npm i --audit=false --fund=false ../openedx-frontend-base-1.0.0.tgz && cd ../"
23+
"test-site:build": "npm --prefix ./test-site i; npm --prefix ./test-site run build",
24+
"test-site:refresh": "npm run build && npm pack && cd test-site && npm i --audit=false --fund=false ../openedx-frontend-base-1.0.0.tgz && cd ../"
2525
},
2626
"repository": {
2727
"type": "git",

runtime/config/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let config: SiteConfig = {
128128
externalRoutes: [],
129129
externalLinkUrlOverrides: [],
130130

131-
appId: '',
131+
siteId: '',
132132
baseUrl: '',
133133
siteName: '',
134134

@@ -139,7 +139,7 @@ let config: SiteConfig = {
139139
// Backends
140140
lmsBaseUrl: '',
141141

142-
custom: {
142+
standalone: {
143143
appId: '',
144144
},
145145
};
@@ -200,7 +200,7 @@ export function setConfig(newConfig: SiteConfig) {
200200
*
201201
* @param {Object} newConfig
202202
*/
203-
export function mergeConfig(newConfig: Partial<Partial<OptionalSiteConfig> & RequiredSiteConfig>) {
203+
export function mergeConfig(newConfig: Partial<SiteConfig>) {
204204
config = merge(config, newConfig);
205205
publish(CONFIG_CHANGED);
206206
}
@@ -214,6 +214,8 @@ const appConfigs: Record<string, AppConfig> = {};
214214
*/
215215
export function addAppConfigs() {
216216
const { apps } = getConfig();
217+
if (!apps) return;
218+
217219
for (const app of apps) {
218220
if (app.config !== undefined) {
219221
patchAppConfig(app.config);

runtime/i18n/lib.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,14 @@ export function getLocale(locale?: string) {
143143
}
144144
// 2. User setting in cookie
145145

146-
const cookieLangPref = cookies.get(getConfig().languagePreferenceCookieName);
147-
if (cookieLangPref) {
148-
return findSupportedLocale(cookieLangPref.toLowerCase());
146+
const { languagePreferenceCookieName } = getConfig();
147+
if (languagePreferenceCookieName) {
148+
const languagePreference = cookies.get(languagePreferenceCookieName);
149+
if (languagePreference) {
150+
return findSupportedLocale(languagePreference.toLowerCase());
151+
}
149152
}
153+
150154
// 3. Browser language (default)
151155
// Note that some browers prefer upper case for the region part of the locale, while others don't.
152156
// Thus the toLowerCase, for consistency.
@@ -240,9 +244,11 @@ export function mergeMessages(newMessages = {}) {
240244
*/
241245
export function addAppMessages() {
242246
const { apps } = getConfig();
243-
apps.forEach((app) => {
244-
mergeMessages(app.messages);
245-
});
247+
if (apps) {
248+
apps.forEach((app) => {
249+
mergeMessages(app.messages);
250+
});
251+
}
246252
}
247253

248254
interface ConfigureI18nOptions {

0 commit comments

Comments
 (0)