mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(www): make site tests pass on Windows (#62207)
This commit is contained in:
committed by
GitHub
Unverified
parent
e3b0ca61ad
commit
84262f9277
@@ -9,3 +9,5 @@ packages/client/src/effect/generated/** linguist-generated
|
||||
packages/client/src/effect/api/** linguist-generated
|
||||
packages/core/src/**/*.txt text eol=lf
|
||||
packages/httpapi-codegen/test/generated/*.ts text eol=lf
|
||||
# The site tests compare source text and humans.txt byte for byte, so Windows checkouts keep LF.
|
||||
services/www/** text=auto eol=lf
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import path from "node:path"
|
||||
import { Glob } from "bun"
|
||||
import { desktopInstall, docsInstalls, installs, sdkInstalls } from "../src/lib/install-commands"
|
||||
|
||||
@@ -13,7 +14,7 @@ const v1 = [
|
||||
{ name: "the AUR opencode package", pattern: /\b(paru|yay|pacman) -S opencode(?![\w-])/ },
|
||||
]
|
||||
|
||||
const app = new URL("..", import.meta.url).pathname
|
||||
const app = path.join(import.meta.dir, "..")
|
||||
// Site copy and the sources of every generated text file (llms.txt, llms-full.txt, the .md pages,
|
||||
// the view-source comment, voice answers). Not .output: a stale build would fail the test.
|
||||
const roots = ["src", "public", "script"]
|
||||
@@ -25,7 +26,10 @@ const stored = new Set(["src/lib/github-snapshot.json"])
|
||||
async function files() {
|
||||
const found = await Promise.all(
|
||||
roots.map((root) =>
|
||||
Array.fromAsync(new Glob(`${root}/**/*`).scan({ cwd: app, onlyFiles: true, dot: true })).catch(() => []),
|
||||
Array.fromAsync(new Glob(`${root}/**/*`).scan({ cwd: app, onlyFiles: true, dot: true })).then(
|
||||
(files) => files.map((file) => file.replaceAll("\\", "/")),
|
||||
() => [],
|
||||
),
|
||||
),
|
||||
)
|
||||
return found.flat().filter((file) => text.test(file) && !stored.has(file) && !file.includes("node_modules"))
|
||||
@@ -55,7 +59,7 @@ describe("install commands", () => {
|
||||
const hits = (
|
||||
await Promise.all(
|
||||
list.map(async (file) =>
|
||||
(await Bun.file(`${app}${file}`).text()).split("\n").flatMap((line, index) =>
|
||||
(await Bun.file(path.join(app, file)).text()).split("\n").flatMap((line, index) =>
|
||||
// Comments may name the OpenCode 1 packages to explain why the site doesn't.
|
||||
/^\s*(\/\/|\*|\/\*)/.test(line)
|
||||
? []
|
||||
|
||||
@@ -52,7 +52,8 @@ function visibleText(file: string, source: string) {
|
||||
}
|
||||
|
||||
async function scan(pattern: string, read: (file: string, source: string) => string[]) {
|
||||
const files = await Array.fromAsync(new Glob(pattern).scan({ cwd: root }))
|
||||
// Glob returns backslash paths on Windows; the allowlist uses forward slashes.
|
||||
const files = (await Array.fromAsync(new Glob(pattern).scan({ cwd: root }))).map((file) => file.replaceAll("\\", "/"))
|
||||
const found = await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const source = await Bun.file(path.join(root, file)).text()
|
||||
|
||||
@@ -9,7 +9,10 @@ import { Glob } from "bun"
|
||||
// script/check-server-bundle.ts checks the built output too.
|
||||
|
||||
const src = path.resolve(import.meta.dir, "..", "src")
|
||||
const files = await Array.fromAsync(new Glob("**/*.{ts,tsx}").scan({ cwd: src }))
|
||||
// Forward slashes on every platform, so they compare with import specifiers.
|
||||
const files = (await Array.fromAsync(new Glob("**/*.{ts,tsx}").scan({ cwd: src }))).map((file) =>
|
||||
file.replaceAll("\\", "/"),
|
||||
)
|
||||
const sources = new Map(
|
||||
await Promise.all(files.map(async (file) => [file, await Bun.file(path.join(src, file)).text()] as const)),
|
||||
)
|
||||
@@ -33,7 +36,7 @@ const browserOnly = (() => {
|
||||
})()
|
||||
|
||||
function specifiers(file: string, target: string) {
|
||||
const relative = path.relative(path.dirname(file), target).replace(/\.tsx?$/, "")
|
||||
const relative = path.posix.relative(path.posix.dirname(file), target).replace(/\.tsx?$/, "")
|
||||
return [relative.startsWith(".") ? relative : `./${relative}`, `~/${target.replace(/\.tsx?$/, "")}`]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user