Files
stack/infra/marimo/theme/scripts/apply-overlay.sh
kert cc6feca253
All checks were successful
CI / lint (push) Successful in 31s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Has been skipped
Deploy / mc (push) Has been skipped
Infra CI / notebooks (push) Successful in 11m22s
Infra CI / zotero (push) Successful in 29s
Infra CI / docs (push) Successful in 1m43s
Infra CI / api (push) Successful in 15s
Infra CI / mc (push) Successful in 18s
Deploy / report (push) Successful in 13s
CI / test (push) Successful in 19m25s
fix(notebooks): pin jotai 2.17.0 in marimo overlay to fix frontend build
The overlay mutates marimo's package.json, so the image builds with
`pnpm install --no-frozen-lockfile`. That let pnpm re-resolve jotai within
marimo's `^2.17.0` range up to 2.20.0+, which dropped the
INTERNAL_getBuildingBlocksRev2 / INTERNAL_buildStoreRev2 exports that
marimo's source imports — the frontend build then died with MISSING_EXPORT.

Pin jotai to the exact version via pnpm.overrides in apply-overlay.sh. The
jq transform creates the overrides (and pnpm) key when absent and preserves
any existing overrides.
2026-07-08 09:28:52 -04:00

118 lines
4.6 KiB
Bash
Executable File

#!/bin/sh
# Apply fhirworx overlay onto a vanilla marimo source tree.
# Idempotent: safe to run multiple times during iterative development.
#
# Invoked by the Dockerfile after `git clone`, before `pnpm install`.
# Run from the marimo source root (same dir as frontend/ and pyproject.toml).
set -eu
SRC="${1:?usage: apply-overlay.sh <marimo-source-root> <overlay-root>}"
OVR="${2:?}"
echo "== fhirworx overlay → $SRC"
# 1. Drop new files in place (lucide-shim, fhirworx.css, asset overrides).
cp -R "$OVR/frontend/." "$SRC/frontend/"
# 2. Add @tabler/icons-react to frontend dependencies via jq (idempotent).
# Pinned to a known-good major that matches our shim's export names.
jq '.dependencies["@tabler/icons-react"] = "^3.26.0"' \
"$SRC/frontend/package.json" > "$SRC/frontend/package.json.new"
mv "$SRC/frontend/package.json.new" "$SRC/frontend/package.json"
# 2b. Pin jotai to the exact version marimo's lockfile expects. We build with
# `pnpm install --no-frozen-lockfile` (the overlay mutates package.json),
# so pnpm otherwise re-resolves jotai within marimo's `^2.17.0` range up to
# 2.20.0+, which dropped the INTERNAL_getBuildingBlocksRev2 /
# INTERNAL_buildStoreRev2 exports marimo's source imports → the frontend
# build dies with MISSING_EXPORT. Add it to the existing pnpm.overrides.
jq '.pnpm.overrides.jotai = "2.17.0"' \
"$SRC/package.json" > "$SRC/package.json.new"
mv "$SRC/package.json.new" "$SRC/package.json"
# 3. Rewrite pnpm-lock if it exists so pnpm install doesn't error on drift.
rm -f "$SRC/frontend/pnpm-lock.yaml" "$SRC/pnpm-lock.yaml"
# 4. Inject our CSS import into globals.css.
# `@import` must precede all other statements (postcss/CSS spec), so
# append-at-EOF would get rejected with a warning + dropped. Instead,
# insert our @import right after the last existing top-level @import.
if ! grep -q 'fhirworx.css' "$SRC/frontend/src/css/globals.css"; then
python3 - "$SRC/frontend/src/css/globals.css" <<'PY'
import sys, re
p = sys.argv[1]
s = open(p).read()
# Find the index right after the last top-level @import line.
matches = list(re.finditer(r'^@import[^;]*;\s*\n', s, flags=re.M))
if not matches:
sys.exit(f"overlay: no existing @import in {p}")
pos = matches[-1].end()
insert = '@import "./fhirworx.css";\n'
open(p, "w").write(s[:pos] + insert + s[pos:])
PY
fi
# 4b. Strip the "Resources" section from the home page.
# Touchless landing page: no upstream documentation links, just the
# user's notebooks + workspace.
HOME="$SRC/frontend/src/components/pages/home-page.tsx"
if [ -f "$HOME" ] && grep -q '<ResourceLinks />' "$HOME"; then
python3 - "$HOME" <<'PY'
import sys, re
p = sys.argv[1]
s = open(p).read()
# Remove the JSX element render.
s = re.sub(r'^\s*<ResourceLinks />\s*\n', '', s, flags=re.M)
# Remove it from the imports so TS doesn't complain about unused symbols.
s = re.sub(r'(\bResourceLinks,\s*)', '', s)
# Relabel the logo so it doesn't say "marimo".
s = s.replace('alt="marimo logo"', 'alt="fhirworx"')
open(p, 'w').write(s)
PY
fi
# 5. Inject the lucide-react → shim alias into vite.config.mts.
# Match the `resolve: {` block and insert an `alias` entry right after.
if ! grep -q 'lucide-shim' "$SRC/frontend/vite.config.mts"; then
python3 - "$SRC/frontend/vite.config.mts" <<'PY'
import sys, re
path = sys.argv[1]
s = open(path).read()
# Ensure node:path + node:url are imported for the alias resolution.
if "from \"node:path\"" not in s and "from 'node:path'" not in s:
s = 'import { dirname, resolve as pathResolve } from "node:path";\n' + \
'import { fileURLToPath } from "node:url";\n' + s
# Inject alias immediately after `resolve: {`. fileURLToPath() keeps the
# path Windows-safe and anchored to this config file, regardless of where
# the build is invoked from.
inject_alias = (
' alias: {\n'
' "lucide-react": pathResolve(\n'
' dirname(fileURLToPath(import.meta.url)),\n'
' "src/lucide-shim.tsx",\n'
' ),\n'
' },\n'
)
s2, n = re.subn(r'(resolve:\s*\{\n)', r'\1' + inject_alias, s, count=1)
if n != 1:
sys.exit(f"overlay: could not find 'resolve: {{' in {path}")
# Raise the build target to esnext. Default is es2020+old-browsers, and
# vite-plugin-top-level-await's esbuild pass can't downlevel Tabler's
# bundled destructuring patterns to that set. All currently-supported
# evergreen browsers handle esnext output fine; no need to constrain.
inject_target = (
' target: "esnext",\n'
)
s3, n2 = re.subn(r'(build:\s*\{\n)', r'\1' + inject_target, s2, count=1)
if n2 != 1:
sys.exit(f"overlay: could not find 'build: {{' in {path}")
open(path, "w").write(s3)
PY
fi
echo "== overlay applied"