/**
 * NextDevServer - Next.js-compatible dev server for browser environment
 * Implements file-based routing, API routes, and HMR
 */
import { DevServer, DevServerOptions, ResponseData } from '../dev-server';
import { VirtualFS } from '../virtual-fs';
import { Buffer } from '../shims/stream';
export interface NextDevServerOptions extends DevServerOptions {
    /** Pages directory (default: '/pages') */
    pagesDir?: string;
    /** App directory for App Router (default: '/app') */
    appDir?: string;
    /** Public directory for static assets (default: '/public') */
    publicDir?: string;
    /** Prefer App Router over Pages Router (default: auto-detect) */
    preferAppRouter?: boolean;
    /** Environment variables (NEXT_PUBLIC_* are available in browser code via process.env) */
    env?: Record<string, string>;
    /** Asset prefix for static files (e.g., '/marketing'). Auto-detected from next.config if not specified. */
    assetPrefix?: string;
    /** Base path for the app (e.g., '/docs'). Auto-detected from next.config if not specified. */
    basePath?: string;
    /** Additional import map entries for the generated HTML (e.g., CDN URLs for framework packages) */
    additionalImportMap?: Record<string, string>;
    /** Additional packages that should NOT be redirected to esm.sh CDN (e.g., packages in the import map) */
    additionalLocalPackages?: string[];
    /** Extra modules to inject into API route handlers (available via require()) */
    apiModules?: Record<string, unknown>;
    /** Pin dependency versions in esm.sh URLs (e.g., 'zod@3.23.8' adds &deps=zod@3.23.8) */
    esmShDeps?: string;
    /** CORS proxy URL prefix for API route handlers (available as process.env.CORS_PROXY_URL) */
    corsProxy?: string;
    /** Deployment base path prefix (e.g., '/almostnode' for GitHub Pages subpath). NOT the same as Next.js basePath. */
    deploymentBasePath?: string;
}
/**
 * NextDevServer - A lightweight Next.js-compatible development server
 *
 * Supports both routing paradigms:
 *
 * 1. PAGES ROUTER (legacy, /pages directory):
 *    - /pages/index.jsx        -> /
 *    - /pages/about.jsx        -> /about
 *    - /pages/users/[id].jsx   -> /users/:id (dynamic)
 *    - /pages/api/hello.js     -> /api/hello (API route)
 *    - Uses next/router for navigation
 *
 * 2. APP ROUTER (new, /app directory):
 *    - /app/page.jsx           -> /
 *    - /app/about/page.jsx     -> /about
 *    - /app/users/[id]/page.jsx -> /users/:id (dynamic)
 *    - /app/layout.jsx         -> Root layout (wraps all pages)
 *    - /app/about/layout.jsx   -> Nested layout (wraps /about/*)
 *    - Uses next/navigation for navigation
 *
 * The server auto-detects which router to use based on directory existence,
 * preferring App Router if both exist. Can be overridden via options.
 */
