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

[Tech] Switch from react-scripts to Vite & clean up everything to work with strict mode #1633

Merged
merged 26 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8274b94
Change complete project structure
CommandMC Jul 26, 2022
25775ee
Switch from react-scripts + foreman + webpack + ts-loader -> Vite
CommandMC Jul 26, 2022
763ac97
Set GH_TOKEN and GITHUB_TOKEN in tests directly
CommandMC Jul 26, 2022
1257174
Merge branch 'beta' into feat/vite
CommandMC Jul 26, 2022
bb1f3d9
Merge branch 'beta' into feat/vite
CommandMC Jul 26, 2022
54875e4
Get SVG & JPG importing working in VSCode
CommandMC Jul 28, 2022
24a4ff8
Merge branch 'beta' into feat/vite
CommandMC Jul 28, 2022
22903b1
Move type definitions into common/typedefs
CommandMC Jul 31, 2022
9e2e73f
Fixup tests
CommandMC Jul 31, 2022
2d7f54b
Rewrite large chunks of the backend to be compatible with strict mode
CommandMC Jul 31, 2022
95b574d
Modify frontend to reflect changes to type definition structure
CommandMC Jul 31, 2022
caef5c8
Remove unused files
CommandMC Jul 31, 2022
fe993b4
Merge branch 'beta' into feat/vite
CommandMC Jul 31, 2022
4cc2ee5
Merge branch 'beta' into feat/vite
CommandMC Aug 3, 2022
15ea70c
Update translations
CommandMC Aug 3, 2022
cc85b00
Fixup: Re-add `--filesystem` parameter for Proton
CommandMC Aug 5, 2022
d5202a4
Remove `build` script
CommandMC Aug 8, 2022
9b66e65
Fully remove all remnants of UE support
CommandMC Aug 8, 2022
2ef1c57
Merge branch 'beta' into feat/vite
CommandMC Aug 21, 2022
647a20d
Add new 'codecheck' command
CommandMC Aug 21, 2022
19781eb
Update translation files
CommandMC Aug 21, 2022
67c0de7
Fix translation files
CommandMC Aug 21, 2022
d428185
Remove some more unnecessary files
CommandMC Aug 21, 2022
8754058
Always get game updates from all libraries
CommandMC Aug 22, 2022
d0d3843
Some misc code style changes
CommandMC Aug 22, 2022
0fcb3b7
Merge branch 'beta' into feat/vite
CommandMC Aug 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public/start-react.js
i18next-parser.config.js
flatpak/build/
flatpak/.flatpak-builder/
vite.config.ts
**/__tests__/**
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ecmaVersion": 12,
"sourceType": "module",
"project": ["./tsconfig.json", "./electron/tsconfig.json"]
"project": ["./tsconfig.json"]
},
"plugins": ["react", "@typescript-eslint"],
"settings": {
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-prs-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
run: yarn
- name: Build artifacts.
run: yarn dist appimage --publish=never
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Upload AppImage.
uses: actions/upload-artifact@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-prs-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
run: yarn
- name: Build artifacts.
run: yarn dist-mac --publish=never
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Upload DMG.
uses: actions/upload-artifact@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/build-prs-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ jobs:
- name: Install modules.
run: npm i --legacy-peer-deps
- name: Build artifacts.
run: npm run dist-win portable
run: npm run dist-win portable --publish=never
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Upload EXE.
uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/draft-release-linux-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
- run: npm run release:linux
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/draft-release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
- run: npm run release:linux
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/draft-release-mac-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ jobs:
- run: npm run release:mac
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/draft-release-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
- run: npm run release:mac
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/draft-release-win-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
- run: npm run release:win
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/draft-release-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
- run: npm run release:win
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ downloads*.json

flatpak/build
.flatpak-builder

vite-plugin-electron.log
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ node_modules
dist
build
coverage
public/index.html
public/locales/
flatpak
2 changes: 0 additions & 2 deletions Procfile

This file was deleted.

16 changes: 0 additions & 16 deletions electron/tsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion i18next-parser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
indentation: 4,
// Indentation of the catalog files

input: ['src/**/*.{ts,tsx}', 'electron/**/*.{ts,tsx}'],
input: ['src/**/*.{ts,tsx}'],
// An array of globs that describe where to look for source files
// relative to the location of the configuration file

Expand Down
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Heroic Games Launcher</title>
<script type="module" src="/src/frontend/index.tsx"></script>
</head>
<body>
<div id="root"></div>
<div class="simple-keyboard"></div>
</body>
</html>
10 changes: 8 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {}
},

