Skip to content

Optimize build system: migrate to esbuild and standardize code#351

Merged
SvenVw merged 15 commits into
developmentfrom
improve-rollup-and-vite-config
Nov 26, 2025
Merged

Optimize build system: migrate to esbuild and standardize code#351
SvenVw merged 15 commits into
developmentfrom
improve-rollup-and-vite-config

Conversation

@SvenVw
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw commented Nov 26, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Sidebar farm labels now truncate cleanly when text is too long.
  • Performance

    • Faster development builds by skipping minification and standardizing source maps.
    • Prevented dependencies from being bundled into build outputs.
  • Chores

    • Consolidated and modernized build tooling and package entry points across packages for more consistent releases.

✏️ Tip: You can customize this high-level summary in your review settings.

- Automate `external` dependency detection from package.json to prevent accidentally bundling dependencies (fixes potential code
     duplication).
- Disable `terser` minification during development to significantly improve rebuild speeds.
 - Standardize source maps: use inline maps for development and external file maps for production.
Add `@rollup/plugin-commonjs` to `fdm-data` to ensure compatibility with CommonJS dependencies.
- Removing "vibe-based" manual chunk splitting, allowing Vite/Rollup to handle chunking more effectively.
- Simplifying the conditional Sentry plugin logic for better readability and maintainability.
- Removing the unnecessary `global: {}` polyfill, which is often a workaround for legacy libraries and can hide issues.
- Correcting the `sentryReactRouter` argument passing to resolve a TypeScript error.
@SvenVw SvenVw self-assigned this Nov 26, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: 3f1cbe0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@svenvw/fdm-calculator Patch
@svenvw/fdm-core Patch
@svenvw/fdm-data Patch
@svenvw/fdm-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 26, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors monorepo build and packaging across packages, replacing TypeScript/terser Rollup plugins with esbuild, standardizing preserveModules/sourcemaps, tightening Vite Sentry activation to env-based logic, normalizing type import paths, adding build-only tsconfigs, and making typing and dose-shape refinements.

Changes

