Skip to content

Commit ba98344

Browse files
arbrandescodex
andcommitted
feat!: restructure tools entry points
Instead of publishing tools separately as /config and /tools/dist, unify the tsc builds so that everything ends up in /dist. BREAKING CHANGE: consuming apps need to modify their imports accordingly. Co-authored-by: ChatGPT 5.2 <noreply@openai.com>
1 parent c8fd074 commit ba98344

14 files changed

Lines changed: 64 additions & 63 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ node_modules
22
npm-debug.log
33
coverage
44
module.config.js
5+
/.tsbuildinfo.*
56
dist/
6-
/config
77
scss
88
docs/api
99

Makefile

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,13 @@ transifex_temp = ./temp/babel-plugin-formatjs
1010
doc_command = ./node_modules/.bin/documentation build src -g -c ./docs/documentation.config.yml -f md -o ./docs/_API-body.md --sort-order alpha
1111
cat_docs_command = cat ./docs/_API-header.md ./docs/_API-body.md > ./docs/API.md
1212

13-
build:
14-
rm -rf ./config ./tools/dist ./dist
13+
clean:
14+
rm -rf dist .tsbuildinfo.*
15+
16+
build: clean
1517
tsc --project ./tsconfig.json
16-
tsc --project ./tsconfig.build.json
17-
mkdir -p ./dist/shell
18+
tsc --build ./tsconfig.build.json
1819
cp ./shell/app.scss ./dist/shell/app.scss
19-
mkdir -p ./config
20-
cp tools/typescript/tsconfig.json config/tsconfig.json
21-
tsc --project ./tools/tsconfig.json
22-
cp -prf ./tools/dist/config-helpers ./config/config-helpers
23-
cp -prf ./tools/dist/defaultConfigPaths.js ./config/defaultConfigPaths.js
24-
cp -prf ./tools/dist/types.js ./config/types.js
25-
cp -prf ./tools/dist/eslint ./config/eslint
26-
cp -prf ./tools/dist/jest ./config/jest
27-
cp -prf ./tools/dist/webpack ./config/webpack
28-
cp -prf ./tools/dist/babel ./config/babel
29-
cp -prf ./tools/dist/index.js ./config/index.js
3020

3121
docs-build:
3222
${doc_command}

docs/how_tos/migrate-frontend-app.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ With the exception of any custom scripts, replace the `scripts` section of your
128128

129129
```json
130130
"scripts": {
131-
"build": "tsc --project tsconfig.build.json && tsc-alias -p tsconfig.build.json",
131+
"build": "make build",
132132
"dev": "PORT=YOUR_PORT PUBLIC_PATH=/YOUR_APP_NAME openedx dev",
133133
"i18n_extract": "openedx formatjs extract",
134134
"lint": "openedx lint .",
@@ -138,12 +138,25 @@ With the exception of any custom scripts, replace the `scripts` section of your
138138
},
139139
```
140140

141-
The `build` script compiles TypeScript to JavaScript and uses `tsc-alias` to rewrite `@src` path aliases to relative paths. You'll need to install `tsc-alias` as a dev dependency:
141+
The `build` script invokes a Makefile target. You'll need to install `tsc-alias` as a dev dependency:
142142

143143
```sh
144144
npm install --save-dev tsc-alias
145145
```
146146

147+
Then add a `build:` target to your `Makefile`:
148+
149+
```makefile
150+
build:
151+
tsc --project tsconfig.build.json
152+
tsc-alias -p tsconfig.build.json
153+
find src -name '*.scss' -exec cp --parents {} dist/ \;
154+
mv dist/src/* dist/
155+
rmdir dist/src
156+
```
157+
158+
This target compiles TypeScript to JavaScript, uses `tsc-alias` to rewrite `@src` path aliases to relative paths, and copies all SCSS files from `src/` into `dist/` preserving directory structure.
159+
147160
- Replace `YOUR_PORT` with the desired port, of course.
148161
- Replace `YOUR_APP_NAME` with the basename used on your site.config, not doing this will result in only the root route working.
149162
- Note that `fedx-scripts` no longer exists, and has been replaced with `openedx`.
@@ -185,8 +198,8 @@ This means that the code from the library can be safely tree-shaken by webpack.
185198

186199
```json
187200
"sideEffects": [
188-
"*.css",
189-
"*.scss"
201+
"dist/**/*.css",
202+
"dist/**/*.scss"
190203
],
191204
```
192205

@@ -206,7 +219,7 @@ Finally, make sure the following fields are set properly:
206219
Clean up .npmignore
207220
===================
208221

209-
Since we use the `files` field in `package.json` to whitelist only `/dist`, the `.npmignore` file is largely unnecessary. You can delete it or keep a minimal version:
222+
Since we use the `files` field in `package.json` to whitelist only `/dist`, the `.npmignore` file is largely unnecessary. You can keep a minimal version:
210223

