From 265e77a44c0c055ff3d5c8930c5c9ccc9c738dc6 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sun, 1 Sep 2024 17:00:11 -0500 Subject: [PATCH 1/2] fix(vite): Make online play work (#509) * Re-revert Vite migration * fix(api): use module import syntax * fix(vite): treat .js as .jsx files * fix(api): don't treat project as a module * fix(config): use VITE_API_ROOT * Revert "fix(api): don't treat project as a module" This reverts commit 2c86ab028e6aae2f61f09233e8edd94011004771. * chore(eslint): enable import/extensions rule * fix(ci): run lint * fix(project): [wip] use fully resolved import paths * fix(api): use module exports * fix(imports): allow virtual:pwa-register/react * fix(api): use nullish check for import.meta.env * fix(scripts): make print:crops work --- .env | 10 +- .env.development.local | 4 +- .eslintrc.json | 6 +- .github/workflows/ci.yml | 14 +- .github/workflows/run-release.yml | 14 +- .gitignore | 1 + README.md | 6 +- api-etc/templates.js | 2 +- api-etc/utils.js | 16 +- api/get-market-data.js | 12 +- api/post-day-results.js | 18 +- ...publish-global-market-values-to-discord.js | 18 +- public/index.html => index.html | 23 +- manifest.js | 34 + package-lock.json | 62779 ++++++++-------- package.json | 76 +- public/manifest.json | 31 - src/common/services/randomNumber.js | 6 +- src/common/services/randomNumber.test.js | 4 +- src/common/utils.js | 4 +- src/common/utils.test.js | 12 +- .../AccountingView/AccountingView.js | 20 +- .../AccountingView/AccountingView.test.js | 10 +- src/components/AccountingView/index.js | 2 +- src/components/Achievement/Achievement.js | 12 +- .../Achievement/Achievement.test.js | 4 +- src/components/Achievement/index.js | 2 +- .../AchievementsView/AchievementsView.js | 18 +- .../AchievementsView/AchievementsView.test.js | 2 +- src/components/AchievementsView/index.js | 2 +- .../AnimatedNumber/AnimatedNumber.js | 2 - .../AnimatedNumber/AnimatedNumber.sass | 1 - .../AnimatedNumber/AnimatedNumber.test.js | 2 +- src/components/AnimatedNumber/index.js | 2 +- src/components/AppBar/AppBar.js | 12 +- src/components/AppBar/AppBar.test.js | 4 +- src/components/AppBar/index.js | 2 +- .../BailOutErrorBoundary.test.js | 2 +- src/components/BailOutErrorBoundary/index.js | 2 +- src/components/Cellar/Cellar.js | 12 +- .../Cellar/CellarInventoryTabPanel.js | 16 +- src/components/Cellar/FermentationTabPanel.js | 10 +- src/components/Cellar/Keg.js | 30 +- src/components/Cellar/WinemakingTabPanel.js | 10 +- src/components/Cellar/index.js | 2 +- src/components/ChatRoom/ChatRoom.js | 12 +- src/components/ChatRoom/index.js | 2 +- src/components/ContextPane/ContextPane.js | 8 +- src/components/ContextPane/ContextPane.sass | 2 + .../ContextPane/ContextPane.test.js | 4 +- src/components/ContextPane/index.js | 2 +- src/components/CowCard/Bloodline/Bloodline.js | 4 +- .../CowCard/Bloodline/Bloodline.test.js | 2 +- src/components/CowCard/Bloodline/index.js | 2 +- src/components/CowCard/CowCard.js | 33 +- src/components/CowCard/CowCard.test.js | 10 +- src/components/CowCard/Subheader/Subheader.js | 22 +- .../CowCard/Subheader/Subheader.test.js | 8 +- src/components/CowCard/Subheader/index.js | 2 +- src/components/CowCard/index.js | 2 +- src/components/CowPen/CowPen.js | 14 +- src/components/CowPen/CowPen.sass | 2 +- src/components/CowPen/CowPen.test.js | 27 +- src/components/CowPen/index.js | 2 +- .../CowPenContextMenu/CowPenContextMenu.js | 30 +- .../CowPenContextMenu.test.js | 10 +- src/components/CowPenContextMenu/index.js | 2 +- src/components/DebugMenu/DebugMenu.js | 12 +- src/components/DebugMenu/DebugMenu.test.js | 4 +- src/components/DebugMenu/index.js | 2 +- src/components/Elements/index.js | 2 +- src/components/Farmhand/Farmhand.context.js | 4 +- src/components/Farmhand/Farmhand.js | 101 +- src/components/Farmhand/Farmhand.sass | 17 +- src/components/Farmhand/Farmhand.test.js | 8 +- src/components/Farmhand/FarmhandReducers.js | 8 +- .../helpers/getInventoryQuantities.js | 2 +- .../helpers/getInventoryQuantities.test.js | 6 +- src/components/Farmhand/index.js | 2 +- .../FermentationRecipe.js | 32 +- .../FermentationRecipeList.js | 8 +- .../FermentationRecipeList.test.js | 12 +- src/components/Field/Field.js | 37 +- src/components/Field/Field.sass | 2 +- src/components/Field/Field.test.js | 75 +- src/components/Field/index.js | 2 +- src/components/Forest/index.js | 2 +- src/components/Home/Home.js | 48 +- src/components/Home/Home.test.js | 6 +- src/components/Home/SnowBackground.js | 4 +- src/components/Home/index.js | 2 +- .../IngredientsList/IngredientsList.js | 6 +- .../IngredientsList/IngredientsList.test.js | 2 +- src/components/IngredientsList/index.js | 2 +- src/components/Inventory/Inventory.js | 14 +- src/components/Inventory/Inventory.sass | 1 - src/components/Inventory/Inventory.test.js | 41 +- src/components/Inventory/index.js | 2 +- src/components/Item/Item.js | 40 +- src/components/Item/Item.test.js | 8 +- src/components/Item/index.js | 2 +- .../KeybindingsView/KeybindingsView.js | 14 +- .../KeybindingsView/KeybindingsView.sass | 1 - .../KeybindingsView/KeybindingsView.test.js | 2 +- src/components/KeybindingsView/index.js | 2 +- src/components/LogView/LogView.js | 6 +- src/components/LogView/LogView.test.js | 4 +- src/components/LogView/index.js | 2 +- .../Navigation/DayAndProgressContainer.js | 14 +- src/components/Navigation/Navigation.js | 72 +- src/components/Navigation/Navigation.test.js | 10 +- src/components/Navigation/index.js | 2 +- .../NotificationSystem/NotificationSystem.js | 6 +- .../NotificationSystem.test.js | 2 +- src/components/NotificationSystem/index.js | 2 +- .../OnlinePeersView/OnlinePeer/OnlinePeer.js | 16 +- .../OnlinePeer/OnlinePeer.sass | 2 - .../OnlinePeer/OnlinePeer.test.js | 2 +- .../OnlinePeersView/OnlinePeer/index.js | 2 +- .../OnlinePeersView/OnlinePeersView.js | 22 +- .../OnlinePeersView/OnlinePeersView.sass | 1 - .../OnlinePeersView/OnlinePeersView.test.js | 2 +- src/components/OnlinePeersView/index.js | 2 +- src/components/Plot/Plot.js | 22 +- src/components/Plot/Plot.rtl.test.js | 20 +- src/components/Plot/Plot.sass | 2 +- src/components/Plot/Plot.test.js | 26 +- src/components/Plot/index.js | 2 +- .../PriceEventView/PriceEventView.js | 10 +- .../PriceEventView/PriceEventView.sass | 1 - .../PriceEventView/PriceEventView.test.js | 2 +- src/components/PriceEventView/index.js | 2 +- .../ProgressBar/ProgressBar.test.js | 2 +- src/components/ProgressBar/index.js | 2 +- src/components/QuantityInput/QuantityInput.js | 14 +- .../QuantityInput/QuantityInput.test.js | 4 +- src/components/QuantityInput/index.js | 2 +- src/components/QuickSelect/QuickSelect.js | 20 +- .../QuickSelect/QuickSelect.test.js | 4 +- src/components/QuickSelect/index.js | 2 +- src/components/Recipe/Recipe.js | 28 +- src/components/Recipe/Recipe.test.js | 4 +- src/components/Recipe/index.js | 2 +- src/components/RecipeList/RecipeList.js | 2 +- .../SettingsView/RandomSeedInput.js | 8 +- .../SettingsView/RandomSeedInput.test.js | 6 +- src/components/SettingsView/SettingsView.js | 28 +- .../SettingsView/SettingsView.test.js | 4 +- src/components/SettingsView/index.js | 2 +- src/components/Shop/Shop.js | 38 +- src/components/Shop/Shop.test.js | 8 +- src/components/Shop/index.js | 2 +- src/components/Stage/Stage.js | 20 +- src/components/Stage/Stage.test.js | 10 +- src/components/Stage/index.js | 2 +- src/components/StatsView/StatsView.js | 30 +- src/components/StatsView/StatsView.test.js | 2 +- src/components/StatsView/index.js | 2 +- src/components/TierPurchase/TierPurchase.js | 18 +- .../TierPurchase/TierPurchase.test.js | 4 +- src/components/TierPurchase/index.js | 2 +- src/components/Toolbelt/Toolbelt.js | 18 +- src/components/Toolbelt/Toolbelt.test.js | 8 +- src/components/Toolbelt/index.js | 2 +- .../UpdateNotifier/UpdateNotifier.js | 33 + src/components/UpdateNotifier/index.js | 1 + .../UpgradePurchase/UpgradePurchase.js | 20 +- .../UpgradePurchase/UpgradePurchase.test.js | 6 +- src/components/UpgradePurchase/index.js | 2 +- src/components/WineRecipeList/WineRecipe.js | 37 +- .../WineRecipeList/WineRecipe.test.js | 26 +- .../WineRecipeList/WineRecipeList.js | 8 +- src/components/Workshop/ForgeTabPanel.js | 18 +- src/components/Workshop/KitchenTabPanel.js | 14 +- src/components/Workshop/RecyclingTabPanel.js | 14 +- src/components/Workshop/Workshop.js | 18 +- src/components/Workshop/Workshop.test.js | 24 +- .../Workshop/getUpgradesAvailable.js | 4 +- .../Workshop/getUpgradesAvailable.test.js | 4 +- src/components/Workshop/index.js | 2 +- src/config.js | 49 +- src/constants.js | 6 +- src/data/__mocks__/items.js | 7 +- src/data/__mocks__/maps.js | 18 +- src/data/__mocks__/recipes.js | 7 +- src/data/achievements.js | 16 +- src/data/achievements.test.js | 20 +- src/data/crop.js | 4 +- src/data/crops/asparagus.js | 4 +- src/data/crops/carrot.js | 4 +- src/data/crops/corn.js | 4 +- src/data/crops/garlic.js | 4 +- src/data/crops/grape.js | 4 +- src/data/crops/index.js | 38 +- src/data/crops/jalapeno.js | 4 +- src/data/crops/olive.js | 4 +- src/data/crops/onion.js | 4 +- src/data/crops/pea.js | 4 +- src/data/crops/potato.js | 4 +- src/data/crops/pumpkin.js | 4 +- src/data/crops/soybean.js | 4 +- src/data/crops/spinach.js | 4 +- src/data/crops/strawberry.js | 4 +- src/data/crops/sunflower.js | 4 +- src/data/crops/sweet-potato.js | 4 +- src/data/crops/tomato.js | 4 +- src/data/crops/watermelon.js | 4 +- src/data/crops/wheat.js | 4 +- src/data/items-map.js | 2 +- src/data/items.js | 8 +- src/data/levels.js | 8 +- src/data/maps.js | 10 +- src/data/ores/bronzeOre.js | 4 +- src/data/ores/coal.js | 4 +- src/data/ores/goldOre.js | 4 +- src/data/ores/index.js | 14 +- src/data/ores/ironOre.js | 4 +- src/data/ores/saltRock.js | 4 +- src/data/ores/silverOre.js | 4 +- src/data/ores/stone.js | 4 +- src/data/recipes.js | 12 +- src/data/shop-inventory-cow.js | 2 +- src/data/shop-inventory.js | 4 +- src/data/tools.js | 4 +- src/data/upgrades.js | 6 +- src/factories/CoalFactory.js | 6 +- src/factories/CoalFactory.test.js | 8 +- src/factories/OreFactory.js | 6 +- src/factories/OreFactory.test.js | 8 +- src/factories/ResourceFactory.js | 16 +- src/factories/ResourceFactory.test.js | 22 +- src/factories/StoneFactory.js | 8 +- src/factories/StoneFactory.test.js | 8 +- src/factories/index.js | 2 +- src/game-logic/cows/cow-selection.test.js | 22 +- src/game-logic/field-purchase.test.js | 6 +- src/game-logic/item-purchase.test.js | 4 +- src/game-logic/item-sell.test.js | 4 +- src/game-logic/reducers/addExperience.js | 4 +- src/game-logic/reducers/addExperience.test.js | 4 +- src/game-logic/reducers/addItemToInventory.js | 2 +- .../reducers/addItemToInventory.test.js | 4 +- src/game-logic/reducers/addRevenue.js | 2 +- src/game-logic/reducers/adjustLoan.js | 6 +- src/game-logic/reducers/adjustLoan.test.js | 4 +- src/game-logic/reducers/applyCrows.js | 14 +- src/game-logic/reducers/applyCrows.test.js | 12 +- src/game-logic/reducers/applyLoanInterest.js | 6 +- .../reducers/applyLoanInterest.test.js | 2 +- src/game-logic/reducers/applyPrecipitation.js | 14 +- .../reducers/applyPrecipitation.test.js | 20 +- .../reducers/changeCowAutomaticHugState.js | 12 +- .../changeCowAutomaticHugState.test.js | 8 +- .../reducers/changeCowBreedingPenResident.js | 2 +- .../changeCowBreedingPenResident.test.js | 6 +- src/game-logic/reducers/changeCowName.js | 4 +- src/game-logic/reducers/changeCowName.test.js | 6 +- src/game-logic/reducers/clearPlot.js | 14 +- src/game-logic/reducers/clearPlot.test.js | 16 +- .../reducers/computeCowInventoryForNextDay.js | 2 +- .../computeCowInventoryForNextDay.test.js | 4 +- .../reducers/computeStateForNextDay.js | 42 +- .../reducers/computeStateForNextDay.test.js | 14 +- .../reducers/createPriceEvent.test.js | 6 +- .../decrementItemFromInventory.test.js | 4 +- src/game-logic/reducers/fertilizePlot.js | 10 +- src/game-logic/reducers/fertilizePlot.test.js | 10 +- src/game-logic/reducers/forRange.test.js | 8 +- .../reducers/generatePriceEvents.js | 14 +- .../reducers/generatePriceEvents.test.js | 24 +- src/game-logic/reducers/harvestPlot.js | 16 +- src/game-logic/reducers/harvestPlot.test.js | 14 +- src/game-logic/reducers/helpers.js | 8 +- src/game-logic/reducers/hugCow.js | 4 +- src/game-logic/reducers/hugCow.test.js | 6 +- .../reducers/incrementPlotContentAge.js | 6 +- .../reducers/incrementPlotContentAge.test.js | 12 +- src/game-logic/reducers/index.js | 152 +- .../reducers/makeFermentationRecipe.js | 16 +- .../reducers/makeFermentationRecipe.test.js | 6 +- src/game-logic/reducers/makeRecipe.js | 12 +- src/game-logic/reducers/makeRecipe.test.js | 25 +- src/game-logic/reducers/makeWine.js | 16 +- src/game-logic/reducers/makeWine.test.js | 14 +- src/game-logic/reducers/minePlot.js | 16 +- src/game-logic/reducers/minePlot.test.js | 14 +- src/game-logic/reducers/offerCow.test.js | 2 +- src/game-logic/reducers/plantInPlot.js | 10 +- src/game-logic/reducers/plantInPlot.test.js | 10 +- .../reducers/prependPendingPeerMessage.js | 2 +- .../prependPendingPeerMessage.test.js | 4 +- src/game-logic/reducers/processCellar.js | 2 +- src/game-logic/reducers/processCellar.test.js | 4 +- .../reducers/processCellarSpoilage.js | 12 +- .../reducers/processCellarSpoilage.test.js | 18 +- .../reducers/processCowAttrition.js | 6 +- .../reducers/processCowAttrition.test.js | 10 +- src/game-logic/reducers/processCowBreeding.js | 10 +- .../reducers/processCowBreeding.test.js | 8 +- .../processCowFertilizerProduction.js | 6 +- .../processCowFertilizerProduction.test.js | 10 +- src/game-logic/reducers/processFeedingCows.js | 8 +- .../reducers/processFeedingCows.test.js | 8 +- src/game-logic/reducers/processField.js | 8 +- src/game-logic/reducers/processLevelUp.js | 18 +- .../reducers/processLevelUp.test.js | 74 +- src/game-logic/reducers/processMilkingCows.js | 6 +- .../reducers/processMilkingCows.test.js | 10 +- src/game-logic/reducers/processNerfs.js | 4 +- src/game-logic/reducers/processNerfs.test.js | 6 +- src/game-logic/reducers/processSprinklers.js | 12 +- .../reducers/processSprinklers.test.js | 8 +- src/game-logic/reducers/processWeather.js | 6 +- .../reducers/processWeather.test.js | 14 +- src/game-logic/reducers/purchaseCellar.js | 10 +- .../reducers/purchaseCellar.test.js | 4 +- src/game-logic/reducers/purchaseCombine.js | 4 +- .../reducers/purchaseCombine.test.js | 4 +- src/game-logic/reducers/purchaseComposter.js | 12 +- .../reducers/purchaseComposter.test.js | 6 +- src/game-logic/reducers/purchaseCow.js | 6 +- src/game-logic/reducers/purchaseCow.test.js | 8 +- src/game-logic/reducers/purchaseCowPen.js | 10 +- .../reducers/purchaseCowPen.test.js | 4 +- src/game-logic/reducers/purchaseField.js | 6 +- src/game-logic/reducers/purchaseField.test.js | 6 +- src/game-logic/reducers/purchaseForest.js | 14 +- .../reducers/purchaseForest.test.js | 6 +- src/game-logic/reducers/purchaseItem.js | 8 +- src/game-logic/reducers/purchaseItem.test.js | 6 +- src/game-logic/reducers/purchaseSmelter.js | 12 +- .../reducers/purchaseSmelter.test.js | 6 +- .../reducers/purchaseStorageExpansion.js | 4 +- .../reducers/purchaseStorageExpansion.test.js | 6 +- .../reducers/removeCowFromInventory.js | 8 +- src/game-logic/reducers/removeFieldPlotAt.js | 2 +- .../reducers/rotateNotificationLogs.js | 2 +- .../reducers/rotateNotificationLogs.test.js | 4 +- src/game-logic/reducers/selectCow.test.js | 2 +- src/game-logic/reducers/sellCow.js | 6 +- src/game-logic/reducers/sellCow.test.js | 10 +- src/game-logic/reducers/sellItem.js | 22 +- src/game-logic/reducers/sellItem.test.js | 104 +- src/game-logic/reducers/sellKeg.js | 30 +- src/game-logic/reducers/sellKeg.test.js | 12 +- src/game-logic/reducers/setScarecrow.js | 10 +- src/game-logic/reducers/setScarecrow.test.js | 10 +- src/game-logic/reducers/setSprinkler.js | 12 +- src/game-logic/reducers/setSprinkler.test.js | 10 +- .../reducers/showNotification.test.js | 2 +- src/game-logic/reducers/spawnWeeds.js | 8 +- src/game-logic/reducers/spawnWeeds.test.js | 6 +- src/game-logic/reducers/unlockTool.js | 2 +- src/game-logic/reducers/unlockTool.test.js | 6 +- src/game-logic/reducers/updateAchievements.js | 6 +- .../reducers/updateAchievements.test.js | 32 +- .../reducers/updateFinancialRecords.js | 4 +- .../reducers/updateFinancialRecords.test.js | 2 +- .../updateInventoryRecordsForNextDay.test.js | 2 +- .../reducers/updateLearnedRecipes.js | 2 +- .../reducers/updateLearnedRecipes.test.js | 10 +- src/game-logic/reducers/updatePeer.js | 8 +- src/game-logic/reducers/updatePeer.test.js | 12 +- .../reducers/updatePlotShoveledState.test.js | 2 +- .../reducers/updatePriceEvents.test.js | 2 +- src/game-logic/reducers/upgradeTool.js | 8 +- src/game-logic/reducers/waterAllPlots.js | 2 +- src/game-logic/reducers/waterAllPlots.test.js | 8 +- src/game-logic/reducers/waterField.js | 2 +- src/game-logic/reducers/waterPlot.js | 6 +- src/game-logic/reducers/waterPlot.test.js | 8 +- src/game-logic/reducers/withdrawCow.test.js | 2 +- src/handlers/peer-events.js | 14 +- src/handlers/ui-events.js | 28 +- src/handlers/ui-events.test.js | 77 +- src/hooks/useMountState/index.js | 1 + src/hooks/useMountState/index.ts | 1 - .../{useMountState.ts => useMountState.js} | 0 src/img/index.js | 20 +- src/index.js | 11 +- src/index.sass | 2 +- src/mui-theme.js | 2 +- src/react-app-env.d.ts | 6 +- src/scripts/generate-crop-table.js | 2 +- src/service-worker.js | 73 - src/serviceWorkerRegistration.js | 143 - src/services/cellar.js | 10 +- src/services/cellar.test.js | 10 +- src/services/wine.js | 14 +- src/services/wine.test.js | 12 +- src/setupTests.js | 6 +- src/shell/bootup.test.js | 16 +- src/shell/field.test.js | 81 + src/shell/game-saving.test.js | 6 +- src/shell/navigation.test.js | 6 +- src/shell/notifications.test.js | 6 +- src/shell/pending-notifications.test.js | 10 +- src/strings.js | 2 +- src/templates.js | 12 +- src/test-utils/index.js | 2 +- src/test-utils/stubs/cowStub.js | 2 +- src/test-utils/stubs/farmhandStub.js | 2 +- src/test-utils/stubs/getKegStub.js | 2 +- src/test-utils/stubs/saveDataStubFactory.js | 5 +- src/utils/__snapshots__/index.test.js.snap | 4 +- src/utils/farmProductsSold.js | 6 +- src/utils/findInField.js | 4 +- src/utils/findInField.test.js | 4 +- src/utils/getCropLifecycleDuration.js | 2 +- src/utils/getCropLifecycleDuration.test.js | 4 +- src/utils/getCropsAvailableToFerment.js | 4 +- src/utils/getCropsAvailableToFerment.test.js | 6 +- src/utils/getInventoryQuantityMap.js | 2 +- src/utils/getItemBaseValue.js | 2 +- src/utils/getKegSpoilageRate.js | 4 +- src/utils/getKegSpoilageRate.test.js | 8 +- src/utils/getKegValue.js | 8 +- src/utils/getKegValue.test.js | 8 +- src/utils/getLevelEntitlements.js | 6 +- src/utils/getLevelEntitlements.test.js | 2 +- src/utils/getMaxYieldOfFermentationRecipe.js | 6 +- .../getMaxYieldOfFermentationRecipe.test.js | 6 +- src/utils/getWineVarietiesAvailableToMake.js | 6 +- .../getWineVarietiesAvailableToMake.test.js | 6 +- src/utils/getYeastRequiredForWine.js | 6 +- src/utils/index.js | 34 +- src/utils/index.test.js | 188 +- src/utils/isItemAFarmProduct.js | 4 +- src/utils/isItemAGrownCrop.js | 2 +- src/utils/memoize.js | 2 +- src/utils/moneyString.test.js | 4 +- src/utils/totalIngredientsInRecipe.test.js | 2 +- tsconfig.json | 8 +- vercel.json | 3 + vite.config.js | 105 + 435 files changed, 35099 insertions(+), 32656 deletions(-) rename public/index.html => index.html (82%) create mode 100644 manifest.js delete mode 100644 public/manifest.json delete mode 100644 src/components/AnimatedNumber/AnimatedNumber.sass delete mode 100644 src/components/Inventory/Inventory.sass delete mode 100644 src/components/KeybindingsView/KeybindingsView.sass delete mode 100644 src/components/OnlinePeersView/OnlinePeer/OnlinePeer.sass delete mode 100644 src/components/OnlinePeersView/OnlinePeersView.sass delete mode 100644 src/components/PriceEventView/PriceEventView.sass create mode 100644 src/components/UpdateNotifier/UpdateNotifier.js create mode 100644 src/components/UpdateNotifier/index.js create mode 100644 src/hooks/useMountState/index.js delete mode 100644 src/hooks/useMountState/index.ts rename src/hooks/useMountState/{useMountState.ts => useMountState.js} (100%) delete mode 100644 src/service-worker.js delete mode 100644 src/serviceWorkerRegistration.js create mode 100644 src/shell/field.test.js create mode 100644 vite.config.js diff --git a/.env b/.env index aba3261ed..eaae24c66 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ BROWSER=none -REACT_APP_API_ROOT=https://farmhand.vercel.app/ -REACT_APP_NAME=$npm_package_name -REACT_APP_VERSION=$npm_package_version -REACT_APP_TURN_USERNAME= -REACT_APP_TURN_CREDENTIAL= +VITE_API_ROOT=https://farmhand.vercel.app/ +VITE_NAME=$npm_package_name +VITE_FARMHAND_PACKAGE_VERSION=$npm_package_version +VITE_TURN_USERNAME= +VITE_TURN_CREDENTIAL= diff --git a/.env.development.local b/.env.development.local index 823eb23bd..9df7ac181 100644 --- a/.env.development.local +++ b/.env.development.local @@ -1,5 +1,5 @@ -REACT_APP_API_ROOT=http://localhost:3001/ -REACT_APP_ENABLE_FOREST=true +VITE_API_ROOT=http://localhost:3001/ +VITE_ENABLE_FOREST=true # Silence warnings from dev server # https://stackoverflow.com/a/70834076 diff --git a/.eslintrc.json b/.eslintrc.json index 3e6205b80..082a5133e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,13 @@ { + "globals": { + "vitest": true + }, "extends": ["react-app"], "rules": { "import/order": [ "error", { "newlines-between": "always-and-inside-groups" } - ] + ], + "import/extensions": ["error", "always"] } } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e0fadb6a..61758a1fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,15 +23,11 @@ jobs: - name: 'Install dependencies' run: npm ci - - name: 'Run tests' - run: npm test -- --reporters=default --reporters=jest-junit + - name: 'Lint code' + run: npm run lint - - name: Test Report - uses: dorny/test-reporter@v1 - with: - name: Jest Tests # Name of the check run which will be created - path: reports/jest-*.xml # Path to test results - reporter: jest-junit # Format of test results + - name: 'Run tests' + run: npm test -- --coverage --run - name: 'Check types' # TODO: Change this to check:types when all type errors are fixed @@ -44,4 +40,4 @@ jobs: - uses: actions/upload-artifact@v3 with: name: build-output - path: build + path: dist diff --git a/.github/workflows/run-release.yml b/.github/workflows/run-release.yml index 943ad52ae..aaf9bebd1 100644 --- a/.github/workflows/run-release.yml +++ b/.github/workflows/run-release.yml @@ -61,13 +61,13 @@ jobs: tags: true branch: main - - run: PUBLIC_URL='./' npm run build + - run: npm run build -- --base="./" - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Prepare Web Artifacts - run: zip farmhand-web-${{ env.PACKAGE_VERSION }}.zip -r build/* + run: zip farmhand-web-${{ env.PACKAGE_VERSION }}.zip -r dist/* - name: Create Release id: create_release @@ -82,7 +82,7 @@ jobs: files: | ./farmhand-web-${{ env.PACKAGE_VERSION }}.zip - - run: node -e "console.log(require('./package.json').version)" > build/version.txt + - run: node -e "console.log(require('./package.json').version)" > dist/version.txt - name: Publish itch.io build uses: josephbmanley/butler-publish-itchio-action@master env: @@ -90,18 +90,18 @@ jobs: CHANNEL: html5 ITCH_GAME: Farmhand ITCH_USER: jeremyckahn - PACKAGE: build - VERSION_FILE: build/version.txt + PACKAGE: dist + VERSION_FILE: dist/version.txt - run: | - PUBLIC_URL='/farmhand' npm run build + npm run build -- --base='/farmhand' # https://github.com/marketplace/actions/deploy-to-github-pages - name: Deploy to jeremyckahn.github.io/farmhand uses: JamesIves/github-pages-deploy-action@v4 with: branch: gh-pages - folder: build + folder: dist clean: true single-commit: true diff --git a/.gitignore b/.gitignore index 8dca9e3b9..5a00c1ad1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ build Session.vim .DS_Store .idea +coverage .vercel diff --git a/README.md b/README.md index 8a48b6e1f..2d579be36 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Farmhand uses a [SemVer](https://semver.org/)-like versioning system. It differs ## Project overview -- This project is built with [Create React App](https://create-react-app.dev/), so please refer to the documentation of that project to learn about the development toolchain. +- This project uses [Vite](https://vitejs.dev/), so please refer to the documentation of that project to learn about the development toolchain. - Farmhand uses [Piskel](https://www.piskelapp.com/) for the art assets. ## Running locally @@ -138,13 +138,13 @@ The process will take several minutes to complete and it will notify the Discord Farmhand supports feature flags for code that should only be enabled in specific environments. To create a feature flag, add a line that looks like this in the relevant `.env` file: ``` -REACT_APP_ENABLE_[FEATURE_NAME]=true +VITE_ENABLE_[FEATURE_NAME]=true ``` Where `[FEATURE_NAME]` is replaced with the name of your feature. So, adding this to `.env.development.local`: ``` -REACT_APP_ENABLE_MINING=true +VITE_ENABLE_MINING=true ``` Would enable the `MINING` feature only for the local development environment. You can access the enabled feature flags at runtime by `import`ing the `features` Object from [`config.js`](https://github.com/jeremyckahn/farmhand/blob/develop/src/config.js). See [Adding Custom Environment Variables](https://create-react-app.dev/docs/adding-custom-environment-variables/) for more information on how to use environment variables. diff --git a/api-etc/templates.js b/api-etc/templates.js index 2aefc9db4..046fbdfd6 100644 --- a/api-etc/templates.js +++ b/api-etc/templates.js @@ -1,4 +1,4 @@ -import { itemsMap } from '../src/data/maps' +import { itemsMap } from '../src/data/maps.js' export const MARKET_SUMMARY_FOR_DISCORD = (_, room, valueAdjustments) => { let string = `Current market values for the **${room}** room:\n` diff --git a/api-etc/utils.js b/api-etc/utils.js index de2462d9a..54085afe4 100644 --- a/api-etc/utils.js +++ b/api-etc/utils.js @@ -1,11 +1,11 @@ -const redis = require('redis') +import redis from 'redis' -const { generateValueAdjustments } = require('../src/common/utils') -const { MAX_ROOM_NAME_LENGTH } = require('../src/common/constants') +import { generateValueAdjustments } from '../src/common/utils.js' +import { MAX_ROOM_NAME_LENGTH } from '../src/common/constants.js' -const { GLOBAL_ROOM_KEY, ACCEPTED_ORIGINS } = require('./constants') +import { GLOBAL_ROOM_KEY, ACCEPTED_ORIGINS } from './constants.js' -module.exports.getRedisClient = () => { +export const getRedisClient = () => { const client = redis.createClient({ host: process.env.REDIS_ENDPOINT, port: process.env.REDIS_PORT, @@ -26,7 +26,7 @@ module.exports.getRedisClient = () => { return client } -module.exports.getRoomData = async (roomKey, get, set) => { +export const getRoomData = async (roomKey, get, set) => { let roomData = JSON.parse(await get(roomKey)) || {} let { valueAdjustments } = roomData @@ -39,14 +39,14 @@ module.exports.getRoomData = async (roomKey, get, set) => { return roomData } -module.exports.getRoomName = req => +export const getRoomName = req => `room-${(req.query?.room || req.body?.room || GLOBAL_ROOM_KEY).slice( 0, MAX_ROOM_NAME_LENGTH )}` // https://vercel.com/support/articles/how-to-enable-cors -module.exports.allowCors = fn => async (req, res) => { +export const allowCors = fn => async (req, res) => { res.setHeader('Access-Control-Allow-Credentials', true) // origin is not defined when the request is from the same domain as the diff --git a/api/get-market-data.js b/api/get-market-data.js index e2f01a81e..163d9f9f2 100644 --- a/api/get-market-data.js +++ b/api/get-market-data.js @@ -1,25 +1,25 @@ // Dependencies required by ./utils (see below) need to be explicitly required // here to ensure that that they are included in serverless builds. Do NOT // remove them unless they are not needed by any upstream modules. -const { promisify } = require('util') +import { promisify } from 'util' -require('redis') -require('../src/common/utils') +import 'redis' +import '../src/common/utils.js' // End explicit requires for serverless builds -const { +import { allowCors, getRedisClient, getRoomData, getRoomName, -} = require('../api-etc/utils') +} from '../api-etc/utils.js' const client = getRedisClient() const get = promisify(client.get).bind(client) const set = promisify(client.set).bind(client) -module.exports = allowCors(async (req, res) => { +export default allowCors(async (req, res) => { const roomKey = getRoomName(req) const roomData = await getRoomData(roomKey, get, set) diff --git a/api/post-day-results.js b/api/post-day-results.js index e26e9fd42..c4f428f01 100644 --- a/api/post-day-results.js +++ b/api/post-day-results.js @@ -1,21 +1,21 @@ // Dependencies required by ./utils (see below) need to be explicitly required // here to ensure that that they are included in serverless builds. Do NOT // remove them unless they are not needed by any upstream modules. -require('redis') -require('../src/common/utils') -require('../src/common/constants') -require('../api-etc/constants') +import 'redis' +import '../src/common/utils.js' +import '../src/common/constants.js' +import '../api-etc/constants.js' // End explicit requires for serverless builds -const { promisify } = require('util') +import { promisify } from 'util' -const { +import { allowCors, getRedisClient, getRoomData, getRoomName, -} = require('../api-etc/utils') -const { random } = require('../src/common/utils') +} from '../api-etc/utils.js' +import { random } from '../src/common/utils.js' const client = getRedisClient() @@ -56,7 +56,7 @@ const applyPositionsToMarket = (valueAdjustments, positions) => { ) } -module.exports = allowCors(async (req, res) => { +export default allowCors(async (req, res) => { const { body: { positions = {} }, } = req diff --git a/api/publish-global-market-values-to-discord.js b/api/publish-global-market-values-to-discord.js index 119caa118..4d3bd2b00 100644 --- a/api/publish-global-market-values-to-discord.js +++ b/api/publish-global-market-values-to-discord.js @@ -1,25 +1,25 @@ // Dependencies required by ./utils (see below) need to be explicitly required // here to ensure that that they are included in serverless builds. Do NOT // remove them unless they are not needed by any upstream modules. -require('redis') -require('../src/common/utils') -require('../src/common/constants') -require('../api-etc/constants') +import 'redis' +import '../src/common/utils.js' +import '../src/common/constants.js' +import '../api-etc/constants.js' // End explicit requires for serverless builds -const { promisify } = require('util') +import { promisify } from 'util' -const axios = require('axios') +import axios from 'axios' -const { MARKET_SUMMARY_FOR_DISCORD } = require('../api-etc/templates') -const { allowCors, getRedisClient, getRoomData } = require('../api-etc/utils') +import { MARKET_SUMMARY_FOR_DISCORD } from '../api-etc/templates.js' +import { allowCors, getRedisClient, getRoomData } from '../api-etc/utils.js' const client = getRedisClient() const get = promisify(client.get).bind(client) const set = promisify(client.set).bind(client) -module.exports = allowCors(async (req, res) => { +export default allowCors(async (req, res) => { const { valueAdjustments } = await getRoomData('room-global', get, set) const content = MARKET_SUMMARY_FOR_DISCORD`${'global'}${valueAdjustments}` const { status } = await axios.post( diff --git a/public/index.html b/index.html similarity index 82% rename from public/index.html rename to index.html index 87e8afb3e..83fedcd43 100644 --- a/public/index.html +++ b/index.html @@ -6,39 +6,31 @@ + - - - - + Farmhand