Skip to content

Commit

Permalink
fix: properly exporting type definitions
Browse files Browse the repository at this point in the history
These type definitions are used by consuming apps.  In particular, this includes a type definition for an SVG file so consuming app test suites can understand their own SVG files.

This commit also updates the README to record additional migration steps.
  • Loading branch information
davidjoy committed Jul 5, 2024
1 parent 982335d commit af5eed3
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 28 deletions.
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@ This will let your MFE use the checked out version of `frontend-base`.

Run `npm install` again to update your `node_modules` and `package-lock.json`.

### 4. Edit package.json `scripts`
### 4. Migrate your MFE

Follow the steps below to migrate an MFE to use frontend-base.

## Migrating to frontend-base

### 1. Edit package.json `scripts`

Replace all instances of `fedx-scripts` with `openedx` in your package.json file.

> [!TIP]
> **Why change `fedx-scripts` to `openedx`?**
> A few reasons. One, the Open edX project shouldn't be using the name of an internal community of practice at edX for its frontend tooling. Two, some dependencies of your MFE invariably still use frontend-build for their own build needs. This means that they already installed `fedx-scripts` into your `node_modules/.bin` folder. Only one version can be in there, so we need a new name. Seemed like a great time for a naming refresh. |
### 5. Add a tsconfig.json file
### 2. Add a tsconfig.json file

Create a tsconfig.json file and add the following contents to it:

Expand All @@ -79,38 +85,42 @@ Create a tsconfig.json file and add the following contents to it:
"outDir": "dist"
},
"include": [
"src"
".eslintrc.js",
"jest.config.js",
"env.config.js",
"src",
"app.d.ts",
]
}
```

This assumes you have a `src` folder and your build goes in `dist`, which is the best practice.

### 6. Edit `jest.config.js`
### 3. Add a Type Declaration file (app.d.ts)

Replace the import from 'frontend-build' with 'frontend-base'.

### 7. Edit `.eslintrc.js`
Add a file named `app.d.ts` to the root of your MFE. It should contain:

Replace the import from 'frontend-build' with 'frontend-base'.
```
/// <reference types="@openedx/frontend-base" />
```

### 8. Search for any other usages of `frontend-build`
### 4. Edit `jest.config.js`

Find any other imports/usages of `frontend-build` in your repository and replace them with `frontend-base` so they don't break.
Replace the import from 'frontend-build' with 'frontend-base'.

## Migrating to frontend-base
### 5. Edit `.eslintrc.js`

Currently this section is a quick of notes documenting required changes to MFEs. We will turn this into a more rigorous migration guide in the future.
Replace the import from 'frontend-build' with 'frontend-base'.

### Follow "Development" section.
### 6. Search for any other usages of `frontend-build`

First follow the steps above in the "Development" section.
Find any other imports/usages of `frontend-build` in your repository and replace them with `frontend-base` so they don't break.

### i18n Descriptions
### 7. i18n Descriptions

Description fields are now required on all i18n messages in the repository. This is because of a change to the ESLint config.

### Jest Mocks
### 8. Jest Mocks

Jest test suites that test React components that import SVG and files must add mocks for those filetypes. This can be accomplished by adding the following module name mappers to jest.config.js:

Expand Down
2 changes: 2 additions & 0 deletions cli/test-app/package-lock.json

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

4 changes: 0 additions & 4 deletions cli/test-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
"env.config.js",
"src"
],
"exclude": [
"node_modules",
"dist"
]
}
1 change: 0 additions & 1 deletion config/jest/fileMock.js

This file was deleted.

4 changes: 0 additions & 4 deletions config/jest/svgrMock.js

This file was deleted.

14 changes: 14 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference types="node" />
/// <reference types="react" />
/// <reference types="react-dom" />

declare module '*.svg' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<React.SVGProps<
SVGSVGElement
> & { title?: string }>;

const src: string;
export default src;
}
36 changes: 36 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"access": "public"
},
"main": "index.js",
"types": "index.d.ts",
"bin": {
"openedx": "./bin/openedx.js"
},
Expand Down Expand Up @@ -62,7 +63,9 @@
"postcss-custom-media": "10.0.6",
"postcss-loader": "7.3.4",
"postcss-rtlcss": "5.1.2",
"react": "^17.0.2",
"react-dev-utils": "12.0.1",
"react-dom": "^17.0.2",
"react-refresh": "0.14.2",
"resolve-url-loader": "5.0.0",
"sass": "1.69.7",
Expand Down
5 changes: 2 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
"cli",
"config",
"config/.eslintrc.js",
"lib"
"lib",
"index.d.ts"
],
"exclude": [
"node_modules",
"dist",
"cli/test-app"
]
}

0 comments on commit af5eed3

Please sign in to comment.