Skip to content

fix(plugin): Windows cross-drive content-module crash (#6)#9

Merged
nc9 merged 2 commits into
mainfrom
fix/windows-cross-drive-content-modules
Jun 11, 2026
Merged

fix(plugin): Windows cross-drive content-module crash (#6)#9
nc9 merged 2 commits into
mainfrom
fix/windows-cross-drive-content-modules

Conversation

@nc9

@nc9 nc9 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Fixes the issue #6 follow-up: a Windows user with their project on E:\ and a global tangly on C:\ saw pages render blank.

Root cause

Tangly runs Astro with root = the runtime inside the installed package, while content lives at TANGLY_USER_ROOT. Astro's glob loader stores posixRelative(root, file) as the deferred-module fileName. On Windows there's no relative path across drives, so path.relative('C:\…','E:\…') returns the absolute target → E:/project/.../overview.mdx is stored. At render, Astro does new URL(fileName, root); E: parses as a URL schemeERR_INVALID_URL_SCHEME → blank page. Only triggers when project drive ≠ install drive (so most users never hit it).

Fix

Rewrite drive-letter fileName= params in .astro/content-modules.mjs to file:// URLs (path segments percent-encoded) inside tangly's existing enforce:"pre" transform. That hook runs before vite:import-analysis resolves the deferred imports. A resolveId hook can't be used: Astro's own content plugin is also enforce:"pre" and ordered first, so it wins resolveId and crashes before ours runs. Inert on POSIX / same-drive Windows.

Regression gate

scripts/smoke-winpath.ts (new) subst-maps a free drive letter to reproduce cross-drive deterministically — path.relative keys off the drive letter, not the volume — runs tangly build --root <letter>:\, and asserts the page body renders. Wired into the windows-latest leg of the smoke job in ci.yml. So the bug is gated in CI before every release.

Tests

  • Unit: content-modules-winpath.test.ts reproduces the exact content-modules.mjs from the issue log; covers the #/%-in-filename round-trip.
  • Codex review: 5/5 ship (one medium edge case — URL metacharacter truncation — found and fixed).

Local: 133 tangly tests + full suite green, bun run check clean. The cross-drive smoke can only be validated on the Windows CI runner.

nc9 added 2 commits June 12, 2026 07:40
Project on a different drive than the runtime (project E:\, global tangly
C:\) rendered pages blank. Astro stores `posixRelative(root, file)` as the
deferred-module fileName; cross-drive there's no relative path so the
absolute drive-letter path is stored, and `new URL("E:/…", root)` reads
`E:` as a URL scheme -> ERR_INVALID_URL_SCHEME.

Rewrite drive-letter fileNames in .astro/content-modules.mjs to file://
URLs (segments percent-encoded) inside the existing enforce:"pre" transform,
which runs before vite:import-analysis -- Astro's own pre content plugin
wins resolveId first, so a transform is the only reliable interception.
Inert on POSIX / same-drive.

Add scripts/smoke-winpath.ts: subst-maps a free drive letter to reproduce
cross-drive deterministically on the windows-latest CI leg and asserts the
page body renders.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
tangly-docs 1280167 Commit Preview URL

Branch Preview URL
Jun 11 2026, 09:43 PM

@nc9 nc9 merged commit 69a2290 into main Jun 11, 2026
18 checks passed
@nc9 nc9 deleted the fix/windows-cross-drive-content-modules branch June 11, 2026 21:55
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