refactor(page): ES modules in src/page/, bundled with ECharts by esbuild into one page #11

Open
dawid wants to merge 3 commits from refactor-page-modules into main
Owner

The page was one index.html of 1,491 lines. Its sources are now ES modules in src/page/, built into one self-contained page.

Build

  • scripts/build_page.mjs (npm run build): esbuild bundles the modules from main.js with the parts of ECharts they import (tree-shaken: the seven chart types and four components the views use) and inlines the bundle and style.css into index.html at its build markers.
  • One file: a browser cannot pair a cached script with a newer page after an MKP update.
  • build-mkp builds the page first. The MKP ships index.html and the three license files; echarts.min.js is gone. The web part shrinks from 1.19 MB to 663 KiB.
  • Reproducible: identical sources give a byte-identical page and MKP.

Modules (the README has the table)
config.js (the parameters, checked first), states.js, tree.js, changes.js (no browser globals), api.js, load.js, ui.js (the shared state), chart.js, paint.js, tips.js, arcs.js, views/*.js (one per view), render.js, legend.js, list.js, main.js.

Unchanged behavior

  • 59 of the 67 functions are identical to the old page's. The other 8 differ only where modules need it: the shared state in ui.*, the legend's select/fade passed in, depth an argument of sankeyGraph/sankeyColumns, and an optional now on the change tracking.
  • window.biCharts.items() and the query parameters are the same. All 86 unit tests, including every browser test, pass against the built page (run locally in a container).

Tests and CI

  • tests/js/tree.test.js (npm test, 13 tests): the BI trees, problems only, the flow graph (hosts as its leaves, a shared host as one node), impact, the state order. The unit job runs it.
  • The stub serves the built page; a session fixture builds it. test_package.py checks that the page is self-contained.
  • test_checkmk.py checks the inline script and the licenses served beside the page.
  • tools/screenshots.py builds the page first.

refactor:, so the release bot makes this a patch release. The integration tests are left to this PR's CI.

🤖 Generated with Claude Code

The page was one `index.html` of 1,491 lines. Its sources are now ES modules in `src/page/`, built into one self-contained page. **Build** - `scripts/build_page.mjs` (`npm run build`): esbuild bundles the modules from `main.js` with the parts of ECharts they import (tree-shaken: the seven chart types and four components the views use) and inlines the bundle and `style.css` into `index.html` at its build markers. - One file: a browser cannot pair a cached script with a newer page after an MKP update. - `build-mkp` builds the page first. The MKP ships `index.html` and the three license files; `echarts.min.js` is gone. The web part shrinks from 1.19 MB to 663 KiB. - Reproducible: identical sources give a byte-identical page and MKP. **Modules** (the README has the table) `config.js` (the parameters, checked first), `states.js`, `tree.js`, `changes.js` (no browser globals), `api.js`, `load.js`, `ui.js` (the shared state), `chart.js`, `paint.js`, `tips.js`, `arcs.js`, `views/*.js` (one per view), `render.js`, `legend.js`, `list.js`, `main.js`. **Unchanged behavior** - 59 of the 67 functions are identical to the old page's. The other 8 differ only where modules need it: the shared state in `ui.*`, the legend's `select`/`fade` passed in, `depth` an argument of `sankeyGraph`/`sankeyColumns`, and an optional `now` on the change tracking. - `window.biCharts.items()` and the query parameters are the same. All 86 unit tests, including every browser test, pass against the built page (run locally in a container). **Tests and CI** - `tests/js/tree.test.js` (`npm test`, 13 tests): the BI trees, problems only, the flow graph (hosts as its leaves, a shared host as one node), impact, the state order. The unit job runs it. - The stub serves the built page; a session fixture builds it. `test_package.py` checks that the page is self-contained. - `test_checkmk.py` checks the inline script and the licenses served beside the page. - `tools/screenshots.py` builds the page first. `refactor:`, so the release bot makes this a patch release. The integration tests are left to this PR's CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
refactor(page): ES modules in src/page/, bundled with ECharts by esbuild into one page
Some checks failed
CI / unit (pull_request) Has been cancelled
CI / integration (Checkmk 2.4) (pull_request) Has been cancelled
CI / integration (Checkmk 2.5) (pull_request) Has been cancelled
CI / integration (update 2.4 to 2.5) (pull_request) Has been cancelled
CI / release (pull_request) Has been cancelled
e459f2a7cb
The page was one file of 1,491 lines. Its sources are now ES modules under
src/page/: the query parameters, the states and the BI trees, the requests,
the chart's shared parts, one module per view, the legend and the list, and
main.js. scripts/build_page.mjs bundles them with the parts of ECharts they
import (esbuild, tree-shaken) and inlines the bundle and style.css into
index.html: one file, which a browser cannot have cached apart from its
script after an update. build-mkp builds the page first; the MKP ships it
with the licenses beside it, no longer echarts.min.js (1.19 MB before,
663 KiB now). Identical sources still give a byte-identical page and MKP.

The functions are unchanged but for what modules need: the shared state in
one object (ui.js), the legend's select and fade passed in, and depth an
argument of the flow graph, so that tree.js, states.js and changes.js use no
browser globals. tests/js tests those in Node.js (npm test, in CI's unit
job); the browser and integration tests run against the built page.
docs: the README's tables aligned
Some checks failed
CI / unit (pull_request) Successful in 1m52s
CI / integration (Checkmk 2.4) (pull_request) Successful in 5m2s
CI / integration (Checkmk 2.5) (pull_request) Successful in 5m1s
CI / integration (update 2.4 to 2.5) (pull_request) Has been cancelled
CI / release (pull_request) Has been cancelled
a35e2738af

Tests of CI / unit: passed

99 passed, 0 failed, 0 skipped (99 tests, 58.1 s)

Of 44d8e56172, the run, updated by every run.

<!-- ci-report tests: CI-unit --> ### Tests of CI / unit: passed **99 passed, 0 failed, 0 skipped** (99 tests, 58.1 s) <sub>Of 44d8e56172, [the run](https://git.ciepiela.org/dawid/checkmk-bi-charts/actions/runs/33), updated by every run.</sub>

Tests of CI / integration (Checkmk 2.4): passed

18 passed, 0 failed, 0 skipped (18 tests, 245.4 s)

Of 44d8e56172, the run, updated by every run.

<!-- ci-report tests: CI-integration-Checkmk-2.4- --> ### Tests of CI / integration (Checkmk 2.4): passed **18 passed, 0 failed, 0 skipped** (18 tests, 245.4 s) <sub>Of 44d8e56172, [the run](https://git.ciepiela.org/dawid/checkmk-bi-charts/actions/runs/33), updated by every run.</sub>

Tests of CI / integration (Checkmk 2.5): passed

18 passed, 0 failed, 0 skipped (18 tests, 244.9 s)

Of a35e2738af, the run, updated by every run.

<!-- ci-report tests: CI-integration-Checkmk-2.5- --> ### Tests of CI / integration (Checkmk 2.5): passed **18 passed, 0 failed, 0 skipped** (18 tests, 244.9 s) <sub>Of a35e2738af, [the run](https://git.ciepiela.org/dawid/checkmk-bi-charts/actions/runs/32), updated by every run.</sub>
ci: the page's module tests in the test report, as JUnit
Some checks are pending
CI / release (pull_request) Blocked by required conditions
CI / unit (pull_request) Successful in 1m52s
CI / integration (update 2.4 to 2.5) (pull_request) Waiting to run
CI / integration (Checkmk 2.4) (pull_request) Successful in 5m0s
CI / integration (Checkmk 2.5) (pull_request) Has started running
44d8e56172
Some checks are pending
CI / release (pull_request) Blocked by required conditions
CI / unit (pull_request) Successful in 1m52s
CI / integration (update 2.4 to 2.5) (pull_request) Waiting to run
CI / integration (Checkmk 2.4) (pull_request) Successful in 5m0s
CI / integration (Checkmk 2.5) (pull_request) Has started running
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'refactor-page-modules:refactor-page-modules'
git switch 'refactor-page-modules'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'refactor-page-modules'
git switch 'refactor-page-modules'
git rebase 'main'
git switch 'main'
git merge --ff-only 'refactor-page-modules'
git switch 'refactor-page-modules'
git rebase 'main'
git switch 'main'
git merge --no-ff 'refactor-page-modules'
git switch 'main'
git merge --squash 'refactor-page-modules'
git switch 'main'
git merge --ff-only 'refactor-page-modules'
git switch 'main'
git merge 'refactor-page-modules'
git push origin 'main'
Sign in to join this conversation.
No description provided.