Skip to content

deps(tko.io): use static JSON imports for pkg + test manifest#367

Merged
brianmhunt merged 1 commit intomainfrom
deps/astro-json-imports-followup
Apr 23, 2026
Merged

deps(tko.io): use static JSON imports for pkg + test manifest#367
brianmhunt merged 1 commit intomainfrom
deps/astro-json-imports-followup

Conversation

@brianmhunt
Copy link
Copy Markdown
Member

@brianmhunt brianmhunt commented Apr 23, 2026

Summary

Follow-up to #360. Replaces the `process.cwd()`-relative `readFileSync` / `Bun.file` calls in `Header.astro` and `tests.astro` with direct static JSON imports.

Vite inlines the data at build time, so there is no runtime path resolution and no dependency on cwd being `tko.io/`.

Why

Adversarial review on #360 flagged that `process.cwd()` assumes `astro build` is invoked from `tko.io/`. CI does that (`cd tko.io && bun run build`), but any future script running from the repo root would silently produce a missing Header version badge and an empty `/tests` chunk list.

Static JSON imports remove the assumption entirely — the build fails loudly at import time if a file is missing, and cwd stops mattering.

Test plan

  • `bun run build` → 66 pages, clean
  • `TKO v4.0.1` rendered in Header via imported `builds/knockout/package.json`
  • 32 `` entries emitted on `/tests` from imported manifest

Summary by CodeRabbit

  • Refactor
    • Improved application startup performance by optimizing how configuration and resource data are loaded.

Replaces the process.cwd()-relative readFileSync/Bun.file calls with
direct JSON imports. Vite inlines the data at build time, so there is
no runtime path resolution and no dependency on cwd being tko.io/.

Fixes an adversarial-review concern: process.cwd() assumes the build
is invoked from tko.io/ (CI does this, but future scripts calling
astro build from repo root would silently produce a missing version
badge and empty tests chunk list).

Verified: bun run build → 66 pages, TKO v4.0.1 rendered, 32
modulepreload links on /tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 23, 2026 12:45
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

Two Astro files migrate from runtime filesystem-based JSON reads to static module imports: Header.astro replaces readFileSync with a direct package.json import, and tests.astro replaces Bun file reads with a static manifest.json import.

Changes

Cohort / File(s) Summary
Static JSON Import Refactoring
src/components/Header.astro, src/pages/tests.astro
Replaced runtime filesystem operations (readFileSync, Bun.file()) with direct static module imports of JSON files; eliminates dynamic path resolution and async file I/O during request/build time.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 Static imports hop with speed,

No filesystem reads at all we need,

Build-time bundling, sleek and clean,

The fastest loader you've ever seen! 📦✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main change: replacing runtime filesystem calls with static JSON imports in two Astro files (Header.astro and tests.astro).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch deps/astro-json-imports-followup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tko.io/src/pages/tests.astro`:
- Around line 10-11: The code currently uses "const sourceChunks: string[] =
manifest.chunks ?? []" which silently ignores a malformed manifest; update
tests.astro to validate the manifest shape and fail fast: check that "manifest"
is an object and "Array.isArray(manifest.chunks)" before assigning to
"sourceChunks" (or throw a clear Error/abort rendering if the check fails) so
missing or non-array "chunks" from the imported manifest triggers an explicit
failure instead of falling back to an empty array.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 94cf2f48-19d9-40ae-9406-a2f786c3f0b6

📥 Commits

Reviewing files that changed from the base of the PR and between 733bbb1 and 9548781.

📒 Files selected for processing (2)
  • tko.io/src/components/Header.astro
  • tko.io/src/pages/tests.astro

Comment on lines +10 to +11
import manifest from '../../public/tests/source/manifest.json'
const sourceChunks: string[] = manifest.chunks ?? []
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fail fast when the manifest shape is wrong.

manifest.chunks ?? [] silently emits no modulepreload links if a stale/malformed manifest lacks chunks, which defeats the WebKit race mitigation. Since bundle-tests.mjs is expected to write chunks, validate the shape instead of falling back.

Proposed fix
 import manifest from '../../public/tests/source/manifest.json'
-const sourceChunks: string[] = manifest.chunks ?? []
+if (!Array.isArray(manifest.chunks)) {
+  throw new Error('tests/source/manifest.json must include a chunks array')
+}
+const sourceChunks: string[] = manifest.chunks

Based on learnings, tko.io/src/pages/tests.astro should warm shared ESM chunks using SSR-rendered <link rel="modulepreload"> tags from the manifest chunk list.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import manifest from '../../public/tests/source/manifest.json'
const sourceChunks: string[] = manifest.chunks ?? []
import manifest from '../../public/tests/source/manifest.json'
if (!Array.isArray(manifest.chunks)) {
throw new Error('tests/source/manifest.json must include a chunks array')
}
const sourceChunks: string[] = manifest.chunks
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tko.io/src/pages/tests.astro` around lines 10 - 11, The code currently uses
"const sourceChunks: string[] = manifest.chunks ?? []" which silently ignores a
malformed manifest; update tests.astro to validate the manifest shape and fail
fast: check that "manifest" is an object and "Array.isArray(manifest.chunks)"
before assigning to "sourceChunks" (or throw a clear Error/abort rendering if
the check fails) so missing or non-array "chunks" from the imported manifest
triggers an explicit failure instead of falling back to an empty array.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the tko.io Astro/Starlight site to avoid runtime file reads that depend on process.cwd() by switching to static JSON imports that Vite can inline at build time.

Changes:

  • Replace runtime manifest loading in /tests page with a static JSON import.
  • Replace runtime package.json reading in the Header with a static JSON import to render the version badge.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tko.io/src/pages/tests.astro Imports the generated test manifest JSON directly to inline chunk preload data at build time.
tko.io/src/components/Header.astro Imports the Knockout build package.json directly to inline the version used by the header badge.

@brianmhunt brianmhunt merged commit 38bbc6d into main Apr 23, 2026
13 checks passed
@brianmhunt brianmhunt deleted the deps/astro-json-imports-followup branch April 23, 2026 12:54
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.

2 participants