Cohort / File(s) Summary
Changesets
.changeset/jolly-eagles-clean.md, .changeset/thin-baths-care.md
Add changesets documenting build optimizations: avoid bundling workspace deps, skip minify in dev, standardize sourcemaps, remove manual chunking/polyfill, simplify Sentry activation and args.
fdm-app (config & UI)
fdm-app/vite.config.ts, fdm-app/app/components/blocks/sidebar/farm.tsx
Vite config now uses env.mode to set isProd and enableSentry (enabled only in production with SENTRY_AUTH_TOKEN); Sentry plugin invocation simplified and filtered; removed global polyfill/manualChunks; added optimizeDeps.exclude. UI: added className="truncate" to farm label span.
fdm-calculator packaging & build
fdm-calculator/package.json, fdm-calculator/rollup.config.js, fdm-calculator/tsconfig.build.json
package.json entry points -> dist/index.js; build script runs rollup -c && tsc -p tsconfig.build.json; rollup switched to object export, preserveModules output to dist, uses rollup-plugin-esbuild with env-driven minify/sourcemap, computes external from package.json. Added build tsconfig excluding tests.
fdm-calculator types & code
fdm-calculator/src/**/* (examples below)
Normalized type import paths (from *.d to *), added explicit type annotations in maps/callbacks, removed unused Harvest import, introduced DoseProperties and NumericDoseKeys, changed dose aggregation to iterate NumericDoseKeys, calculate/get-dose now extract .dose.
fdm-core packaging & build
fdm-core/package.json, fdm-core/rollup.config.js, fdm-core/tsconfig.build.json
Align package entrypoints to dist/index.js; build script runs rollup + tsc; rollup replaces TS/terser with esbuild, dir-based preserveModules output, env-driven sourcemaps/minify, external computed from package.json + Node built-ins. Added build tsconfig.
fdm-core type/test tweaks
fdm-core/src/authorization.test.ts, fdm-core/src/db/schema-custom-types.ts, fdm-core/src/field.ts, fdm-core/src/principal.ts, fdm-core/src/soil.ts
Added explicit parameter typings in mapping/predicate callbacks; geometry generic changed to keyof GeometryTypes; SRID read removed from parseHexToGeometry; relaxed ordering assertion in a test.
fdm-data packaging & build
fdm-data/package.json, fdm-data/rollup.config.js, fdm-data/tsconfig.build.json
Entry points and exports target dist/index.js; build script extended with tsc; rollup switched to esbuild + preserveModules output and dependency-driven external; added build tsconfig excluding tests; engines.node added.
Workspace catalog
pnpm-workspace.yaml
Removed @rollup/plugin-terser from catalog, added rollup-plugin-esbuild, bumped @vitest/coverage-v8 and vitest.
Examples of import/type fixes
fdm-calculator/src/balance/nitrogen/index.ts, fdm-calculator/src/balance/organic-matter/{degradation.ts,index.ts,input.ts,types.ts}, fdm-calculator/src/balance/organic-matter/supply/*, fdm-calculator/src/balance/shared/soil.ts, fdm-calculator/src/doses/{d.ts,calculate-dose.ts,get-dose-field.ts,get-dose-field.test.ts}
Import path normalizations and explicit typings; dose types reorganized (DoseProperties + NumericDoseKeys); get-dose extracts .dose; tests adjusted to flattened dose shape.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Env as build env
  participant Vite as vite.config
  participant Sentry as sentryReactRouter
  note over Vite,Sentry `#DDEBF7`: Sentry plugin enabled only when env.mode="production" and SENTRY_AUTH_TOKEN exists

  Env->>Vite: load(env)
  alt production + token
    Vite->>Sentry: sentryReactRouter(..., env)
    Sentry-->>Vite: pluginInstance
    Vite-->>build: include pluginInstance
  else otherwise
    Vite-->>build: do not include Sentry
  end
Loading
sequenceDiagram
  autonumber
  participant RollupCfg as rollup.config
  participant Esbuild as rollup-plugin-esbuild
  participant PKG as package.json
  participant FS as src/
  participant Dist as dist/

  RollupCfg->>PKG: read dependencies/peerDependencies
  RollupCfg->>FS: input src/index.ts
  RollupCfg->>Esbuild: transform (minify if isProd)
  RollupCfg->>RollupCfg: mark externals based on PKG + node builtins
  RollupCfg->>Dist: output preserveModules -> dir with entryFileNames "[name].js" and sourcemaps (inline or true)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Pay attention to:
    • Rollup configs for fdm-core, fdm-calculator, fdm-data: externals computation, preserveModules semantics and sourcemap/minify toggles.
    • fdm-app/vite.config.ts: env-based Sentry enabling and change to pass env.
    • Dose typing and runtime shape changes (DoseProperties, NumericDoseKeys, extraction of .dose) and updated tests.
    • package.json entrypoint and build script changes (consumers/CI compatibility).

Possibly related PRs

Suggested reviewers

  • gerardhros

Poem

🐰 I hopped through code at break of dawn,
swapped plugins, typed a field, then yawned.
Builds keep modules safe and neat,
sourcemaps inline when devs repeat.
Esbuild hops — the dist is born 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main objective of the changeset: migrating the build system from terser/typescript plugins to esbuild and standardizing configurations across three packages and the app.
Docstring Coverage ✅ Passed Docstring coverage is 88.89% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4cea472 and 3f1cbe0.

📒 Files selected for processing (2)
  • fdm-data/package.json (3 hunks)
  • fdm-data/rollup.config.js (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.60%. Comparing base (114afba) to head (3f1cbe0).
⚠️ Report is 16 commits behind head on development.

Files with missing lines Patch % Lines
fdm-calculator/src/balance/organic-matter/index.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           development     #351   +/-   ##
============================================
  Coverage        87.59%   87.60%           
============================================
  Files               79       79           
  Lines             3951     3952    +1     
  Branches          1141     1140    -1     
============================================
+ Hits              3461     3462    +1     
  Misses             490      490           
Flag Coverage Δ
fdm-calculator 87.81% <60.00%> (ø)
fdm-core 87.03% <100.00%> (+<0.01%) ⬆️
fdm-data 92.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SvenVw
Copy link
Copy Markdown
Collaborator Author

SvenVw commented Nov 26, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot changed the title @coderabbitai Optimize build system: migrate to esbuild and standardize code Nov 26, 2025
@coderabbitai coderabbitai Bot added branch:development Issue only affecting development, not the main branch (yet) dependencies Pull requests that update a dependency file enhancement New feature or request fdm-app fdm-calculator fdm-core fdm-data labels Nov 26, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (9)
fdm-core/src/field.ts (1)

493-496: Inline .map parameter typings are correct but duplicate schema knowledge

The new annotations { b_lu: string }, { b_id_harvestable: string }, { b_id_harvestable_analysis: string }, and { a_id: string } look accurate, but they mirror column shapes manually. To keep types single‑sourced and future‑proof, consider either:

  • Dropping the inline param types and let the select({ ... }) result drive inference, e.g. cultivations.map((c) => c.b_lu), or
  • Typing the ID arrays instead, anchored on the schema, e.g.:
const cultivationIds: schema.cultivationsTypeSelect["b_lu"][] =
    cultivations.map((c) => c.b_lu)

Same idea for harvestableIds, harvestableAnalysisIds, and soilAnalysisIds.

Also double‑check that the selected columns are non‑nullable in the schema; if any can be null, the current string annotations would be too narrow and should be widened accordingly.

Also applies to: 510-513, 530-533, 604-606

fdm-core/src/principal.ts (1)

292-297: Explicit { id: string } typing on principals.map is correct; consider centralizing the row type

The new parameter type matches how principals is built (select({ id: ... }) on user and organization), so this is type-safe and makes the map callback clearer. As a minor refinement, you could avoid repeating the inline shape by deriving a small type from the schema (or from the original select) and reusing it here, which keeps things in sync if the DB field type ever changes.

Example (optional):

type PrincipalIdRow = { id: string } // or derived from schema

const principalsDetails = await Promise.all(
    principals.map(async (principal: PrincipalIdRow) => {
        return getPrincipal(tx, principal.id)
    }),
)

Not required for this PR, just a small maintainability tweak you might consider later.

fdm-app/app/components/blocks/sidebar/farm.tsx (1)

119-121: Truncation is good; consider exposing full label via tooltip/title

Adding truncate here should help keep long farm names from breaking the sidebar layout. Consider also adding a title={farmLinkDisplay} on this span (or parent) so users can still see the full name on hover, especially when names are frequently longer than the available width.

fdm-app/vite.config.ts (1)

2-10: Sentry gating via env.mode + token looks sound; just verify plugin expectations

Using env.mode === "production" plus !!process.env.SENTRY_AUTH_TOKEN to decide enableSentry is a good guardrail so the plugin only runs for actual prod builds with credentials configured. The enableSentry && sentryReactRouter({...}, env) + .filter(Boolean) pattern keeps the plugin list clean and avoids conditionals scattered around.

Given this depends on the exact @sentry/react-router version, please double-check that passing the Vite config env as the second argument is what your installed version expects, and that the chosen env vars (PUBLIC_SENTRY_*, SENTRY_AUTH_TOKEN, npm_package_version) match how you configure Sentry elsewhere in the app.

If you want, I can also help factor the Sentry options object into a shared const sentryConfig = { ... } so it can be reused (and optionally surfaced on the returned config) without changing behavior.

Also applies to: 16-31

fdm-core/rollup.config.js (2)

4-15: Externals derived from package.json look good; consider node: specifiers if you ever use them

Building dependencies from dependencies + peerDependencies and adding only explicit Node builtins keeps the externals list tight and matches the “no extra externals” guideline. One minor nuance: external will not treat node:fs-style imports as external (only bare fs or fs/...), so if you ever switch to node: specifiers you may want to extend the predicate accordingly (e.g. also checking id.startsWith("node:")). Based on learnings, this approach to externals is consistent with earlier Rollup configs in this repo.

Also applies to: 49-49


20-24: Align Rollup sourcemap and esbuild sourceMap behaviour across envs

Right now, Rollup has sourcemap: isProd ? true : "inline" while esbuild is configured with sourceMap: !isProd, so in production Rollup writes sourcemaps but esbuild does not emit TS-level maps, and in development you get inline maps from both. If you want full TS→JS mappings in production too, consider either dropping the explicit sourceMap option and letting rollup-plugin-esbuild follow Rollup’s output.sourcemap, or setting both to the same predicate (e.g. !!isProd or !isProd, depending on intent).

Also applies to: 28-33

fdm-data/rollup.config.js (2)

4-12: Dependency‑driven externals are clean; consider subpaths if you ever import them

Building external directly from dependencies and peerDependencies keeps the bundle surface minimal and adheres to the earlier guideline about only marking real deps as external. Note that with an array, only exact IDs (e.g. "xxhash-wasm") are treated as external; if you later import subpaths (like "xxhash-wasm/foo"), you may want to switch to a predicate function similar to fdm-core/rollup.config.js that also matches dep/....

Also applies to: 33-34


15-22: Same sourcemap/esbuild inversion as fdm-core; consider unifying intent

This config also enables Rollup sourcemaps in production (sourcemap: isProd ? true : "inline") while disabling esbuild’s sourceMap there (sourceMap: !isProd), which can limit TS-level mapping in prod builds. If you want consistent behaviour, either let rollup-plugin-esbuild infer source map usage from Rollup by omitting sourceMap, or set both to the same condition depending on whether you prefer dev-only or dev+prod sourcemaps.

Also applies to: 27-31

fdm-calculator/src/doses/calculate-dose.ts (1)

133-133: Consider a type-safe alternative to as any casting.

The as any casting bypasses TypeScript's type safety for dynamic property access. While this works, it could mask future type errors.

Consider one of these approaches:

Option 1: Create a helper type for numeric dose fields

type NumericDoseKeys = Exclude<keyof Dose, 'p_app_id'>

for (const key of Object.keys(totalDose) as NumericDoseKeys[]) {
    if (key !== "p_app_id") {
        totalDose[key] += currentDose[key]
    }
}

Option 2: Use a type assertion that preserves some safety

for (const key of Object.keys(totalDose) as (keyof Dose)[]) {
    if (key !== "p_app_id") {
        (totalDose[key] as number) += (currentDose[key] as number)
    }
}

Either approach maintains better type safety while still handling the dynamic property access pattern.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 114afba and 4859b64.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (32)
  • .changeset/jolly-eagles-clean.md (1 hunks)
  • .changeset/thin-baths-care.md (1 hunks)
  • fdm-app/app/components/blocks/sidebar/farm.tsx (1 hunks)
  • fdm-app/vite.config.ts (1 hunks)
  • fdm-calculator/package.json (3 hunks)
  • fdm-calculator/rollup.config.js (1 hunks)
  • fdm-calculator/src/balance/nitrogen/index.ts (1 hunks)
  • fdm-calculator/src/balance/organic-matter/degradation.ts (2 hunks)
  • fdm-calculator/src/balance/organic-matter/index.ts (2 hunks)
  • fdm-calculator/src/balance/organic-matter/input.ts (1 hunks)
  • fdm-calculator/src/balance/organic-matter/supply/cultivation.ts (1 hunks)
  • fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts (2 hunks)
  • fdm-calculator/src/balance/organic-matter/supply/index.ts (1 hunks)
  • fdm-calculator/src/balance/organic-matter/supply/residues.ts (1 hunks)
  • fdm-calculator/src/balance/organic-matter/types.ts (0 hunks)
  • fdm-calculator/src/balance/shared/soil.ts (1 hunks)
  • fdm-calculator/src/doses/calculate-dose.ts (1 hunks)
  • fdm-calculator/src/doses/get-dose-field.test.ts (2 hunks)
  • fdm-calculator/src/doses/get-dose-field.ts (1 hunks)
  • fdm-calculator/tsconfig.build.json (1 hunks)
  • fdm-core/package.json (3 hunks)
  • fdm-core/rollup.config.js (2 hunks)
  • fdm-core/src/authorization.test.ts (1 hunks)
  • fdm-core/src/db/schema-custom-types.ts (2 hunks)
  • fdm-core/src/field.ts (4 hunks)
  • fdm-core/src/principal.ts (1 hunks)
  • fdm-core/src/soil.ts (1 hunks)
  • fdm-core/tsconfig.build.json (1 hunks)
  • fdm-data/package.json (3 hunks)
  • fdm-data/rollup.config.js (1 hunks)
  • fdm-data/tsconfig.build.json (1 hunks)
  • pnpm-workspace.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • fdm-calculator/src/balance/organic-matter/types.ts
🧰 Additional context used
🧠 Learnings (47)
📓 Common learnings
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 6
File: fdm-app/vite.config.ts:5-9
Timestamp: 2024-11-25T12:42:32.783Z
Learning: In the `fdm-app` project, SvenVw is preparing for migration to Remix v3 and may include type declarations or configurations for v3 features in advance, such as in `vite.config.ts`.
📚 Learning: 2025-11-21T10:02:25.556Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 343
File: fdm-calculator/src/balance/organic-matter/types.d.ts:12-132
Timestamp: 2025-11-21T10:02:25.556Z
Learning: In the organic matter balance calculation system (fdm-calculator), degradation values are negative by definition. This means the balance calculation using supply.total.plus(degradation.total) is correct, as it effectively computes supply - |degradation|. This follows the same pattern as the nitrogen balance system.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/residues.ts
  • fdm-calculator/src/balance/organic-matter/supply/index.ts
  • fdm-calculator/src/balance/organic-matter/degradation.ts
📚 Learning: 2025-11-24T10:43:09.278Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 343
File: fdm-app/app/components/blocks/balance/organic-matter-chart.tsx:19-25
Timestamp: 2025-11-24T10:43:09.278Z
Learning: In the organic matter balance chart (fdm-app), degradation values are multiplied by -1 before plotting to show supply and degradation bars side-by-side with positive magnitudes, enabling direct visual comparison. This is a deliberate design choice for the organic matter chart visualization, different from the nitrogen balance chart which uses separate stacks.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/residues.ts
  • fdm-calculator/src/balance/organic-matter/index.ts
  • fdm-calculator/src/balance/organic-matter/supply/index.ts
  • fdm-calculator/src/balance/organic-matter/degradation.ts
📚 Learning: 2025-11-21T10:02:25.556Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 343
File: fdm-calculator/src/balance/organic-matter/types.d.ts:12-132
Timestamp: 2025-11-21T10:02:25.556Z
Learning: In the organic matter balance calculations, EOM (Effective Organic Matter) and OM (Organic Matter) are the same units and can be used together in calculations. EOM refers to the organic matter that remains in the soil after one year.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/residues.ts
  • fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts
  • fdm-calculator/src/balance/organic-matter/supply/cultivation.ts
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A shared layout component `FarmLayoutBase` has been created in `components/custom/farm-layout-base.tsx` to maintain consistency across farm-related pages. The component handles farm selection dropdown, breadcrumb navigation, and provides a common layout structure.

Applied to files:

  • fdm-app/app/components/blocks/sidebar/farm.tsx
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: The `FarmLayout` component in `components/custom/farm-layout.tsx` provides a reusable layout structure for farm-related pages, with support for farm selection dropdown, customizable breadcrumb titles, and flexible content rendering through either children or Outlet components.

Applied to files:

  • fdm-app/app/components/blocks/sidebar/farm.tsx
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: The farm layout system has been reorganized into separate components (`FarmHeader`, `ContentLayout`, `PaginationLayout`) to support different navigation patterns (sidebar, pagination) while maintaining consistent styling. Each layout component is designed to be used independently or combined as needed.

Applied to files:

  • fdm-app/app/components/blocks/sidebar/farm.tsx
📚 Learning: 2025-01-09T16:03:37.764Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 42
File: fdm-app/app/routes/farm/_b_id_farm/layout.tsx:46-95
Timestamp: 2025-01-09T16:03:37.764Z
Learning: A comprehensive farm layout system has been created in `components/custom/farm-layouts/` with `BaseFarmLayout` and `FarmSidebarLayout` components. The system supports both simple and sidebar-based layouts while maintaining consistent header and farm selection functionality across all farm routes.

Applied to files:

  • fdm-app/app/components/blocks/sidebar/farm.tsx
📚 Learning: 2024-11-25T12:42:32.783Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 6
File: fdm-app/vite.config.ts:5-9
Timestamp: 2024-11-25T12:42:32.783Z
Learning: In the `fdm-app` project, SvenVw is preparing for migration to Remix v3 and may include type declarations or configurations for v3 features in advance, such as in `vite.config.ts`.

Applied to files:

  • .changeset/jolly-eagles-clean.md
  • .changeset/thin-baths-care.md
  • fdm-data/tsconfig.build.json
  • fdm-calculator/tsconfig.build.json
  • fdm-core/tsconfig.build.json
  • fdm-data/rollup.config.js
  • fdm-core/package.json
  • fdm-data/package.json
  • fdm-core/rollup.config.js
  • fdm-app/vite.config.ts
  • fdm-calculator/rollup.config.js
📚 Learning: 2025-08-13T10:33:05.313Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 0
File: :0-0
Timestamp: 2025-08-13T10:33:05.313Z
Learning: In the fdm project, fdm-calculator integration for new features like b_lu_variety is handled in separate updates from the core data model changes. When fdm-core functions are updated to support new fields, fdm-calculator can consume these enhanced APIs without requiring changes in the same PR that introduces the core functionality.

Applied to files:

  • .changeset/jolly-eagles-clean.md
  • fdm-calculator/tsconfig.build.json
  • fdm-calculator/package.json
  • fdm-core/package.json
  • fdm-data/package.json
  • fdm-calculator/rollup.config.js
📚 Learning: 2025-09-26T08:34:50.413Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 279
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.norms.tsx:277-283
Timestamp: 2025-09-26T08:34:50.413Z
Learning: In the fdm project, fdm-core and fdm-app are updated together as part of a monorepo structure, which eliminates legacy data concerns when new fields like b_isproductive are introduced. Both packages are synchronized, so there's no need for defensive coding against undefined values for newly introduced database fields.

Applied to files:

  • .changeset/jolly-eagles-clean.md
  • fdm-data/tsconfig.build.json
  • fdm-core/tsconfig.build.json
  • fdm-calculator/package.json
  • fdm-data/rollup.config.js
  • fdm-core/package.json
  • fdm-data/package.json
  • fdm-core/rollup.config.js
📚 Learning: 2025-09-23T10:02:32.123Z
Learnt from: BoraIneviNMI
Repo: SvenVw/fdm PR: 272
File: fdm-app/app/routes/farm.create.$b_id_farm.$calendar.fertilizers.$b_lu_catalogue.manage.$p_id.tsx:151-164
Timestamp: 2025-09-23T10:02:32.123Z
Learning: The getFertilizer function from svenvw/fdm-core throws an exception if the fertilizer doesn't exist, rather than returning null or undefined.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts
  • fdm-calculator/src/doses/get-dose-field.ts
  • fdm-calculator/src/balance/organic-matter/index.ts
  • fdm-calculator/src/balance/organic-matter/input.ts
📚 Learning: 2025-01-31T15:05:14.310Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core has optional parameters after `fdm` and `b_id`. The TypeScript definitions might show 8 required parameters due to a potential version mismatch.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts
  • fdm-calculator/src/doses/get-dose-field.test.ts
  • fdm-calculator/src/doses/calculate-dose.ts
  • fdm-calculator/src/doses/get-dose-field.ts
  • fdm-core/src/db/schema-custom-types.ts
  • fdm-core/src/field.ts
  • fdm-data/package.json
📚 Learning: 2025-08-11T11:55:26.053Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 233
File: fdm-app/app/integrations/nmi.ts:54-0
Timestamp: 2025-08-11T11:55:26.053Z
Learning: The NMI API Estimates endpoint (`https://api.nmi-agro.nl/estimates`) always returns the fields `b_gwl_ghg`, `b_gwl_glg`, and `cultivations` according to its specification. These fields should be kept as required (not optional) in the TypeScript return type and Zod validation schema in `fdm-app/app/integrations/nmi.ts`.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts
  • fdm-calculator/src/balance/organic-matter/index.ts
  • fdm-calculator/src/balance/organic-matter/supply/cultivation.ts
  • fdm-core/src/field.ts
  • fdm-calculator/src/balance/organic-matter/supply/index.ts
  • fdm-calculator/src/balance/organic-matter/degradation.ts
📚 Learning: 2025-08-14T14:31:55.384Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 236
File: fdm-calculator/src/balance/nitrogen/index.ts:173-0
Timestamp: 2025-08-14T14:31:55.384Z
Learning: In nitrogen balance calculations for agricultural systems, the balance should only include ammonia emissions (emission.ammonia.total) and should not include nitrate leaching from the emission calculation. The nitrate component (emission.nitrate) should be excluded from the balance formula.

Applied to files:

  • fdm-calculator/src/balance/nitrogen/index.ts
📚 Learning: 2025-05-26T10:32:15.538Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 134
File: fdm-calculator/src/balance/nitrogen/index.ts:236-238
Timestamp: 2025-05-26T10:32:15.538Z
Learning: In nitrogen balance calculations for agricultural systems, removal and volatilization are calculated as negative values by definition since they represent nitrogen losses from the system. The balance calculation uses addition (.add()) for all components because removal and volatilization are already negative, so adding them effectively subtracts the losses from the supply.

Applied to files:

  • fdm-calculator/src/balance/nitrogen/index.ts
📚 Learning: 2025-04-18T14:51:48.033Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/organization.ts:300-339
Timestamp: 2025-04-18T14:51:48.033Z
Learning: The `getUsersInOrganization` function in fdm-core/src/organization.ts will be updated in commit b17fac16c9e5a0de56d0346e712b2ce966d305d5 to include id and email fields, which are necessary for subsequent role updates and user removal operations.

Applied to files:

  • fdm-core/src/authorization.test.ts
  • fdm-core/src/principal.ts
📚 Learning: 2025-04-18T14:51:48.033Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/organization.ts:300-339
Timestamp: 2025-04-18T14:51:48.033Z
Learning: The `getUsersInOrganization` function in fdm-core/src/organization.ts needs to include user ID and email fields to support role updates and user removal operations, which will be fixed in a future commit (b17fac16c9e5a0de56d0346e712b2ce966d305d5).

Applied to files:

  • fdm-core/src/authorization.test.ts
  • fdm-core/src/principal.ts
📚 Learning: 2025-04-18T14:51:48.033Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/organization.ts:300-339
Timestamp: 2025-04-18T14:51:48.033Z
Learning: The `getUsersInOrganization` function in fdm-core/src/organization.ts currently returns only firstname, surname, image, and role, but needs to include id and email fields to support downstream operations like role updates and user removal. This will be fixed in commit b17fac16c9e5a0de56d0346e712b2ce966d305d5.

Applied to files:

  • fdm-core/src/authorization.test.ts
  • fdm-core/src/principal.ts
📚 Learning: 2025-04-18T14:51:48.033Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/organization.ts:300-339
Timestamp: 2025-04-18T14:51:48.033Z
Learning: The `getUsersInOrganization` function in fdm-core/src/organization.ts needed to include id and email fields for users, which was fixed in commit b17fac16c9e5a0de56d0346e712b2ce966d305d5.

Applied to files:

  • fdm-core/src/authorization.test.ts
  • fdm-core/src/principal.ts
📚 Learning: 2025-04-18T14:20:40.975Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/db/schema-authn.ts:70-76
Timestamp: 2025-04-18T14:20:40.975Z
Learning: The schema defined in fdm-core/src/db/schema-authn.ts follows better-auth's structure and requirements. While the schema is defined in the application code, modifications to it should maintain compatibility with better-auth's expectations.

Applied to files:

  • fdm-core/src/authorization.test.ts
📚 Learning: 2025-04-18T14:20:40.975Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 124
File: fdm-core/src/db/schema-authn.ts:70-76
Timestamp: 2025-04-18T14:20:40.975Z
Learning: The organization schema in fdm-core/src/db/schema-authn.ts is managed by better-auth, and modifications to field constraints (like making the slug field non-nullable) should maintain compatibility with better-auth's expectations, even if application code assumes non-null values.

Applied to files:

  • fdm-core/src/authorization.test.ts
📚 Learning: 2025-02-14T09:56:37.606Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 75
File: fdm-app/app/routes/farm.$b_id_farm.field.$b_id.fertilizer.tsx:68-71
Timestamp: 2025-02-14T09:56:37.606Z
Learning: The `calculateDose` function in `svenvw/fdm-calculator` is a synchronous function that includes built-in validation for negative application amounts and nutrient rates.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.test.ts
  • fdm-calculator/src/doses/calculate-dose.ts
  • fdm-calculator/src/doses/get-dose-field.ts
📚 Learning: 2025-01-23T15:17:23.027Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:208-208
Timestamp: 2025-01-23T15:17:23.027Z
Learning: The `addField` function in fdm-core should verify field creation within the same transaction by checking the existence of the field and all its required relations (field data, acquiring info, geometry) before resolving its promise.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.test.ts
  • fdm-core/src/field.ts
📚 Learning: 2024-12-11T12:09:35.540Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 20
File: fdm-app/tsconfig.json:8-9
Timestamp: 2024-12-11T12:09:35.540Z
Learning: In the `fdm-app/tsconfig.json` file, the include path `.react-router/types/**/*` refers to a build-time generated directory which is intentionally not included in the repository.

Applied to files:

  • fdm-data/tsconfig.build.json
  • fdm-calculator/tsconfig.build.json
  • fdm-core/tsconfig.build.json
  • fdm-core/package.json
  • fdm-data/package.json
  • fdm-core/rollup.config.js
  • fdm-app/vite.config.ts
📚 Learning: 2025-09-24T14:02:48.574Z
Learnt from: BoraIneviNMI
Repo: SvenVw/fdm PR: 272
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.fertilizer.manage.new.$p_id.tsx:85-101
Timestamp: 2025-09-24T14:02:48.574Z
Learning: Both getFertilizer and getFertilizers functions in svenvw/fdm-core perform authorization checks using the user's principal_id to verify farm access before returning fertilizer data.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.ts
  • fdm-calculator/src/balance/organic-matter/input.ts
📚 Learning: 2025-09-24T14:02:48.574Z
Learnt from: BoraIneviNMI
Repo: SvenVw/fdm PR: 272
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.field.$b_id.fertilizer.manage.new.$p_id.tsx:85-101
Timestamp: 2025-09-24T14:02:48.574Z
Learning: The getFertilizer function in svenvw/fdm-core does not perform authorization checks, unlike getFertilizers which includes a checkPermission call to verify farm access. This means getFertilizer(fdm, p_id) can potentially return fertilizer details for any fertilizer ID without validating user permissions.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.ts
  • fdm-calculator/src/balance/organic-matter/input.ts
📚 Learning: 2025-09-23T12:37:58.711Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 274
File: fdm-app/app/routes/farm.$b_id_farm.$calendar.field._index.tsx:113-148
Timestamp: 2025-09-23T12:37:58.711Z
Learning: In the FDM application, the current field data fetching implementation using Promise.all with individual API calls (getCultivations, getFertilizerApplications, getCurrentSoilData) performs acceptably even with farms containing 90+ fields. No performance issues have been observed in practice with this approach.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.ts
  • fdm-calculator/src/balance/organic-matter/index.ts
  • fdm-calculator/src/balance/organic-matter/input.ts
  • fdm-core/src/field.ts
📚 Learning: 2025-09-23T12:29:34.184Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 274
File: fdm-app/app/routes/farm.$b_id_farm._index.tsx:160-163
Timestamp: 2025-09-23T12:29:34.184Z
Learning: In the FDM application, the fertilizer application route intentionally uses `${calendar}/field/fertilizer` instead of the originally planned `/farm/{farmId}/add/fertilizer` structure. This design decision prioritizes starting from the field list view to provide better field selection workflow before applying fertilizer, rather than direct dashboard-to-action navigation.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.ts
📚 Learning: 2025-03-04T10:56:35.540Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 88
File: fdm-calculator/src/doses/calculate-dose.ts:18-18
Timestamp: 2025-03-04T10:56:35.540Z
Learning: In the FDM calculator, fertilizer nutrient rates (p_n_rt, p_p_rt, p_k_rt) are measured in g/kg, and are converted to fractions by dividing by 10 during dose calculations.

Applied to files:

  • fdm-calculator/src/doses/get-dose-field.ts
📚 Learning: 2025-05-28T07:57:19.217Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 147
File: fdm-docs/package.json:39-39
Timestamp: 2025-05-28T07:57:19.217Z
Learning: In pnpm workspaces, the syntax `"typescript": "catalog:"` is valid and correct. It references the version defined in the workspace's catalog section in pnpm-workspace.yaml, allowing consistent dependency versions across packages in a monorepo. The catalog: syntax without a package name is the shorthand for referencing the default catalog.

Applied to files:

  • pnpm-workspace.yaml
  • fdm-calculator/package.json
  • fdm-core/package.json
  • fdm-data/package.json
📚 Learning: 2025-05-28T07:57:19.217Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 147
File: fdm-docs/package.json:39-39
Timestamp: 2025-05-28T07:57:19.217Z
Learning: In pnpm workspaces, the syntax `"typescript": "catalog:"` is valid and correct. It references the version defined in the workspace's catalog section in pnpm-workspace.yaml, allowing consistent dependency versions across packages in a monorepo.

Applied to files:

  • pnpm-workspace.yaml
  • fdm-calculator/package.json
  • fdm-core/package.json
  • fdm-data/package.json
📚 Learning: 2025-01-24T11:46:49.990Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-data/rollup.config.js:7-17
Timestamp: 2025-01-24T11:46:49.990Z
Learning: When suggesting external dependencies in Rollup configuration, only include packages that are actually listed in the package's dependencies or peerDependencies.

Applied to files:

  • pnpm-workspace.yaml
  • fdm-calculator/package.json
  • fdm-data/rollup.config.js
  • fdm-core/package.json
  • fdm-data/package.json
  • fdm-core/rollup.config.js
  • fdm-calculator/rollup.config.js
📚 Learning: 2025-03-04T09:03:04.358Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 87
File: fdm-core/src/farm.ts:22-25
Timestamp: 2025-03-04T09:03:04.358Z
Learning: In the FDM codebase, functions that insert/create data (like `addFarm`) intentionally use `principal_id: string` instead of `PrincipalId` to enforce that only a single principal ID can be used for creation operations, while read operations use the more flexible `PrincipalId` type which supports both single IDs and arrays of IDs.

Applied to files:

  • fdm-core/src/principal.ts
📚 Learning: 2024-11-27T12:15:36.425Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 9
File: fdm-data/src/cultivations/index.test.ts:57-59
Timestamp: 2024-11-27T12:15:36.425Z
Learning: In `fdm-data/src/cultivations/index.test.ts`, the `fdm` object created by `drizzle` does not have an `.end()` method. Cleanup code should not attempt to call `fdm.end();`.

Applied to files:

  • fdm-calculator/src/balance/organic-matter/supply/cultivation.ts
  • fdm-calculator/src/balance/organic-matter/degradation.ts
📚 Learning: 2025-01-31T15:34:20.850Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:34:20.850Z
Learning: The `updateField` function in fdm-core has optional parameters that don't need to be passed as undefined. Only `fdm` and `b_id` are required.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-01-23T15:17:23.028Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-app/app/routes/farm.create.$b_id_farm.atlas.tsx:208-208
Timestamp: 2025-01-23T15:17:23.028Z
Learning: The `addField` function in fdm-core should use database transactions and field verification to ensure field availability before resolving its promise, eliminating the need for sleep workarounds.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2024-11-25T14:42:26.660Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 6
File: fdm-app/app/components/blocks/field-map.tsx:0-0
Timestamp: 2024-11-25T14:42:26.660Z
Learning: In `fdm-app/app/components/blocks/field-map.tsx`, explicit cleanup of Mapbox GL resources is not necessary, as `react-map-gl` handles it automatically upon component unmount, and `MapRef` does not have a `remove` method.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-01-31T15:05:14.310Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: When using `updateField` from fdm-core, all 8 parameters must be provided in order: fdm, b_id, b_name, b_geometry, b_area, b_id_source, b_id_farm, and b_id_farm_source.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-01-31T15:05:14.310Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 67
File: fdm-app/app/routes/farm.create.$b_id_farm.fields.$b_id.tsx:601-610
Timestamp: 2025-01-31T15:05:14.310Z
Learning: The `updateField` function in fdm-core requires 8 parameters: fdm, b_id (required), and 6 optional parameters (b_name, b_id_source, b_geometry, b_acquiring_date, b_acquiring_method, b_discarding_date).

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2024-11-27T11:27:27.797Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 9
File: fdm-data/src/cultivations/index.test.ts:57-59
Timestamp: 2024-11-27T11:27:27.797Z
Learning: When cleaning up test data in `afterAll` hooks in `fdm-data/src/cultivations/index.test.ts`, use `fdm.delete(schema.tableName).execute();` to delete rows from a table without dropping the table itself.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-02-13T08:28:00.183Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 71
File: fdm-core/src/cultivation.ts:572-597
Timestamp: 2025-02-13T08:28:00.183Z
Learning: In the FDM database schema, `b_id_harvesting` is a primary key in the `cultivationHarvesting` table, ensuring no duplicate harvest entries can exist. Therefore, duplicate checking is not needed when processing harvest records from database queries.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-01-23T15:18:57.212Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-core/src/db/schema.ts:407-426
Timestamp: 2025-01-23T15:18:57.212Z
Learning: In the farm data model, each cultivation (b_lu) can have only one termination date but can have multiple harvest dates. This is enforced through the database schema where cultivationTerminating uses b_lu as primary key while cultivationHarvesting uses a composite primary key of b_id_harvestable and b_lu.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-02-13T09:03:11.890Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 71
File: fdm-app/app/routes/farm.create.$b_id_farm.cultivations.$b_lu_catalogue.crop.harvest._index.tsx:111-135
Timestamp: 2025-02-13T09:03:11.890Z
Learning: When adding multiple harvests in fdm-app, use Promise.all instead of Promise.allSettled to ensure atomic behavior - if one harvest addition fails, all should fail and rollback to maintain data consistency.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-01-24T11:39:57.805Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-core/src/cultivation.ts:625-671
Timestamp: 2025-01-24T11:39:57.805Z
Learning: Every cultivation has an associated `cultivationTerminating` record created by `addCultivation`, with `b_terminate_date` initially set to null. Therefore, `updateCultivation` can safely assume the record exists and only needs to handle updates.

Applied to files:

  • fdm-core/src/field.ts
📚 Learning: 2025-02-19T10:50:50.200Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 82
File: fdm-app/app/entry.client.tsx:13-13
Timestamp: 2025-02-19T10:50:50.200Z
Learning: Sentry DSN being public in client-side code is not a security concern as per Sentry documentation, but it can be made configurable using Vite's environment variables system with the `VITE_` prefix.

Applied to files:

  • fdm-app/vite.config.ts
📚 Learning: 2024-12-16T10:56:07.561Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 16
File: fdm-app/app/routes/app.addfarm.$b_id_farm.cultivations.$b_lu_catalogue.fertilizers.tsx:1-1
Timestamp: 2024-12-16T10:56:07.561Z
Learning: The project uses `react-router` v7, and the `data` function is exported and used for error handling in loaders and actions.

Applied to files:

  • fdm-app/vite.config.ts
🧬 Code graph analysis (8)
fdm-core/src/authorization.test.ts (1)
fdm-core/src/authorization.ts (1)
  • roles (29-29)
fdm-calculator/src/doses/get-dose-field.ts (1)
fdm-calculator/src/doses/calculate-dose.ts (1)
  • calculateDose (37-142)
fdm-calculator/src/balance/organic-matter/index.ts (1)
fdm-calculator/src/balance/organic-matter/types.ts (2)
  • FertilizerDetail (235-240)
  • CultivationDetail (224-230)
fdm-core/src/field.ts (1)
fdm-core/src/db/schema.ts (1)
  • cultivations (373-385)
fdm-calculator/src/balance/organic-matter/degradation.ts (1)
fdm-core/src/db/schema.ts (1)
  • cultivations (373-385)
fdm-data/rollup.config.js (2)
fdm-core/rollup.config.js (2)
  • isProd (7-7)
  • external (15-15)
fdm-calculator/rollup.config.js (2)
  • isProd (6-6)
  • external (8-11)
fdm-app/vite.config.ts (3)
fdm-core/rollup.config.js (1)
  • isProd (7-7)
fdm-calculator/rollup.config.js (1)
  • isProd (6-6)
fdm-data/rollup.config.js (1)
  • isProd (7-7)
fdm-calculator/rollup.config.js (2)
fdm-core/rollup.config.js (2)
  • isProd (7-7)
  • external (15-15)
fdm-data/rollup.config.js (2)
  • isProd (7-7)
  • external (9-12)
🔇 Additional comments (30)
.changeset/jolly-eagles-clean.md (2)

1-5: Valid changeset format with appropriate version bump level.

The YAML frontmatter correctly declares patch-level version bumps across the three affected packages. This is appropriate for bug fixes (dependency bundling) and performance improvements.


7-11: Changeset description aligns well with PR objectives.

The bullet points clearly summarize the build optimization work: fixing unintended dependency bundling, skipping minification in dev builds, and standardizing source maps.

However, verify whether fdm-app should be included in this changeset. The AI summary indicates that fdm-app also receives build optimizations (Vite config simplification, Sentry logic changes). If fdm-app is a user-facing or dependency package, it may warrant its own patch entry to inform consumers of changes.

fdm-calculator/tsconfig.build.json (1)

1-9: Well-structured build configuration.

This new build-specific TypeScript configuration appropriately extends the base tsconfig and excludes test-related files from the build scope. The pattern aligns with the PR's build optimization objective and follows standard TypeScript configuration best practices for isolating production builds.

fdm-calculator/src/balance/organic-matter/degradation.ts (1)

7-7: LGTM! Import path standardization and type clarity improvements.

The changes improve code quality:

  • Import path updated to follow TypeScript conventions (removing .d extension)
  • Explicit type annotation on the callback parameter makes the code more self-documenting

These align with the broader PR effort to standardize type imports across the organic-matter module.

Also applies to: 43-43

fdm-calculator/src/balance/shared/soil.ts (1)

9-9: LGTM! Import path standardization.

The import path update aligns with TypeScript conventions and is consistent with similar changes across the organic-matter module.

fdm-calculator/src/balance/organic-matter/input.ts (1)

16-16: LGTM! Import path standardization.

The type import path update follows TypeScript conventions and aligns with the broader refactoring across the organic-matter module.

fdm-calculator/src/balance/organic-matter/supply/cultivation.ts (1)

6-6: LGTM! Import path standardization.

The import path update removes the .d extension and simplifies the path structure, aligning with TypeScript conventions and the broader module refactoring.

fdm-calculator/src/balance/organic-matter/supply/index.ts (1)

7-7: LGTM! Import path standardization.

The type import path update is consistent with the standardization effort across the organic-matter module.

fdm-calculator/src/balance/organic-matter/supply/fertilizers.ts (1)

6-6: LGTM! Import standardization and enhanced type safety.

The changes improve code quality:

  • Import path updated to follow TypeScript conventions
  • Explicit type annotations in the reduce callback enhance type safety and make the code more maintainable

These align with the broader refactoring to standardize types across the organic-matter module.

Also applies to: 37-37

fdm-calculator/src/balance/organic-matter/supply/residues.ts (1)

7-7: LGTM! Import path standardization.

The type import path update is consistent with the standardization effort across the organic-matter module.

fdm-calculator/src/balance/organic-matter/index.ts (1)

18-18: LGTM! Comprehensive type safety improvements.

The changes significantly enhance type clarity:

  • Import path standardized to follow TypeScript conventions
  • Explicit generic type parameters on Map declarations improve type inference
  • Typed callbacks in map functions make the code more maintainable and self-documenting

These changes are part of the broader effort to strengthen type safety across the organic-matter balance module.

Also applies to: 42-46

fdm-app/vite.config.ts (1)

37-42: optimizeDeps.exclude aligns dev pre-bundling with your library build outputs

Excluding @svenvw/fdm-core, @svenvw/fdm-data, and @svenvw/fdm-calculator from Vite’s dependency optimization is a good fit for a monorepo where those are built separately with Rollup. This should reduce duplicate bundling work and avoid dev-server issues if those packages ship modern ESM.

No changes needed from my side here.

If you hit any dev-only issues after this (e.g., missing dependency pre-bundle warnings), it’d be worth confirming the published formats/entrypoints of these three packages match what Vite expects in your current version.

.changeset/thin-baths-care.md (1)

1-10: Changeset accurately summarizes the Vite/Sentry tweaks

The patch description matches the actual vite.config.ts changes (simplified Sentry wiring, no manual chunks, no global polyfill) and is scoped correctly as a patch for @svenvw/fdm-app. Looks good to commit.

fdm-core/src/db/schema-custom-types.ts (2)

110-116: SRID value reading was intentionally removed and poses no risk to the codebase.

The search reveals that the commented-out SRID reading was never actually used anywhere. The codebase hardcodes SRID 4326 in the geometry schema definition (line 43 of the same file: geometry(${type},4326)), and coordinate system conversions use EPSG:4326 as a fixed target projection. The SRID value from binary data was being read but never stored or referenced by any downstream code. The offset handling and flag clearing remain correct, so the change is safe and represents legitimate cleanup of dead code.


32-32: Now I have all the information needed. Let me finalize the verification:

The geometry function is not exported in the public API. It's only defined in schema-custom-types.ts and used internally in schema.ts. The public API exports fdmSchema which contains the table definitions, but not the geometry function itself. Since consumers cannot directly call the geometry function with different type parameters, this type narrowing is an internal implementation detail, not a breaking change to the public API.

All internal uses of geometry() in the codebase (found in schema.ts at lines 97 and 781) only use "Polygon" and "MultiPoint" types, which are now the only supported types after the change. The implementation in parseGeometry also only handles these two types.


fdm-core/src/authorization.test.ts (1)

780-782: LGTM! Order-independent assertion improves test robustness.

The updated assertion correctly verifies that both roles are present without enforcing a specific order, which is appropriate since the function queries the database and order may not be deterministic.

fdm-core/tsconfig.build.json (1)

1-10: LGTM! Clean build-time configuration.

The build-specific TypeScript config appropriately excludes test files and utilities from production builds, following the standard pattern established across the monorepo.

fdm-calculator/src/balance/nitrogen/index.ts (1)

23-23: LGTM! Import reordering.

The import statement has been relocated but remains functionally identical.

fdm-core/src/soil.ts (1)

547-547: LGTM! Explicit type annotation improves clarity.

The Record<string, any> annotation appropriately reflects the dynamic property access pattern used in this predicate.

fdm-calculator/rollup.config.js (2)

3-29: LGTM! Clean migration to esbuild-based build pipeline.

The configuration updates align well with the parallel changes in fdm-core and fdm-data, establishing a consistent build approach across packages. The switch to esbuild provides faster transpilation, and preserveModules maintains a clean module structure in the output.

Also applies to: 57-57


36-39: The placeholder replacement mechanism is correctly implemented and will work as intended.

The implementation is sound:

  1. Placeholder location verified: The placeholder "fdm-calculator:{FDM_CALCULATOR_VERSION}" exists in fdm-calculator/src/package.ts (line 2), which is part of the module tree and will be included in the build.

  2. Version replacement works correctly: The renderChunk plugin (lines 31-55) searches for the placeholder in all output chunks, replaces it with the actual version from package.json (line 4), and pads the replacement to match the placeholder length to preserve source maps (line 50).

  3. Graceful handling with preserveModules: Returning null when the placeholder is not found (line 38) is the correct behavior—only the chunk containing the placeholder will be modified, while all other chunks remain untouched.

  4. Edge case handling: The code includes a warning (lines 41-45) if the replacement string would exceed the placeholder length, protecting source map integrity.

No issues found. The version replacement will correctly apply to the intended entry file through its exports.

pnpm-workspace.yaml (1)

14-14: LGTM! Workspace catalog aligned with esbuild migration.

The updates appropriately introduce rollup-plugin-esbuild to support the new build pipeline and bring vitest tooling to the latest patch versions.

Also applies to: 19-19, 26-26

fdm-data/tsconfig.build.json (1)

1-9: LGTM! Build configuration mirrors fdm-core pattern.

The build-specific TypeScript config appropriately excludes test files and utilities from production builds, consistent with the approach in fdm-core.

fdm-calculator/package.json (1)

15-16: LGTM! Package configuration aligned with new build output.

The entry point updates (main, module, exports) correctly reflect the new dist/index.js output from the preserveModules build strategy, and the extended build script ensures TypeScript declarations are generated using the build-specific configuration.

Also applies to: 22-22, 34-34, 56-56

fdm-core/package.json (1)

19-21: Entry points and build pipeline look consistent with Rollup config; double‑check tsconfig.build emit mode

Pointing main, module, and the export’s default to ./dist/index.js matches the Rollup output (input: "src/index.ts", preserveModules: true, entryFileNames: "[name].js"). The build script then runs rollup -c && tsc -p tsconfig.build.json; just ensure tsconfig.build.json is configured to emit only declarations (or at least not overwrite dist/index.js) so Rollup remains the source of truth for JS.

Also applies to: 26-26, 39-39, 58-58

fdm-data/package.json (1)

19-20: fdm-data package.json is aligned with the new Rollup/esbuild pipeline; verify TS build only emits d.ts

The main/module/exports default now all target ./dist/index.js, which lines up with the new Rollup config (src/index.ts + preserveModules). The build script mirrors fdm-core; as there too, confirm that tsconfig.build.json is set up (e.g. emitDeclarationOnly) so TypeScript only contributes .d.ts files into dist and doesn’t overwrite the Rollup-generated JS bundle.

Also applies to: 26-26, 37-37, 52-52

fdm-calculator/src/doses/get-dose-field.test.ts (2)

128-148: LGTM! Test expectations align with the simplified API.

The test expectations correctly reflect the new return type from getDoseForField, which now returns a flat Dose object instead of a nested structure.


181-201: LGTM! Consistent test update for the zero-dose case.

The test expectations are correctly updated to match the simplified return type.

fdm-calculator/src/doses/get-dose-field.ts (2)

54-54: LGTM! Proper error type casting.

The error casting to Error type is the correct approach for TypeScript error handling, ensuring type-safe access to the message property.


50-51: Based on my verification, I can now generate the rewritten review comment.

No production callers found for the simplified return type change.

Verification shows that getDoseForField is a newly added function (per CHANGELOG: "Add calculateDose and getDoseForField to retrieve the nutrient doses") with no production code callers in the monorepo. The only callers are in the test file, which correctly expect and validate the simplified return type (only Dose object, not {dose, applications}). The function is exported as public API but is not used elsewhere in the codebase.

@SvenVw SvenVw requested a review from BoraIneviNMI November 26, 2025 15:51
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
fdm-calculator/rollup.config.js (1)

4-4: Verify Node.js version compatibility with import assertions.

The with { type: "json" } syntax requires Node.js ≥20.10. This is the same concern as flagged in fdm-data/rollup.config.js.

🧹 Nitpick comments (1)
fdm-calculator/src/doses/d.ts (1)

40-42: Consider tightening the index signature for better type safety.

The index signature [key: string]: string | number | undefined allows assigning undefined to properties that DoseProperties declares as required numbers (e.g., p_dose_n). While TypeScript permits this, it weakens type guarantees and may lead to runtime issues if consumers assume dose values are always present.

If dynamic property access is needed for iteration (as suggested by the NumericDoseKeys usage in calculate-dose.ts), consider alternatives:

  • Use Record<string, unknown> with type guards for dynamic keys
  • Or restrict the index signature to exclude DoseProperties keys: [key: string]: unknown with a more specific type helper

Example refinement:

 export interface Dose extends DoseProperties {
-    [key: string]: string | number | undefined
+    [key: string]: unknown
 }

Then use type assertions or guards when accessing dynamic properties.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4859b64 and 4cea472.

📒 Files selected for processing (6)
  • fdm-calculator/rollup.config.js (1 hunks)
  • fdm-calculator/src/doses/calculate-dose.ts (2 hunks)
  • fdm-calculator/src/doses/d.ts (2 hunks)
  • fdm-core/rollup.config.js (2 hunks)
  • fdm-core/src/field.ts (4 hunks)
  • fdm-data/rollup.config.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • fdm-core/src/field.ts
  • fdm-calculator/src/doses/calculate-dose.ts
  • fdm-core/rollup.config.js
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 6
File: fdm-app/vite.config.ts:5-9
Timestamp: 2024-11-25T12:42:32.783Z
Learning: In the `fdm-app` project, SvenVw is preparing for migration to Remix v3 and may include type declarations or configurations for v3 features in advance, such as in `vite.config.ts`.
📚 Learning: 2025-01-24T11:46:49.990Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 49
File: fdm-data/rollup.config.js:7-17
Timestamp: 2025-01-24T11:46:49.990Z
Learning: When suggesting external dependencies in Rollup configuration, only include packages that are actually listed in the package's dependencies or peerDependencies.

Applied to files:

  • fdm-calculator/rollup.config.js
  • fdm-data/rollup.config.js
📚 Learning: 2025-08-13T10:33:05.313Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 0
File: :0-0
Timestamp: 2025-08-13T10:33:05.313Z
Learning: In the fdm project, fdm-calculator integration for new features like b_lu_variety is handled in separate updates from the core data model changes. When fdm-core functions are updated to support new fields, fdm-calculator can consume these enhanced APIs without requiring changes in the same PR that introduces the core functionality.

Applied to files:

  • fdm-calculator/rollup.config.js
📚 Learning: 2024-11-25T12:42:32.783Z
Learnt from: SvenVw
Repo: SvenVw/fdm PR: 6
File: fdm-app/vite.config.ts:5-9
Timestamp: 2024-11-25T12:42:32.783Z
Learning: In the `fdm-app` project, SvenVw is preparing for migration to Remix v3 and may include type declarations or configurations for v3 features in advance, such as in `vite.config.ts`.

Applied to files:

  • fdm-calculator/rollup.config.js
  • fdm-data/rollup.config.js
🧬 Code graph analysis (1)
fdm-data/rollup.config.js (1)
fdm-calculator/rollup.config.js (2)
  • isProd (6-6)
  • external (8-11)
🔇 Additional comments (5)
fdm-calculator/src/doses/d.ts (2)

21-38: LGTM! Well-structured dose properties interface.

The DoseProperties interface is clearly documented and logically organized. Making p_app_id optional while keeping dose values as required numbers is appropriate for the domain.


44-44: NumericDoseKeys type definition is correct and properly integrated.

The type correctly excludes p_app_id (the only string-type property in DoseProperties) while retaining all 16 numeric dose properties (p_dose_n, p_dose_nw, p_dose_p, etc.). The usage in calculate-dose.ts (line 131) is type-safe: Object.keys(totalDose) as NumericDoseKeys[] properly constrains iteration to numeric properties only. No type safety issues found.

fdm-data/rollup.config.js (1)

14-33: LGTM! Clean migration to esbuild with appropriate library bundling.

The configuration successfully migrates from TypeScript + Terser to esbuild while:

  • Using preserveModules for library-friendly output structure
  • Dynamically computing externals from package.json (per established patterns)
  • Optimizing sourcemaps by environment (inline for dev, separate for prod)
  • Targeting Node 20 for modern JavaScript features
fdm-calculator/rollup.config.js (2)

13-28: LGTM! Consistent migration pattern with fdm-data.

The base configuration mirrors the clean esbuild migration in fdm-data, maintaining consistency across the monorepo packages.


30-54: Placeholder replacement logic handles preserveModules correctly.

The containment check and null return (line 35-37) appropriately handle the common case where most modules won't contain the version placeholder. The length validation and padding preserve sourcemap accuracy.

Comment thread fdm-data/rollup.config.js
@SvenVw SvenVw merged commit c02b53d into development Nov 26, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch:development Issue only affecting development, not the main branch (yet) dependencies Pull requests that update a dependency file enhancement New feature or request fdm-app fdm-calculator fdm-core fdm-data

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants