fix(tui): truncate fractional mtimes in fresh plugin specifiers (#41891)

This commit is contained in:
Kit Langton 2026-08-11 21:56:44 -04:00 committed by GitHub
parent 9322f5d2c9
commit 452335a78d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -49,7 +49,11 @@ export function localSource(spec: string, directory: string) {
// of hitting the ESM cache. Bun ignores query params when caching file:// URL
// imports, so bust with a plain path there; Node keys its cache on the full
// URL. Mirrors the core plugin supervisor's loader.
// The mtime is truncated to whole milliseconds: a fractional mtimeMs puts a
// dot in the query, and Bun's compiled binaries then skip runtime plugin
// hooks for the import, breaking JSX/solid rewriting for external plugins.
export function freshSpecifier(entrypoint: string, mtime: number) {
if (typeof Bun !== "undefined") return `${fileURLToPath(entrypoint).replaceAll("\\", "/")}?mtime=${mtime}`
return `${entrypoint}?mtime=${mtime}`
const version = Math.trunc(mtime)
if (typeof Bun !== "undefined") return `${fileURLToPath(entrypoint).replaceAll("\\", "/")}?mtime=${version}`
return `${entrypoint}?mtime=${version}`
}

View file

@ -1,7 +1,8 @@
import { mkdir, writeFile } from "node:fs/promises"
import path from "node:path"
import { pathToFileURL } from "node:url"
import { expect, test } from "bun:test"
import { discoverTuiPlugins, tuiPluginDirectories } from "../src/plugin/discovery"
import { discoverTuiPlugins, freshSpecifier, tuiPluginDirectories } from "../src/plugin/discovery"
import { localProjectDirectory } from "../src/util/config-directories"
import { tmpdir } from "./fixture/fixture"
@ -67,6 +68,14 @@ test("uses an Hg root for a missing project plugin directory", async () => {
)
})
test("truncates fractional mtimes in fresh specifiers", () => {
// A dot in the query makes Bun's compiled binaries skip runtime plugin
// hooks for the import, breaking JSX/solid rewriting for external plugins.
const entrypoint = pathToFileURL(path.resolve("example.tsx")).href
const specifier = freshSpecifier(entrypoint, 1786494961337.0317)
expect(specifier.endsWith("example.tsx?mtime=1786494961337")).toBe(true)
})
test("propagates non-missing filesystem errors", async () => {
await expect(localProjectDirectory("\0")).rejects.toBeInstanceOf(Error)
await expect(discoverTuiPlugins(["\0"])).rejects.toBeInstanceOf(Error)