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

Migrate from CRA to Vite #1379 #1380

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9fe7b76
Initial migration to use vite and get dev working #346
joelvdavies Mar 12, 2024
8636baf
Update tsconfig and fix issues preventing build #1379
joelvdavies Mar 12, 2024
54aea49
Enable pre-commit linting again #1379
joelvdavies Mar 12, 2024
c0f3258
Add vitest and make some tests function #1379
joelvdavies Mar 13, 2024
9561d42
Fix global mocking behavour and vscode linting in tests and replace s…
joelvdavies Mar 13, 2024
cd8d1bd
Fix more unit tests #371
joelvdavies Mar 13, 2024
4b48f5e
Fix flushPromises in unit tests #371
joelvdavies Mar 13, 2024
07b9472
Fix some more unit tests using timers #1379
joelvdavies Mar 14, 2024
7d1f68d
Fix two more unit tests #1379
joelvdavies Mar 14, 2024
8608169
Fix remaining broken unit test #1379
joelvdavies Mar 15, 2024
ec83e56
Make cypress run again and exclude some files from coverage #1379
joelvdavies Mar 15, 2024
7cebf93
Fix docker build and replace REACT_APP with VITE_APP #1379
joelvdavies Mar 15, 2024
a0275df
Update readme with new commands and slight cleanup #1379
joelvdavies Mar 15, 2024
5fa11dd
Replace eslint-config-react-app #1379
joelvdavies Mar 15, 2024
1c5ef55
Cleanup vite config and package.json #1379
joelvdavies Mar 18, 2024
38139cc
Move flushPromises into testUtils file to avoid repeated mocks during…
joelvdavies Mar 19, 2024
4da835b
Cleanup eslint config #1379
joelvdavies Mar 19, 2024
bf9dce6
Remove react-app-polyfill and custom-event-polyfill #1379
joelvdavies Mar 19, 2024
505728c
Update and use browserslist #1379
joelvdavies Mar 21, 2024
374532a
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Mar 22, 2024
a91c2d0
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Mar 22, 2024
fec13e4
Modify vite config to output an lcov.info for vscode extension #1379
joelvdavies Apr 3, 2024
4d80658
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Apr 3, 2024
4276cfd
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Apr 16, 2024
d881122
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Jun 4, 2024
0b670a8
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Jul 3, 2024
06d1c95
Ignore cypress on coverage #1379
joelvdavies Aug 7, 2024
384f97b
Apply changes from OG vite and update vite and vitest #1379
joelvdavies Aug 16, 2024
5923c81
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Sep 17, 2024
4e7d733
Merge branch 'react-18-#1205' into migrate-to-vite-#1379
joelvdavies Nov 21, 2024
7713795
Merge branch 'develop' into migrate-to-vite-#1379
joelvdavies Nov 27, 2024
09cb6b7
Upgrade some packages to align with IMS #1379
joelvdavies Nov 27, 2024
26fab0f
Address review comments #1379
joelvdavies Dec 2, 2024
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
69 changes: 38 additions & 31 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
env: {
browser: true,
jest: true,
es6: true,
node: true,
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
plugins: [
'react',
'react-hooks',
'@typescript-eslint',
'cypress',
'prettier',
],
extends: [
'react-app',
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'prettier',
'plugin:cypress/recommended',
'prettier',
],
plugins: ['prettier', 'cypress'],
rules: {
'react/jsx-filename-extension': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'react/react-in-jsx-scope': 'off',
'prettier/prettier': [
'error',
{
Expand All @@ -26,34 +42,25 @@ module.exports = {
endOfLine: 'auto',
},
],
// disable for all files - this means we can have plain JS files not causing errors
'@typescript-eslint/explicit-function-return-type': 'off',
// Emulate typescript style for unused variables, see
// https://typescript-eslint.io/rules/no-unused-vars/
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
overrides: [
{
// and enable again specifically for TS files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
},
],
},
files: ['**/?*test.*'],
extends: ['plugin:testing-library/react'],
},
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
allowImportExportEverywhere: true,
sourceType: 'module',
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
};
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
sudo apt-get install libgconf-2-4
yarn --immutable
- name: Run linting
run: yarn lint:js
run: yarn lint
- name: Run unit tests
run: yarn test
- name: Upload unit test coverage
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/coverage

# production
/build
dist

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FROM httpd:2.4.62-alpine3.20@sha256:66c49302c02430619abb84240a438bcfc08301566100
WORKDIR /usr/local/apache2/htdocs

# Put the output of the build into an apache server
COPY --from=builder /scigateway-build/build/. .
COPY --from=builder /scigateway-build/dist/. .

RUN set -eux; \
\
Expand Down
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,38 @@ The SciGateway application offers features such as authentication and authorisat

## Code details

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This project uses [Vite](https://vitejs.dev/).

#### Available Scripts

In the project directory, you can run:

#### `yarn start`
### `yarn dev`

Runs the app in the development mode.<br>
Runs the `dev` script, which runs the app in development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.
### `yarn test`

#### `yarn test`
Runs unit tests

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `yarn e2e`

#### `yarn build`
Runs e2e tests

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.
### `yarn lint`

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

#### `yarn eject`
Lints all code under /src

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
### `yarn build`

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Builds the app for production to the `dist` folder.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

### Learn More
See the section about [building for production](https://vitejs.dev/guide/build.html) for more information.

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
### `yarn preview`

To learn React, check out the [React documentation](https://reactjs.org/).
Deploys a static version of the build from the `dist` directory to port 5001. Use `yarn preview:build` to build and preview it in SciGateway.
21 changes: 21 additions & 0 deletions __mocks__/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const requests = {
get: vi.fn((path) => {
if (path === '/settings.json') {
return Promise.resolve({
data: {
'auth-provider': 'jwt',
'ui-strings': '/res/default.json',
plugins: [],
'help-tour-steps': [],
},
});
} else {
return Promise.resolve({
data: {},
});
}
}),
post: vi.fn(() => Promise.resolve({ data: {} })),
};

export default requests;
File renamed without changes.
9 changes: 2 additions & 7 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from 'cypress'
import { defineConfig } from 'cypress';

export default defineConfig({
chromeWebSecurity: false,
Expand All @@ -8,11 +8,6 @@ export default defineConfig({
openMode: 0,
},
e2e: {
setupNodeEvents(on, config) {
on('task', {
failed: require('cypress-failed-log/src/failed')(),
})
},
baseUrl: 'http://127.0.0.1:3000',
},
})
});
2 changes: 0 additions & 2 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')

require('cypress-failed-log');
35 changes: 35 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico?v=2" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="/manifest.json" />
<title>SciGateway</title>
</head>

<body>
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script>
window.React ||
document.write('<script src="/react.production.min.js">\x3C/script>');
</script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
<script>
window.ReactDOM ||
document.write(
'<script src="/react-dom.production.min.js">\x3C/script>'
);
</script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="scigateway"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
13 changes: 9 additions & 4 deletions micro-frontend-tools/serve-plugins.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
var fs = require('fs');
const path = require('path');
var exec = require('child_process').exec;
import fs from 'fs';
import path from 'path';
import child_process from 'child_process';

const settingsFilePath = path.join(__dirname, '/dev-plugin-settings.json');
var exec = child_process.exec;

const settingsFilePath = path.join(
import.meta.dirname,
'/dev-plugin-settings.json'
);

function checkForSettingsFile() {
if (!fs.existsSync(settingsFilePath)) {
Expand Down
Loading