All files / src/lib/compiler/validate validateEjectedBuild.ts

0% Statements 0/18
0% Branches 0/22
0% Functions 0/3
0% Lines 0/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                                 
import { readFile } from "fs-extra";
import Path from "path";
import l10n from "shared/lib/lang/l10n";
 
type ValidateOptions = {
  buildRoot: string;
  progress: (msg: string) => void;
  warnings: (msg: string) => void;
};
 
export const validateEjectedBuild = async ({
  buildRoot,
  progress = (_msg) => {},
  warnings = (_msg) => {},
}: ValidateOptions) => {
  const vmIncludePath = Path.join(buildRoot, "include/vm.h");
  const gameGlobalsPath = Path.join(buildRoot, "include/data/game_globals.i");
  const vmInclude = await readFile(vmIncludePath, "utf8");
  const gameGlobals = await readFile(gameGlobalsPath, "utf8");
 
  const vmHeapSizeStr = vmInclude.match(/#define VM_HEAP_SIZE (\d+)/m)?.[1];
  const maxGlobalVarsStr = gameGlobals.match(/MAX_GLOBAL_VARS = (\d+)/m)?.[1];
 
  const vmHeapSize = parseInt(vmHeapSizeStr ?? "", 10);
  const maxGlobalVars = parseInt(maxGlobalVarsStr ?? "", 10);
 
  progress(`${l10n("COMPILING_VALIDATING_BUILD_FILES")}...`);
 
  Iif (isNaN(vmHeapSize) || isNaN(maxGlobalVars)) {
    warnings(
      "Unable to read VM_HEAP_SIZE and MAX_GLOBAL_VARS to determine if project contains too many unique variables"
    );
  }
 
  Iif (maxGlobalVars > vmHeapSize) {
    warnings(
      `Your project contains too many unique variables and will not work as expected. VM_HEAP_SIZE defines the maximum amount of variables allowed ${vmHeapSize} but your project contained ${maxGlobalVars} unique variables.`
    );
  }
};