export declare class NextDevServer extends DevServer {
    /** Pages Router directory (default: '/pages') */
    private pagesDir;
    /** App Router directory (default: '/app') */
    private appDir;
    /** Static assets directory (default: '/public') */
    private publicDir;
    /** Whether to use App Router (true) or Pages Router (false) */
    private useAppRouter;
    /** Cleanup function for file watchers */
    private watcherCleanup;
    /** Target window for HMR updates (iframe contentWindow) */
    private hmrTargetWindow;
    /** Store options for later access (e.g., env vars) */
    private options;
    /** Transform result cache for performance */
    private transformCache;
    /** Path aliases from tsconfig.json (e.g., @/* -> ./*) */
    private pathAliases;
    /** Shared module cache for VFS-based require (persists across API requests) */
    private vfsModuleCache;
    /**
     * Create a VFS-based require function for API route handlers.
     * Resolves npm packages from /node_modules/ in VFS.
     */
    private createApiVfsRequire;
    private createApiRuntime;
    private getCompiledApiModulePath;
    private loadApiNamespace;
    /** Cached Tailwind config script (injected before CDN) */
    private tailwindConfigScript;
    /** Whether Tailwind config has been loaded */
    private tailwindConfigLoaded;
    /** Asset prefix for static files (e.g., '/marketing') */
    private assetPrefix;
    /** Base path for the app (e.g., '/docs') */
    private basePath;
    private pendingInstalledPackagesCacheClear;
    /** Route resolver context (passes VFS access to standalone route functions) */
    private get routeCtx();
    constructor(vfs: VirtualFS, options: NextDevServerOptions);
    /**
     * Load path aliases from tsconfig.json
     * Supports common patterns like @/* -> ./*
     */
    private loadPathAliases;
    /**
     * Load a string config value from options or auto-detect from next.config.ts/js
     */
    private loadConfigStringValue;
    private loadAssetPrefix;
    private loadBasePath;
    /**
     * Resolve path aliases in transformed code
     * Converts imports like "@/components/foo" to "/__virtual__/PORT/components/foo"
     * This ensures imports go through the virtual server instead of the main server
     */
    private resolvePathAliases;
    /**
     * Set an environment variable at runtime
     * NEXT_PUBLIC_* variables will be available via process.env in browser code
     */
    setEnv(key: string, value: string): void;
    /**
     * Get current environment variables
     */
    getEnv(): Record<string, string>;
    /**
     * Set the target window for HMR updates (typically iframe.contentWindow).
     * This enables HMR to work with sandboxed iframes via postMessage.
     * Pass null when the workspace detaches: the iframe element (and its
     * contentWindow identity) is shared across sandboxes, so a stale target
     * would deliver this server's updates into another sandbox's preview.
     */
    setHMRTarget(targetWindow: Window | null): void;
    /**
     * Generate a script tag that defines process.env with NEXT_PUBLIC_* variables
     * This makes environment variables available to browser code via process.env.NEXT_PUBLIC_*
     * Also includes all env variables for Server Component compatibility
     */
    private generateEnvScript;
    /**
     * Load Tailwind config from tailwind.config.ts and generate a script
     * that configures the Tailwind CDN at runtime
     */
    private loadTailwindConfigIfNeeded;
    /**
     * Handle an incoming HTTP request
     */
    handleRequest(method: string, url: string, headers: Record<string, string>, body?: Buffer): Promise<ResponseData>;
    /**
     * Serve Next.js shims (link, router, head, navigation)
     */
    private serveNextShim;
    /**
     * Serve route info for client-side navigation
     * Returns params extracted from dynamic route segments
     */
    private serveRouteInfo;
    /**
     * Serve static assets from /_next/static/
     */
    private serveStaticAsset;
    /**
     * Serve page components for client-side navigation
     * Maps /_next/pages/index.js → /pages/index.jsx (transformed)
     */
    private servePageComponent;
    /**
     * Serve app components for client-side navigation (App Router)
     * Maps /_next/app/app/about/page.js → /app/about/page.tsx (transformed)
     */
    private serveAppComponent;
    private isServerActionFile;
    private serveServerActionProxy;
    private handleServerAction;
    /**
     * Handle API route requests
     */
    private handleApiRoute;
    /**
     * Handle App Router route handler (route.ts) requests
     * These use the Web Request/Response API pattern
     */
    private handleAppRouteHandler;
    /**
     * Handle streaming API route requests
     * This is called by the server bridge for requests that need streaming support
     */
    handleStreamingRequest(method: string, url: string, headers: Record<string, string>, body: Buffer | undefined, onStart: (statusCode: number, statusMessage: string, headers: Record<string, string>) => void, onChunk: (chunk: string | Uint8Array) => void, onEnd: () => void): Promise<void>;
    /**
     * Handle App Router route handler with streaming support.
     * Executes the handler, and if it returns a Response with a ReadableStream body,
     * pipes the stream through the onStart/onChunk/onEnd callbacks.
     */
    private handleAppRouteHandlerStreaming;
    /**
     * Handle page route requests
     */
    private handlePageRoute;
    /**
     * Handle App Router page requests
     */
    private handleAppRouterPage;
    /**
     * Build context object for HTML generation functions
     */
    private htmlContext;
    /**
     * Generate HTML for App Router with nested layouts
     */
    private generateAppRouterHtml;
    /**
     * Generate HTML shell for a page
     */
    private generatePageHtml;
    /**
     * Serve a basic 404 page
     */
    private serve404Page;
    /**
     * Transform and serve a JSX/TS file
     */
    private transformAndServe;
    /**
     * Transform JSX/TS code to browser-compatible JavaScript (ESM for browser)
     */
    private transformCode;
    /** Cached dependency versions from package.json */
    private _dependencies;
    private getDependencies;
    /** Cached set of packages installed in VFS node_modules */
    private _installedPackages;
    /** Scan /node_modules/ in VFS to build a set of installed package names. */
    private getInstalledPackages;
    /** Invalidate installed packages cache (call after npm install). */
    clearInstalledPackagesCache(): void;
    private scheduleInstalledPackagesCacheClear;
    /**
     * Serve a bundled npm module from VFS node_modules.
     * /_npm/@ai-sdk/react → esbuild bundles @ai-sdk/react as ESM
     */
    private serveNpmModule;
    private redirectNpmImports;
    private stripCssImports;
    private getCssModuleContext;
    /**
     * Transform API handler code to CommonJS for eval execution
     */
    private transformApiHandler;
    private addReactRefresh;
    /**
     * Start file watching for HMR
     */
    startWatching(): void;
    /**
     * Handle file change event
     */
    private handleFileChange;
    /**
     * Override serveFile to wrap JSON files as ES modules
     * This is needed because browsers can't dynamically import raw JSON files
     */
    protected serveFile(filePath: string): ResponseData;
    /**
     * Resolve a path (helper to access protected method from parent)
     */
    protected resolvePath(urlPath: string): string;
    /**
     * Stop the server
     */
    stop(): void;
}
export default NextDevServer;
//# sourceMappingURL=next-dev-server.d.ts.map