@troyio/vite-file-router 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,17 @@ import type { RouteManifestNode } from "./scanner";
3
3
  /** HMR events the dev-only client in `virtual:routes` sends to the server. */
4
4
  export declare const APP_LOCATION_EVENT = "vite-file-router:location";
5
5
  export declare const APP_DATA_EVENT = "vite-file-router:data";
6
+ /** Sent from the server to the app: navigate one tab to a URL. */
7
+ export declare const APP_NAVIGATE_EVENT = "vite-file-router:navigate";
8
+ /**
9
+ * Checks a URL the panel asks an app tab to open. Only same-origin paths are
10
+ * allowed, so the panel can't send the app to another site.
11
+ */
12
+ export declare function isAppPath(url: unknown): url is string;
13
+ /** The part of Vite's HMR client used to message one app tab. */
14
+ export type AppClient = {
15
+ send(event: string, payload?: unknown): void;
16
+ };
6
17
  /** An open browser tab running the app, and the route it's on. */
7
18
  export type AppTab = {
8
19
  id: string;
@@ -12,13 +23,14 @@ export type AppTab = {
12
23
  updatedAt: number;
13
24
  match: RouteMatchResult;
14
25
  };
15
- export type RouteDataOutcome = "data" | "response" | "redirect" | "error";
26
+ /** `next` means middleware passed control on to the next handler. */
27
+ export type RouteDataOutcome = "data" | "response" | "redirect" | "error" | "next";
16
28
  /** One loader, action, or `shouldRevalidate` call reported by the app. */
17
29
  export type RouteDataEvent = {
18
30
  /** Increasing number, unique for this dev-server session. */
19
31
  id: number;
20
32
  tabId: string;
21
- type: "loader" | "action" | "revalidate";
33
+ type: "loader" | "action" | "middleware" | "revalidate";
22
34
  /** React Router route ID, `file-route:` plus the route directory. */
23
35
  routeId: string;
24
36
  url?: string;
@@ -34,6 +46,30 @@ export type RouteDataEvent = {
34
46
  /** For `revalidate` events: whether the loader runs. */
35
47
  decision?: boolean;
36
48
  defaultShouldRevalidate?: boolean;
49
+ /** Route params passed to the handler. */
50
+ params?: Record<string, string>;
51
+ /** The submitted body of an action request. */
52
+ body?: RouteRequestBody;
53
+ /** Serialized returned (or thrown, non-`Error`) data, capped in size. */
54
+ data?: string;
55
+ dataTruncated?: boolean;
56
+ /** Response headers, from a `Response` or React Router's `data()`. */
57
+ headers?: [string, string][];
58
+ responseBody?: string;
59
+ errorName?: string;
60
+ stack?: string;
61
+ /** For `revalidate` events: the URL being left. */
62
+ currentUrl?: string;
63
+ formMethod?: string;
64
+ actionStatus?: number;
65
+ };
66
+ export type RouteRequestBody = {
67
+ kind: "form";
68
+ entries: [string, string][];
69
+ } | {
70
+ kind: "text";
71
+ contentType?: string;
72
+ text: string;
37
73
  };
38
74
  /**
39
75
  * Validates an event from the browser. Anything a page sends over the HMR
@@ -52,6 +88,8 @@ export declare function createAppTracker(options: {
52
88
  tabs: () => AppTab[];
53
89
  activity: () => RouteDataEvent[];
54
90
  updateLocation(client: object, input: unknown): Promise<void>;
91
+ /** The HMR client for an app tab, to send it events such as navigation. */
92
+ clientFor(tabId: string): AppClient | undefined;
55
93
  disconnect(client: object): void;
56
94
  /** Re-matches every tab, for example after route files change. */
57
95
  rematch(): Promise<void>;
@@ -5,6 +5,8 @@ export declare const ROUTE_INSPECTOR_PATH = "/__vite-file-router/";
5
5
  export declare const ROUTE_INSPECTOR_DATA_PATH = "/__vite-file-router-data";
6
6
  export declare const ROUTE_INSPECTOR_EVENTS_PATH = "/__vite-file-router-events";
7
7
  export declare const ROUTE_INSPECTOR_MATCH_PATH = "/__vite-file-router-match";
8
+ export declare const ROUTE_INSPECTOR_NAVIGATE_PATH = "/__vite-file-router-navigate";
9
+ export declare const ROUTE_INSPECTOR_CODE_PATH = "/__vite-file-router-code";
8
10
  export type RouteInspectorState = {
9
11
  /** Absolute Vite project root, so the panel can open files in an editor. */
10
12
  projectRoot: string;
@@ -12,7 +14,30 @@ export type RouteInspectorState = {
12
14
  directory: string;
13
15
  manifest: RouteManifestNode;
14
16
  conflicts: RouteConflict[];
17
+ warnings: RouteWarning[];
15
18
  };
19
+ export type RouteWarningKind = "no-error-boundary" | "no-not-found" | "missing-export";
20
+ export type RouteWarning = {
21
+ kind: RouteWarningKind;
22
+ severity: "warning" | "info";
23
+ /**
24
+ * The route's position in the manifest: `0` for the root, then child
25
+ * indexes joined with dots, such as `0.2.1`.
26
+ */
27
+ key: string;
28
+ fullPath: string;
29
+ message: string;
30
+ /** Project-relative files the warning is about. */
31
+ files: string[];
32
+ };
33
+ /** Whether module source code (probably) has a named export. */
34
+ export declare function hasNamedExport(source: string, name: string): boolean;
35
+ /**
36
+ * Finds routes that are missing a file they likely need: an error file for a
37
+ * loader, action, or middleware, a root not-found page, or the expected export
38
+ * of a data module. `readSource` reads a project-relative file.
39
+ */
40
+ export declare function findRouteWarnings(manifest: RouteManifestNode, readSource?: (file: string) => string | undefined): RouteWarning[];
16
41
  export type RouteMatchSegment = {
17
42
  fullPath: string;
18
43
  segment: string | null;
@@ -32,7 +57,9 @@ export type RouteMatchResult = {
32
57
  notFound?: string;
33
58
  layouts: string[];
34
59
  loaders: string[];
60
+ middleware: string[];
35
61
  loading?: string;
62
+ hydrateFallback?: string;
36
63
  error?: string;
37
64
  };
38
65
  export declare function matchRouteManifest(manifest: RouteManifestNode, url: string): Promise<RouteMatchResult>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Plugin } from "vite";
2
+ import { type RouteWarning, type RouteWarningKind } from "./devtools";
2
3
  import { type RouteConventions } from "./scanner";
3
4
  export type RoutesOptions = {
4
5
  directory?: string;
@@ -15,6 +16,25 @@ export type RoutesOptions = {
15
16
  * @default "auto"
16
17
  */
17
18
  dts?: "auto" | string | false;
19
+ /**
20
+ * What to do with route warnings during `vite build`: a loader, action, or
21
+ * middleware with no error file at or above it, no root not-found page, or
22
+ * a data module missing its expected export.
23
+ *
24
+ * - `"warn"` prints them as Vite warnings.
25
+ * - `"error"` fails the build, for example in CI.
26
+ * - `false` turns them off.
27
+ * - An object sets the `level` and lists warning kinds to `ignore`.
28
+ * @default "warn"
29
+ */
30
+ warnings?: RouteWarningsOption;
31
+ };
32
+ export type RouteWarningsOption = "warn" | "error" | false | {
33
+ level?: "warn" | "error";
34
+ ignore?: RouteWarningKind[];
18
35
  };
36
+ export type { RouteWarning, RouteWarningKind } from "./devtools";
19
37
  export type { RouteConventions, RouteFileKind, RouteManifestNode, } from "./scanner";
38
+ /** Formats route warnings for the terminal, grouped by route. */
39
+ export declare function formatRouteWarnings(warnings: RouteWarning[]): string;
20
40
  export declare function routes(input?: string | RoutesOptions): Plugin;