mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(storybook): pre-bundle component test dependencies at startup
main.ts removes storybook:optimize-deps-plugin and there are no HTML
files under the Vite root, so Vite's startup scan finds nothing and
discovers every dependency on first import. Each discovery re-runs the
optimizer and broadcasts a full reload to every page in both workers,
which aborts tests mid-import ("Execution context was destroyed",
"Failed to fetch dynamically imported module") and is why the app
component suite is flaky on every CI run.
optimizeDeps.entries now covers the stories, the *.worker.ts files (the
scan does not follow new Worker(new URL(...))) and the modules component
tests load by URL, read from the ./ and ../ literals in the specs so a
new spec needs no config change. Based on the approach in #55632.
On top of that, preview.tsx is an entry and the Storybook preview
runtime is included. Without them the preview's addons and the runtime
are still found late, and one reload remains whenever the first browser
request arrives after the startup optimize has finished, which is the
usual case because the webServer is ready once the manager page loads.
The webServer's stdout is now piped, so any "optimized dependencies
changed. reloading" line shows up in CI logs instead of being dropped.
This commit is contained in:
parent
be1d4b6925
commit
c543d18eb7
2 changed files with 33 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { defineMain } from "storybook-solidjs-vite"
|
||||
import { existsSync, readdirSync, readFileSync } from "node:fs"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import tailwindcss from "@tailwindcss/vite"
|
||||
|
|
@ -11,6 +12,22 @@ const app = path.resolve(here, "../../app/src")
|
|||
const extensions = path.resolve(here, "../../gui-extensions/src")
|
||||
const mocks = path.resolve(here, "./mocks")
|
||||
|
||||
// Component tests import real modules by URL (`source("../src/…")`, `new URL("./x.fixture.tsx", import.meta.url)`),
|
||||
// past the mock aliases. Read those paths from the specs so the dependency optimizer crawls exactly what they load.
|
||||
const packages = path.resolve(here, "../..")
|
||||
const componentTestModules = readdirSync(packages)
|
||||
.map((name) => path.join(packages, name, "component-tests"))
|
||||
.filter((dir) => existsSync(dir))
|
||||
.flatMap((dir) =>
|
||||
readdirSync(dir, { recursive: true, encoding: "utf8" })
|
||||
.filter((file) => file.endsWith(".spec.ts"))
|
||||
.flatMap((file) =>
|
||||
Array.from(readFileSync(path.join(dir, file), "utf8").matchAll(/["'](\.{1,2}\/[^"']+\.tsx?)["']/g), (match) =>
|
||||
path.resolve(dir, path.dirname(file), match[1]!),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
export default defineMain({
|
||||
framework: {
|
||||
name: "storybook-solidjs-vite",
|
||||
|
|
@ -32,8 +49,22 @@ export default defineMain({
|
|||
],
|
||||
async viteFinal(config) {
|
||||
const { mergeConfig, searchForWorkspaceRoot } = await import("vite")
|
||||
const entry = (file: string) =>
|
||||
path.relative(config.root ?? process.cwd(), path.resolve(here, file)).replaceAll("\\", "/")
|
||||
const merged = mergeConfig(config, {
|
||||
plugins: [tailwindcss(), playgroundCss()],
|
||||
optimizeDeps: {
|
||||
// Without Storybook's optimizer plugin (removed below), Vite finds dependencies on first import and reloads
|
||||
// every open page, aborting component tests mid-import. Crawl the stories, the workers (the scan does not
|
||||
// follow `new Worker(new URL(…))`), the modules component tests load, and the preview with the Storybook
|
||||
// runtime that its virtual entry imports, so the first browser request never discovers a new dependency.
|
||||
entries: [
|
||||
entry("../../{ui,session-ui,app,gui-extensions}/src/**/*.{stories.tsx,worker.ts}"),
|
||||
...new Set(componentTestModules.map(entry)),
|
||||
entry("./preview.tsx"),
|
||||
],
|
||||
include: ["storybook/internal/preview/runtime"],
|
||||
},
|
||||
resolve: {
|
||||
// Storybook declares @tanstack/solid-query itself, so dedupe resolves one copy under both bun linkers. A path
|
||||
// into app/node_modules exists only with the isolated linker; Windows CI installs hoisted.
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ export function componentConfig(directory: string) {
|
|||
url: baseURL,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120_000,
|
||||
// Vite reports dependency re-optimization ("optimized dependencies changed. reloading") on stdout; keep it in logs.
|
||||
stdout: "pipe",
|
||||
},
|
||||
use: {
|
||||
baseURL,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue