/** @import { Platform, RuntimeImportMode } from '@tsrx/react' */ import path from 'node:path'; import { compile } from '@tsrx/react'; const CSS_QUERY = '?tsrx-css&lang.css'; /** * Appends an import of the sibling virtual CSS resource. It goes after the * module's own imports so the stylesheets of imported themes are added to the * graph first and a rule in the applying module wins at equal specificity. * Top-level directives such as `'use client'` stay first, and nothing above * the import moves, so the compiler's source map still applies. The specifier * is relative because Turbopack does not resolve absolute import paths. * * @param {string} code * @param {string} resource_path * @returns {string} */ function append_css_import(code, resource_path) { const specifier = `./${path.basename(resource_path)}${CSS_QUERY}`; return `${code}\nimport ${JSON.stringify(specifier)};\n`; } /** * @typedef {{ * resourcePath: string, * getOptions?: () => { runtimeImports?: RuntimeImportMode, platform?: Platform }, * async: () => (err: unknown, output?: string | null, map?: unknown) => void, * }} LoaderContext */ /** * Compile `.tsrx` files to TSX for consumption by Turbopack's built-in * TypeScript/React pipeline. When a component-local `