mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-16 16:23:22 +00:00
fix(tui): truncate fractional mtimes in fresh plugin specifiers (#41891)
This commit is contained in:
parent
9322f5d2c9
commit
452335a78d
2 changed files with 16 additions and 3 deletions
|
|
@ -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}`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue