Skip to content

Commit

Permalink
Merge patch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 7, 2024
2 parents 212e190 + 32f58e4 commit 5453477
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 76 deletions.
37 changes: 37 additions & 0 deletions doc/adr/0006-fully-resolved-module-paths.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 6. Fully-resolved Module Paths

Date: 2024-09-02

## Status

Accepted

## Context

Farmhand's Vercel-based API code imports a subset of the browser-based game code in order to function. The browser code is processed by Vite at build time and therefore doesn't require fully-resolved module paths. So, this would be a valid import:

```js
import Farmhand from './components/Farmhand'
```

Which would resolve to `./components/Farmhand/index.js`. However, Vercel executes serverless function code as raw, [standard ES6 modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) via Node. So, code with shorthand paths such as this break the Vercel API. Fully-resolved import paths that look like this work in both environments:

```js
import Farmhand from './components/Farmhand/index.js'
```

---

See:

- https://github.com/jeremyckahn/farmhand/pull/506 (reverted)
- https://github.com/jeremyckahn/farmhand/pull/509 (contains #506 along with fixes)

## Decision

In order to keep code compatible with both client-side web app and the server-side API, modules paths must be fully resolved. So, they must include the trailing `.js` file extension.

## Consequences

- Code can be consumed by both Vite for the web app and Node in Vercel for the server API
- Module paths are more verbose and less flexible
100 changes: 41 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jeremyckahn/farmhand",
"version": "1.18.18",
"version": "1.18.19",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -112,7 +112,7 @@
"compass-mixins": "^0.12.12",
"dinero.js": "^1.7.0",
"electron-is-dev": "^2.0.0",
"electron-updater": "^5.0.5",
"electron-updater": "^6.3.0",
"fast-memoize": "^2.5.2",
"file-saver": "^2.0.2",
"fs": "npm:browserify-fs@^1.0.0",
Expand Down
20 changes: 10 additions & 10 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ export const INITIAL_FIELD_HEIGHT = 10
export const PURCHASEABLE_FIELD_SIZES = freeze(
new Map([
[1, { columns: 8, rows: 12, price: 1_000 }],
[2, { columns: 10, rows: 16, price: 2_000 }],
[3, { columns: 12, rows: 18, price: 3_000 }],
[2, { columns: 10, rows: 16, price: 5_000 }],
[3, { columns: 12, rows: 18, price: 20_000 }],
])
)

export const INITIAL_FOREST_WIDTH = 4
export const INITIAL_FOREST_HEIGHT = 1

/**
* @type Map<number, farmhand.purchasableFieldSize>
* @type Map<number, farmhand.purchaseableFieldSize>
*/
export const PURCHASABLE_FOREST_SIZES = freeze(
new Map([
Expand All @@ -68,30 +68,30 @@ export const LARGEST_PURCHASABLE_FIELD_SIZE = /** @type {farmhand.purchaseableFi
))

export const PURCHASEABLE_COMBINES = freeze(
new Map([[1, { type: 'Basic', price: 500_000 }]])
new Map([[1, { type: 'Basic', price: 250_000 }]])
)

export const PURCHASEABLE_COMPOSTERS = freeze(
new Map([[1, { type: 'Basic', price: 1_000 }]])
)

export const PURCHASEABLE_SMELTERS = freeze(
new Map([[1, { type: 'Basic', price: 500_000 }]])
new Map([[1, { type: 'Basic', price: 250_000 }]])
)

export const PURCHASEABLE_COW_PENS = freeze(
new Map([
[1, { cows: 10, price: 1500 }],
[2, { cows: 20, price: 2500 }],
[3, { cows: 30, price: 3500 }],
[1, { cows: 10, price: 1_500 }],
[2, { cows: 20, price: 10_000 }],
[3, { cows: 30, price: 50_000 }],
])
)

export const PURCHASEABLE_CELLARS = freeze(
new Map([
[1, { space: 10, price: 250_000 }],
[2, { space: 20, price: 400_000 }],
[3, { space: 30, price: 500_000 }],
[2, { space: 20, price: 750_000 }],
[3, { space: 30, price: 2_000_000 }],
])
)

Expand Down
7 changes: 5 additions & 2 deletions src/game-logic/reducers/purchaseCombine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ describe('purchaseCombine', () => {
})

test('deducts money', () => {
const { money } = purchaseCombine({ money: 500000 }, 1)
expect(money).toEqual(PURCHASEABLE_COMBINES.get(1).price - 500000)
const { money } = purchaseCombine(
{ money: (PURCHASEABLE_COMBINES.get(1)?.price ?? 0) + 10 },
1
)
expect(money).toEqual(10)
})
})
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
"module": "ES2022" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": [
"ES2022"
] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true /* Report errors in .js files. */,
"jsx": "preserve" /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */,
Expand Down
2 changes: 1 addition & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ignoreCommand": "stat static",
"ignoreCommand": "stat static || (git log -1 --pretty=oneline --abbrev-commit | grep -w \"\\[skip deploy\\]\" && exit 0 || exit 1)",
"framework": "vite",
"outputDirectory": "dist",
"rewrites": [
Expand Down

0 comments on commit 5453477

Please sign in to comment.