Skip to content

build(srcts): Convert Flow to TypeScript and build with esbuild - #150

Merged
schloerke merged 7 commits into
mainfrom
schloerke/typescript-code-update
Oct 20, 2026
Merged

schloerke merged 7 commits into
mainfrom
schloerke/typescript-code-update

Conversation

@schloerke

@schloerke schloerke commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Converts the viewer from Flow-typed JavaScript to TypeScript and renames srcjs/ to srcts/ to match rstudio/shiny. The Flow syntax was edited in place, so git still sees renames and the diff stays small: casts became as, ?T became T | null | undefined, %checks became a type guard, Flow's Object became any, and LogStates is now as const so switch (entry.action) narrows. tsc runs with strict off here; rstudio/reactlog#154 turns it on. TypeScript is pinned to 6.0 because typescript-eslint (next PR) does not support 7.

Replaces grunt, webpack 4, Babel, Flow, flow-typed, and the polyfills with esbuild plus tsc, targeting es2021 like rstudio/shiny (which also uses no polyfills). bin/check_shiny_target.js and the new shiny-target.yaml workflow fail if our tsc or esbuild target drifts from shiny's; it runs on PRs that touch the build config and weekly. npm run build is now typecheck + build-only and builds in under 0.1s. The bundle drops from 679 KB to 574 KB, and the --openssl-legacy-provider workaround is gone. Linting is out of the build until the next PR, because eslint 5 and prettier 1 can't parse TypeScript, and the Flow-only babel-eslint, eslint-plugin-flowtype, and .eslintrc.js are removed here. The prev/next buttons now call their functions through an arrow, so jQuery's click event no longer ends up in the cytoscape layout options. Cytoscape event targets are typed as an element or the core, with an isCore() guard instead of as unknown casts.

Checked by loading the old and new bundles in a browser with the default log and running the same 13 actions (every nav button, arrow keys, Home/End, search). Tick, node and edge counts, the log entry text, and the timeline position all matched, and so did the screenshots. No console errors.

Rename srcjs/*.js to .ts and rewrite the Flow-only syntax: casts become
`as`, maybe types become `T | null | undefined`, %checks becomes a type
guard, and $Values / $ReadOnlyArray use TypeScript forms. tsc runs with
strict off for now.

Replace grunt, webpack 4, Babel, and Flow with esbuild plus `tsc`. This
drops the polyfills and the --openssl-legacy-provider workaround. Linting
is out of the build until eslint and prettier are updated.
@schloerke
schloerke added this pull request to stack #153 October 20, 2026 17:31
@schloerke schloerke changed the title schloerke/typescript code update build(srcts): Convert Flow to TypeScript and build with esbuild Oct 20, 2026
Use the same tsc and esbuild target as rstudio/shiny (es2021). The
viewer only runs inside Shiny apps, so it never needs an older target.

bin/check_shiny_target.js reads shiny's tsconfig.json and
srcts/build/_build.ts from GitHub and fails if either target differs
from ours. The new workflow runs it on PRs that touch the build
config and weekly, since shiny can change on its own.
The prev/next buttons were bound straight to the button functions, so
jQuery's click event arrived as `cytoOptions` and was merged into the
cytoscape layout options. Wrap each in an arrow function instead of
hiding it with `as any`.

Also type cytoscape event targets as an element or the core, with an
`isCore()` guard in place of three `as unknown` casts, and give
`hasLength()` an honest signature that always returns a boolean.
babel-eslint, eslint-plugin-flowtype, @babel/core, and .eslintrc.js
only served the Flow lint setup and cannot read TypeScript. The next
change in the stack adds the TypeScript lint setup.
@schloerke
schloerke merged commit 4e74027 into main Oct 20, 2026
13 checks passed
@schloerke
schloerke deleted the schloerke/typescript-code-update branch October 20, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant