… it (#9995)
* refactor(desktop): sanitize theme CSS only where the renderer applies it
The theme CSS sanitizer is a browser concern: it decides what may go
into the renderer's <style> element. It lived in packages/shared and
also ran at import, so the CLI loaded css-tree through
parseThemeConfigFile. css-tree's Node entry reads JSON with
createRequire, which bun build --compile does not embed, and the
compiled CLI crashed at start. #9992 worked around the bundling.
Import-time sanitizing protects nothing: app-state.json can be edited
by hand or written by any client (CLI, ui-state router), and the
renderer sanitizes on every apply. So:
- Move sanitizeThemeCss next to applyThemeCss in the desktop renderer,
and css-tree with it. Import plain css-tree again; the renderer
bundler resolves its browser build.
- parseThemeConfigFile keeps the length check and stores CSS as given.
MAX_THEME_CSS_LENGTH stays in shared as a plain constant.
- Remove the #9992 shim (css-tree-esm.d.ts and its triple-slash
reference) and the Bun.build test in shared.
- Add one CLI test that bundles every command and fails if css-tree
or mdn-data is in the inputs.
* refactor(cli-framework): share the build options with the CSS guard test
Export buildOptions (entry and plugins) from cli-framework and use it in
both runBuild and the CLI bundle test, so the test bundles exactly what
the compiled CLI bundles. Name the test for what it keeps out.
What and why
Main's Build CLI / Build linux-x64 smoke step has failed since #9970:
Cause. #9970 added
css-tree@3to@superset/sharedforsanitizeThemeCss. The CLI imports@superset/shared/themes, so the parser loads when the CLI starts. css-tree's ESM entry reads its syntax data at run time withcreateRequire(import.meta.url)(../data/patch.json,mdn-data/css/*.json).bun build --compiledoes not embed files loaded that way, so the compiled binary throws on start, also for--version. Browser bundles (the desktop renderer) were not affected: css-tree'sbrowsermap sendslib/data.jstodist/data.js, which has the data inlined. Bun withtarget: "bun"does not use that map. #9970 is a fork PR and had no CI run of its own, so main was the first Build CLI run with it.Fix. Import from
css-tree/dist/csstree.esm. This is css-tree's own self-contained ESM bundle (public./dist/*export), with the data inlined. A 3-line ambient declaration re-exports the@types/css-treetypes for that subpath. Same version, same API, no behaviour change. No revert of #9970.Regression test.
sanitizeThemeCss.test.tsbundles the sanitizer withBun.build({ target: "bun" })and runs the output (~20 ms). It fails with the samepatch.jsonerror on the old import.What breaks
Nothing. Released CLIs were not built from this main commit.
Not in this PR
The
cli-frameworktablehyperlink test failures in recent PR runs have a different cause: they fail when the runner setsTERM=dumb(the tests forceisTTYbut inheritTERM). #9664 fixes that. It applies cleanly to main and passes underTERM=dumb, so this PR does not duplicate it.How I verified
bun run build:dist --target=linux-x64, Bun 1.4.3) and ranpackages/cli/scripts/smoke-test.sh. On main it fails with the error above. On this branch it prints[smoke] all checks passed.packages/shared:bun testpasses (1762 pass, 0 fail).tsc --noEmitis clean for shared, cli and desktop. biome is clean.Evidence: https://app.superset.sh/page/mainfix-fix-compiled-cli-crash-on-css-tree-data-fi-2pnpef
Design: https://app.superset.sh/page/admin-cloud-workspace-cost-and-health-design-8z3d4d
Summary by cubic
Fixes the compiled CLI crashing on startup because
css-tree's ESM entry reads its syntax data at runtime, whichbun build --compiledoes not embed.sanitizeThemeCssnow importscss-tree/dist/csstree.esm, a self-contained bundle with the data inlined; no API or behavior change.sanitizeThemeCsswithBun.buildso the failure surfaces inbun test.Written for commit 8b37428. Summary will update on new commits.
Summary by CodeRabbit