collectCoverageFrom: ['**/*.{js,jsx,ts,tsx}', '!**/*.config.js'],
coverageDirectory: '<rootDir>/coverage',
coveragePathIgnorePatterns: [
'<rootDir>/node_modules',
'<rootDir>/public',
'<rootDir>/electron',
'<rootDir>/dist',
'<rootDir>/build',
'<rootDir>/coverage'
],
coverageReporters: ['text', 'html'],
projects: ['<rootDir>/electron'],
projects: ['<rootDir>/src/backend'],

rootDir: '.'
}
54 changes: 19 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "heroic",
"version": "2.4.0-beta.2",
"private": true,
"main": "public/main.js",
"main": "build/electron/main.js",
"homepage": "./",
"license": "GPL-3.0-only",
"description": "An Open Source Launcher for GOG and Epic Games",
Expand Down Expand Up @@ -30,9 +30,6 @@
"build/icon-dark.png",
"build/icon-light.png"
],
"directories": {
"buildResources": "public"
},
"protocols": [
{
"name": "heroic",
Expand Down Expand Up @@ -156,7 +153,6 @@
"react-dom": "17",
"react-i18next": "^11.16.7",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"shlex": "^2.1.2",
"simple-keyboard": "^3.4.24",
"source-map-support": "^0.5.21",
Expand All @@ -165,26 +161,19 @@
"tslib": "^2.4.0"
},
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true nf start -p 3000 && electron-start",
"electron-start": "ELECTRON_IS_DEV=1 node public/start-react",
"electron": "yarn build-electron && electron . --trace-warnings",
"react-start": "HOST=localhost BROWSER=none react-scripts start",
"react-start:win": "react-scripts start",
"build": "react-scripts build",
"dev": "vite",
"build": "vite build",
"test": "jest --noStackTrace",
"test-watch": "jest --watch --maxWorkers=25%",
"test:ci": "jest --runInBand --silent",
"eject": "react-scripts eject",
"release:linux": "GH_TOKEN='${{ secrets.WORKFLOW_TOKEN }}' yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js -p always --linux deb AppImage rpm pacman tar.xz",
"release:mac": "GH_TOKEN='${{ secrets.WORKFLOW_TOKEN }}' yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js -p always --mac",
"release:win": "yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js -p always --win nsis portable",
"dist": "GH_TOKEN='${{ secrets.WORKFLOW_TOKEN }}' yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js --linux",
"dist-mac": "GH_TOKEN='${{ secrets.WORKFLOW_TOKEN }}' yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js --mac",
"dist-win": "yarn build-electron && yarn build && electron-builder -c.extraMetadata.main=build/main.js --win",
"lint": "eslint -c .eslintrc --ext .tsx,ts ./src && eslint -c .eslintrc --ext .ts ./electron",
"lint-fix": "eslint --fix -c .eslintrc --ext .tsx,ts ./src && eslint --fix -c .eslintrc --ext .ts ./electron",
"build-electron": "tsc --project electron/tsconfig.json",
"watch-electron": "tsc --watch --project electron/tsconfig.json",
"release:linux": "yarn build && electron-builder -p always --linux deb AppImage rpm pacman tar.xz",
"release:mac": "yarn build && electron-builder -p always --mac",
"release:win": "yarn build && electron-builder -p always --win nsis portable",
"dist": "yarn build && electron-builder --linux",
"dist-mac": "yarn build && electron-builder --mac",
"dist-win": "yarn build && electron-builder --win",
"lint": "eslint -c .eslintrc --ext .tsx,ts ./src",
"lint-fix": "eslint --fix -c .eslintrc --ext .tsx,ts ./src",
"dist-flatpak": "cd flatpak && flatpak-builder build local.heroic.yml --install --force-clean --user",
"flatpak-test": "yarn dist appimage && cd flatpak && flatpak-builder build local.heroic.yml --install --force-clean --user",
"i18n": "i18next",
Expand Down Expand Up @@ -215,29 +204,24 @@
"@types/tmp": "^0.2.3",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@vitejs/plugin-react": "^2.0.0",
"electron": "^19.0.9",
"electron-builder": "^23.1.0",
"electron-devtools-installer": "^3.2.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-react": "^7.29.4",
"foreman": "^3.0.1",
"husky": "^7.0.4",
"i18next-parser": "^6.3.0",
"jest": "^28.1.3",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"tmp": "^0.2.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version"
]
"ts-jest": "^28.0.7",
"typescript": "^4.6.3",
"vite": "^3.0.3",
"vite-plugin-electron": "^0.8.3",
"vite-plugin-svgr": "^2.2.1",
"vite-tsconfig-paths": "^3.5.0"
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSync, copyFileSync, mkdirSync } from 'graceful-fs'
import { GameInfo } from '../../types'
import { GameInfo } from 'common/types'
import { join } from 'path'
import { DirResult, dirSync } from 'tmp'
import {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { heroicAnticheatDataPath, isLinux } from '../constants'
import * as axios from 'axios'
import { logInfo, LogPrefix, logWarning } from '../logger/logger'
import { readFileSync, writeFileSync } from 'graceful-fs'
import { AntiCheatInfo } from '../types'
import { AntiCheatInfo } from 'common/types'

async function downloadAntiCheatData() {
if (!isLinux) return
Expand Down
6 changes: 5 additions & 1 deletion electron/config.ts → src/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
import { homedir, userInfo as user } from 'os'
import { parse as plistParse, PlistObject } from 'plist'

import { AppSettings, GlobalConfigVersion, WineInstallation } from './types'
import {
AppSettings,
GlobalConfigVersion,
WineInstallation
} from 'common/types'
import { LegendaryUser } from './legendary/user'
import {
currentGlobalConfigVersion,
Expand Down
18 changes: 12 additions & 6 deletions electron/constants.ts → src/backend/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { homedir, platform } from 'os'
import { join, normalize } from 'path'
import path, { join, normalize } from 'path'
import Store from 'electron-store'
import { parse } from '@node-steam/vdf'

import { GameConfigVersion, GlobalConfigVersion } from './types'
import { GameConfigVersion, GlobalConfigVersion } from 'common/types'
import {
createNewLogFileAndClearOldOnces,
logDebug,
Expand Down Expand Up @@ -58,9 +58,14 @@ const heroicAnticheatDataPath = join(heroicFolder, 'areweanticheatyet.json')
const { currentLogFile: currentLogFile, lastLogFile: lastLogFile } =
createNewLogFileAndClearOldOnces()

const icon = fixAsarPath(join(__dirname, 'icon.png'))
const iconDark = fixAsarPath(join(__dirname, 'icon-dark.png'))
const iconLight = fixAsarPath(join(__dirname, 'icon-light.png'))
const publicDir = path.resolve(
__dirname,
'..',
app.isPackaged ? '' : '../public'
)
const icon = fixAsarPath(join(publicDir, 'icon.png'))
const iconDark = fixAsarPath(join(publicDir, 'icon-dark.png'))
const iconLight = fixAsarPath(join(publicDir, 'icon-light.png'))
const installed = join(legendaryConfigPath, 'installed.json')
const libraryPath = join(legendaryConfigPath, 'metadata')
const fallBackImage = 'fallback'
Expand Down Expand Up @@ -218,5 +223,6 @@ export {
isSteamDeckGameMode,
runtimePath,
isCLIFullscreen,
isCLINoGui
isCLINoGui,
publicDir
}
2 changes: 1 addition & 1 deletion electron/game_config.ts → src/backend/game_config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, readFileSync, writeFileSync } from 'graceful-fs'

import { GameConfigVersion, GameSettings } from './types'
import { GameConfigVersion, GameSettings } from 'common/types'
import { GlobalConfig } from './config'
import {
currentGameConfigVersion,
Expand Down
18 changes: 3 additions & 15 deletions electron/games.ts → src/backend/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ import {
GameInfo,
GameSettings,
InstallArgs,
InstallInfo,
Runner
} from './types'
InstallInfo
} from '../common/types'
import type { Runner } from '../common/types'

abstract class Game {
public static get(
appName: string,
runner: Runner = 'legendary'
): LegendaryGame | GOGGame {
if (runner === 'legendary') {
return LegendaryGame.get(appName)
} else if (runner === 'gog') {
return GOGGame.get(appName)
}
}
public get logFileLocation() {
return join(heroicGamesConfigPath, `${this.appName}-lastPlay.log`)
}
Expand All @@ -45,9 +35,7 @@ abstract class Game {
abstract runWineCommand(command: string, wait?: boolean): Promise<ExecResult>
}

import { LegendaryGame } from './legendary/games'
import { BrowserWindow } from 'electron'
import { GOGGame } from './gog/games'
import { join } from 'path'
import { heroicGamesConfigPath } from './constants'

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions electron/gog/games.ts → src/backend/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
GOGLoginData,
InstalledInfo,
SteamRuntime
} from 'types'
} from 'common/types'
import { appendFileSync, existsSync, rmSync } from 'graceful-fs'
import {
heroicGamesConfigPath,
Expand Down Expand Up @@ -66,7 +66,7 @@ class GOGGame extends Game {
if (!this.instances.get(appName)) {
this.instances.set(appName, new GOGGame(appName))
}
return this.instances.get(appName)
return this.instances.get(appName) as GOGGame
}
public async getExtraInfo(): Promise<ExtraInfo> {
const gameInfo = GOGLibrary.get().getGameInfo(this.appName)
Expand Down