feat(frontend) :: upgrade to typescript - #1382
Conversation
|
there is a lot more optimisations and type safety we can do here but i tried to keep it 1:1 ish so that its easy to review |
lovasoa
left a comment
There was a problem hiding this comment.
This is useful, I do stand by the idea of getting rid of our custom dependency management system. But I think this PR tries to do too much at once to be actionable, and reviewable. I think a good first step would be to just change the build system. I also think we should try to make things as easy as possible for downstream packagers like homebrew and nix, helping them with the build system changes: at least make the changelog very explicit for them, and at best contributing directly to them.
oof, I had already broken up the changes to bar raise the build and CI. I also figured since most of my changes thus far were frontend only this would be a good place to start. Is there a reccomended path forward to raise the typescript changes? It's also totally okay if you want the project to stay on javascript to avoid this build step. We were already using typescript for the tests so I assumed it would be worth bringing it to the published code.
I 100% agree, although currently I can only show efforts of up streaming changes as I haven't touched the publish CI path locally yet. |
feat(frontend) :: upgrade to typescript
Motivation
build.rsreads.jsand.cssfiles for top level comments to create a custom installer for 3rd party deps./* !include https://cdn.jsdelivr.net/npm/@tabler/core@1.4.0/dist/js/tabler.min.js */This resulted in a few issues ::
cargo buildrequires a network to finish successfully. This also requires pulling in deps likeawc,rustls, andactix-rt.cargo build.sqlpage.jsto be a global.DOCS_RSwas set,build.rswould return early and ship broken assets.What changed
sqlpage/sqlpage.jsfrontend/src/sqlpage.tssqlpage/apexcharts.jsfrontend/src/apexcharts.ts+frontend/src/chart_series.tssqlpage/tomselect.jsfrontend/src/tomselect.tssqlpage/sqlpage.cssfrontend/src/sqlpage.csssqlpage/favicon.svgfrontend/src/favicon.svgsqlpage/globals.d.tsfrontend/types/globals.d.tssqlpage/tabler-icons.svgThe frontend is now built through
frontend/build.mjs, an esbuild script, which builds with proper attribution and outputs tofrontend/dist.build.rsnow only compresses and hashes the output files.Benefits
cargo buildno longer touches the network. npm handles installing frontend deps.docs.rs gets assets because
frontend/distships in the crate. Verified withcargo package --list.The browser code is type-checked as against published 3rd party types (eg ::
apexchartsandtom-select).Frontend can now be updated via
npm updaterather than manual comment updates. 3rd party packages are still pinned at the current versions.The served bundles are slightly smaller, because esbuild:
sqlpage.jsapexcharts.jssqlpage.csstomselect.jstomselect.jsgrew because we now bundle@orchidjs/sifterfrom source rather than taking tom-select's prebuilt file.Downsides & How to avoid them
npm ci && npm run buildbefore runningcargo build. There is no easy path to hot reload the entire app.frontend/distfolder but then we would run the risk of committing outdated files if folks don't build before committing.flake.nixfixes this and I would be happy to make a follow up PR to add one.build.mjssqlpage_table()or reached forwindow.tabler.Testing