/** @import { Plugin } from 'vite' */ import { readFile } from 'node:fs/promises'; import { existsSync } from 'node:fs'; import { resolve as path_resolve, isAbsolute } from 'node:path'; import { normalizePath, parseSync } from 'vite'; import { compile } from '@tsrx/solid'; import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core'; import { resolveBuildPlatform } from '@tsrx/core/config'; import { createDepScanLoadPlugin } from '@tsrx/core/vite/dep-scan'; import { findUnconfiguredPlatformFlag, restartOnPlatformChange } from '@tsrx/core/vite/platform'; import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker'; const DEFAULT_TSRX_PATTERN = /\.tsrx$/; const VIRTUAL_TSX_SUFFIX = '.tsx'; // CSS ids stay the component path plus this query, with no `\0` prefix, so // Vite resolves relative `@import` and `url()` references in the extracted // CSS from the component's directory. const CSS_QUERY = '?tsrx-solid-css&lang.css'; /** * Whether Vite runs a hook for a server build. Vite 6+ names the environment; * older versions only pass the `ssr` flag, which vite-plugin-solid reads and * Vite 6+ still passes. * * @param {unknown} context the hook's `this` * @param {{ ssr?: boolean } | undefined} options the hook's options * @returns {boolean} */ function is_server_build(context, options) { const consumer = /** @type {{ environment?: { config?: { consumer?: string } } } | undefined} */ ( context )?.environment?.config?.consumer; return consumer ? consumer === 'server' : !!options?.ssr; } /** * Vite plugin that compiles `.tsrx` files to Solid-flavoured TSX via * `@tsrx/solid`. It does not run Solid's JSX-DOM-expressions transform * itself — instead it rewrites module ids so the upstream `vite-plugin-solid` * can handle that stage. Per-component `