mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 00:28:14 +00:00
build: migrate build system to Vite and test runner to Vitest & Remove depracated husky usage (#2703)
- Replace Webpack with Vite for faster client bundling and HMR. - Migrate tests from Jest to Vitest and update configuration. - Update Web Worker instantiation to standard ESM syntax. - Implement Env utility in `src/core` for safe, hybrid environment variable access (Vite vs Node). - Refactor configuration loaders to remove direct `process.env` dependencies in shared code. - Update TypeScript environment definitions and project scripts for the new toolchain. - Remove the [depracated usage of the husky](https://github.com/typicode/husky/releases/tag/v9.0.1). ## Description: migrate build system to Vite and test runner to Vitest & Remove depracated husky usage ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [ ] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: wraith4081 --------- Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
@@ -2,14 +2,6 @@ import { GameMapType } from "./Game";
|
||||
import { GameMapLoader, MapData } from "./GameMapLoader";
|
||||
import { MapManifest } from "./TerrainMapLoader";
|
||||
|
||||
export interface BinModule {
|
||||
default: string;
|
||||
}
|
||||
|
||||
interface NationMapModule {
|
||||
default: MapManifest;
|
||||
}
|
||||
|
||||
export class BinaryLoaderGameMapLoader implements GameMapLoader {
|
||||
private maps: Map<GameMapType, MapData>;
|
||||
|
||||
@@ -36,59 +28,38 @@ export class BinaryLoaderGameMapLoader implements GameMapLoader {
|
||||
);
|
||||
const fileName = key?.toLowerCase();
|
||||
|
||||
const loadBinary = (url: string) =>
|
||||
fetch(url)
|
||||
.then((res) => {
|
||||
if (!res.ok) throw new Error(`Failed to load ${url}`);
|
||||
return res.arrayBuffer();
|
||||
})
|
||||
.then((buf) => new Uint8Array(buf));
|
||||
|
||||
const mapBasePath = `/maps/${fileName}`;
|
||||
|
||||
const mapData = {
|
||||
mapBin: this.createLazyLoader(() =>
|
||||
(
|
||||
import(
|
||||
`!!binary-loader!../../../resources/maps/${fileName}/map.bin`
|
||||
) as Promise<BinModule>
|
||||
).then((m) => this.toUInt8Array(m.default)),
|
||||
),
|
||||
mapBin: this.createLazyLoader(() => loadBinary(`${mapBasePath}/map.bin`)),
|
||||
map4xBin: this.createLazyLoader(() =>
|
||||
(
|
||||
import(
|
||||
`!!binary-loader!../../../resources/maps/${fileName}/map4x.bin`
|
||||
) as Promise<BinModule>
|
||||
).then((m) => this.toUInt8Array(m.default)),
|
||||
loadBinary(`${mapBasePath}/map4x.bin`),
|
||||
),
|
||||
map16xBin: this.createLazyLoader(() =>
|
||||
(
|
||||
import(
|
||||
`!!binary-loader!../../../resources/maps/${fileName}/map16x.bin`
|
||||
) as Promise<BinModule>
|
||||
).then((m) => this.toUInt8Array(m.default)),
|
||||
loadBinary(`${mapBasePath}/map16x.bin`),
|
||||
),
|
||||
manifest: this.createLazyLoader(() =>
|
||||
(
|
||||
import(
|
||||
`../../../resources/maps/${fileName}/manifest.json`
|
||||
) as Promise<NationMapModule>
|
||||
).then((m) => m.default),
|
||||
fetch(`${mapBasePath}/manifest.json`).then((res) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to load ${mapBasePath}/manifest.json`);
|
||||
}
|
||||
return res.json() as Promise<MapManifest>;
|
||||
}),
|
||||
),
|
||||
webpPath: this.createLazyLoader(() =>
|
||||
(
|
||||
import(
|
||||
`../../../resources/maps/${fileName}/thumbnail.webp`
|
||||
) as Promise<{ default: string }>
|
||||
).then((m) => m.default),
|
||||
Promise.resolve(`${mapBasePath}/thumbnail.webp`),
|
||||
),
|
||||
} satisfies MapData;
|
||||
|
||||
this.maps.set(map, mapData);
|
||||
return mapData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given string into a UInt8Array where each character in the string
|
||||
* is represented as an 8-bit unsigned integer.
|
||||
*/
|
||||
private toUInt8Array(data: string) {
|
||||
const rawData = new Uint8Array(data.length);
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
rawData[i] = data.charCodeAt(i);
|
||||
}
|
||||
|
||||
return rawData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ export class FetchGameMapLoader implements GameMapLoader {
|
||||
let url = `${this.prefix}/${map}/${path}`;
|
||||
|
||||
if (this.cacheBuster) {
|
||||
url += `${url.includes("?") ? "&" : "?"}v=${this.cacheBuster}`;
|
||||
url += `${url.includes("?") ? "&" : "?"}v=${encodeURIComponent(
|
||||
this.cacheBuster.trim(),
|
||||
)}`;
|
||||
}
|
||||
|
||||
return url;
|
||||
|
||||
Reference in New Issue
Block a user