Improves documentation of `@fresh/plugin-vite` related to public API, and exports missing symbols/types that are part of public API (`FreshViteConfig`). - Adds `@module` JSDoc for the `@fresh/plugin-vite/client` entrypoint - Internal only, used for browser HMR - Exports types `ImportCheck` & `ImportCheckDiagnostic`, as they are part of the public API via `FreshViteConfig` - Should make [`ImportCheck` link to correct type](https://jsr.io/@fresh/plugin-vite/doc/~/FreshViteConfig#property_checkimports): <img width="1053" height="285" alt="image" src="https://github.com/user-attachments/assets/766c29f7-7f39-429e-bd81-234fed6b0820" /> - Adds JSDoc descriptions for all public exports; `fresh`, `FreshViteConfig`, `ImportCheck` & `ImportCheckDiagnostic` - Adds description for `FreshViteConfig.checkImports` Part of #3597 & #3596
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import * as path from "@std/path";
|
|
import type { FsRouteFileNoMod, UniqueNamer } from "fresh/internal-dev";
|
|
import type { ImportCheck } from "./plugins/verify_imports.ts";
|
|
|
|
export const JS_REG = /\.([tj]sx?|[mc]?[tj]s)(\?.*)?$/;
|
|
export const JSX_REG = /\.[tj]sx(\?.*)?$/;
|
|
|
|
export function pathWithRoot(fileOrDir: string, root?: string): string {
|
|
if (path.isAbsolute(fileOrDir)) return fileOrDir;
|
|
|
|
if (root === undefined) {
|
|
return path.join(Deno.cwd(), fileOrDir);
|
|
}
|
|
|
|
if (path.isAbsolute(root)) return path.join(root, fileOrDir);
|
|
|
|
return path.join(Deno.cwd(), root, fileOrDir);
|
|
}
|
|
|
|
export interface FreshState {
|
|
namer: UniqueNamer;
|
|
root: string;
|
|
serverEntry: string;
|
|
islandDir: string;
|
|
routeDir: string;
|
|
dev: boolean;
|
|
islands: Map<string, { name: string; chunk: string | null }>;
|
|
// deno-lint-ignore no-explicit-any
|
|
routes: FsRouteFileNoMod<any>[];
|
|
clientOutDir: string;
|
|
serverOutDir: string;
|
|
}
|
|
|
|
export interface ClientSnapshot {
|
|
entry: string;
|
|
}
|
|
|
|
/** Configuration options for Fresh when using the Vite plugin */
|
|
export interface FreshViteConfig {
|
|
/** Path to main server entry file. Default: `main.ts` */
|
|
serverEntry?: string;
|
|
/** Path to main client entry file. Default: `client.ts` */
|
|
clientEntry?: string;
|
|
/** Path to islands directory. Default: `./islands` */
|
|
islandsDir?: string;
|
|
/** Path to routes directory. Default: `./routes` */
|
|
routeDir?: string;
|
|
/**
|
|
* Ignore file paths matching any of the provided regexes when
|
|
* crawling the islands and routes directories.
|
|
*/
|
|
ignore?: RegExp[];
|
|
/**
|
|
* Treat these specifiers as island files. This is used to declare
|
|
* islands from remote packages.
|
|
*/
|
|
islandSpecifiers?: string[];
|
|
/**
|
|
* A list of checks that will be performed for imports.
|
|
*
|
|
* Can be used to warn or error when certain imports exist in
|
|
* server or client code. Useful to enforce that some dependencies
|
|
* are not imported in Islands running in the browser.
|
|
*/
|
|
checkImports?: ImportCheck[];
|
|
}
|
|
|
|
export type ResolvedFreshViteConfig =
|
|
& Required<
|
|
Omit<FreshViteConfig, "islandSpecifiers">
|
|
>
|
|
& { islandSpecifiers: Map<string, string>; namer: UniqueNamer };
|