211224
```
212225
node_modules
@@ -262,7 +275,7 @@ Create a `tsconfig.json` file and add the following contents to it:
262275

263276
```json
264277
{
265-
"extends": "@openedx/frontend-base/config/tsconfig.json",
278+
"extends": "@openedx/frontend-base/dist/tools/typescript/tsconfig.json",
266279
"compilerOptions": {
267280
"baseUrl": ".",
268281
"rootDir": ".",
@@ -311,8 +324,6 @@ Create a `tsconfig.build.json` file for compiling your app before publishing:
311324
"rootDir": "src",
312325
"outDir": "dist",
313326
"noEmit": false,
314-
"declaration": true,
315-
"declarationMap": false,
316327
"sourceMap": false
317328
},
318329
"include": [
@@ -343,7 +354,7 @@ Replace the import from 'frontend-build' with 'frontend-base'.
343354

344355
```diff
345356
- const { createConfig } = require('@openedx/frontend-build');
346-
+ const { createConfig } = require('@openedx/frontend-base/config');
357+
+ const { createConfig } = require('@openedx/frontend-base/dist/tools');
347358
```
348359

349360
Use 'test' instead of 'jest' as the config type for createConfig()
@@ -387,7 +398,7 @@ Resulting jest.config.js file
387398
An uncustomized jest.config.js looks like:
388399

389400
```js
390-
const { createConfig } = require('@openedx/frontend-base/config');
401+
const { createConfig } = require('@openedx/frontend-base/dist/tools');
391402

392403
module.exports = createConfig('test', {
393404
// setupFilesAfterEnv is used after the jest environment has been loaded. In general this is what you want.
@@ -414,7 +425,7 @@ Add a babel.config.js file for Jest
414425
Jest needs a babel.config.js file to be present in the repository. It should look like:
415426

416427
```js
417-
const { createConfig } = require('@openedx/frontend-base/config');
428+
const { createConfig } = require('@openedx/frontend-base/dist/tools');
418429

419430
module.exports = createConfig('babel');
420431
```
@@ -441,7 +452,7 @@ ESLint has been upgraded to v9, which has a new 'flat' file format. Replace the
441452
```js
442453
// @ts-check
443454

444-
const { createLintConfig } = require('@openedx/frontend-base/config');
455+
const { createLintConfig } = require('@openedx/frontend-base/dist/tools');
445456

446457
module.exports = createLintConfig(
447458
{
@@ -554,14 +565,14 @@ SVGR "ReactComponent" imports have been removed
554565
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`.
555566

556567

557-
Import createConfig and getBaseConfig from @openedx/frontend-base/config
568+
Import createConfig and getBaseConfig from @openedx/frontend-base/dist/tools
558569
========================================================================
559570

560571
In frontend-build, `createConfig` and `getBaseConfig` could be imported from the root package (`@openedx/frontend-build`). They have been moved to a sub-directory to make room for runtime exports from the root package (`@openedx/frontend-base`).
561572

562573
```diff
563574
- const { createConfig, getBaseConfig } = require('@openedx/frontend-build');
564-
+ const { createConfig, getBaseConfig } = require('@openedx/frontend-base/config');
575+
+ const { createConfig, getBaseConfig } = require('@openedx/frontend-base/dist/tools');
565576
```
566577

567578
You may have handled this in steps 4 and 5 above (jest.config.js and .eslintrc.js)

nodemon.pack.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"watch": ["runtime", "shell", "tools", "index.ts", "types.ts"],
33
"ext": "ts,tsx,js,jsx,json,scss,css",
4-
"ignore": ["node_modules/**", ".git/**", "pack/**", "config/**", "tools/dist/**"],
4+
"ignore": ["node_modules/**", ".git/**", "pack/**"],
55
"delay": "250ms",
66
"exec": "npm run build:pack"
77
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"files": [
11-
"/config",
12-
"/dist",
13-
"/tools/dist"
11+
"/dist"
1412
],
1513
"bin": {
16-
"intl-imports.js": "tools/dist/cli/intl-imports.js",
17-
"openedx": "tools/dist/cli/openedx.js",
18-
"transifex-utils.js": "tools/dist/cli/transifex-utils.js"
14+
"intl-imports.js": "dist/tools/cli/intl-imports.js",
15+
"openedx": "dist/tools/cli/openedx.js",
16+
"transifex-utils.js": "dist/tools/cli/transifex-utils.js"
1917
},
2018
"scripts": {
2119
"build": "make build",
22-
"clean": "rm -rf dist",
23-
"dev": "npm run build && node ./tools/dist/cli/openedx.js dev:shell",
20+
"clean": "make clean",
21+
"dev": "npm run build && node ./dist/tools/cli/openedx.js dev:shell",
2422
"docs": "jsdoc -c jsdoc.json",
2523
"docs:watch": "nodemon -w runtime -w docs/template -w README.md -e js,jsx,ts,tsx --exec npm run docs",
2624
"lint": "eslint .; npm run lint:tools; npm --prefix ./test-site run lint",
@@ -41,8 +39,8 @@
4139
"url": "https://github.com/openedx/frontend-base/issues"
4240
},
4341
"sideEffects": [
44-
"*.css",
45-
"*.scss"
42+
"dist/**/*.css",
43+
"dist/**/*.scss"
4644
],
4745
"homepage": "https://github.com/openedx/frontend-base#readme",
4846
"dependencies": {

test-site/eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
const { createLintConfig } = require('@openedx/frontend-base/config');
3+
const { createLintConfig } = require('@openedx/frontend-base/dist/tools');
44

55
module.exports = createLintConfig(
66
{

test-site/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-site/src/site.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@use '@openedx/frontend-base/shell/app.scss';
1+
@use '@openedx/frontend-base/dist/shell/app.scss';
22

33
.red-text {
44
color: var(--pgn-color-red);

test-site/tsconfig.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
2-
"extends": "@openedx/frontend-base/config/tsconfig.json",
2+
"extends": "@openedx/frontend-base/dist/tools/typescript/tsconfig.json",
33
"compilerOptions": {
44
"baseUrl": ".",
55
"rootDir": ".",
6-
"outDir": "dist",
7-
"paths": {
8-
"@src/*": ["./src/*"]
9-
}
6+
"outDir": "dist"
107
},
118
"include": [
129
"eslint.config.js",

0 commit comments

Comments
 (0)