@reckona/mreact-router 0.0.66 → 0.0.67

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.
Files changed (59) hide show
  1. package/package.json +13 -12
  2. package/src/actions.ts +1130 -0
  3. package/src/adapters/aws-lambda.ts +993 -0
  4. package/src/adapters/cloudflare.ts +1286 -0
  5. package/src/adapters/devtools.ts +5 -0
  6. package/src/adapters/edge.ts +70 -0
  7. package/src/adapters/node.ts +126 -0
  8. package/src/adapters/static.ts +61 -0
  9. package/src/app-router-globals.ts +19 -0
  10. package/src/assets.ts +113 -0
  11. package/src/build.ts +2948 -0
  12. package/src/bundle-pipeline.ts +496 -0
  13. package/src/cache-config.ts +35 -0
  14. package/src/cache-stats.ts +54 -0
  15. package/src/cache.ts +418 -0
  16. package/src/cli-options.ts +296 -0
  17. package/src/cli.ts +94 -0
  18. package/src/client.ts +3398 -0
  19. package/src/config.ts +146 -0
  20. package/src/cookies.ts +113 -0
  21. package/src/csp.ts +103 -0
  22. package/src/csrf.ts +132 -0
  23. package/src/deferred.ts +52 -0
  24. package/src/dev-server.ts +262 -0
  25. package/src/file-conventions.ts +88 -0
  26. package/src/http.ts +128 -0
  27. package/src/i18n.ts +98 -0
  28. package/src/import-policy.ts +261 -0
  29. package/src/index.ts +221 -0
  30. package/src/link.ts +47 -0
  31. package/src/logger.ts +149 -0
  32. package/src/module-runner.ts +554 -0
  33. package/src/multipart.ts +577 -0
  34. package/src/native-escape.ts +53 -0
  35. package/src/native-route-matcher.ts +173 -0
  36. package/src/navigation-state.ts +98 -0
  37. package/src/navigation.ts +215 -0
  38. package/src/prerender-store.ts +233 -0
  39. package/src/render.ts +5187 -0
  40. package/src/route-path.ts +5 -0
  41. package/src/route-shells.ts +47 -0
  42. package/src/route-source.ts +224 -0
  43. package/src/route-styles.ts +91 -0
  44. package/src/routes.ts +362 -0
  45. package/src/runtime-cache.ts +8 -0
  46. package/src/runtime-state.ts +37 -0
  47. package/src/security-headers.ts +134 -0
  48. package/src/serve.ts +1265 -0
  49. package/src/session.ts +238 -0
  50. package/src/source-jsx.ts +30 -0
  51. package/src/source-modules.ts +69 -0
  52. package/src/stream-list.ts +45 -0
  53. package/src/trace.ts +114 -0
  54. package/src/types.ts +155 -0
  55. package/src/upgrade.ts +8 -0
  56. package/src/vite-config.ts +63 -0
  57. package/src/vite-plugin-cache-key.ts +53 -0
  58. package/src/vite.ts +690 -0
  59. package/src/workspace-packages.ts +67 -0
@@ -0,0 +1,63 @@
1
+ import { loadConfigFromFile, type ConfigEnv, type PluginOption, type UserConfig } from "vite";
2
+ import type { ResolvedAppRouterProject } from "./config.js";
3
+ import { mreactRouterConfigFromPlugins } from "./vite.js";
4
+
5
+ export interface LoadedMreactRouterViteConfig {
6
+ project: ResolvedAppRouterProject;
7
+ serverPort?: number | undefined;
8
+ viteConfig?: UserConfig | undefined;
9
+ }
10
+
11
+ export async function loadMreactRouterViteConfig(options: {
12
+ command: ConfigEnv["command"];
13
+ cwd: string;
14
+ mode?: string | undefined;
15
+ }): Promise<ResolvedAppRouterProject> {
16
+ return (await loadMreactRouterViteConfigDetails(options)).project;
17
+ }
18
+
19
+ export async function loadMreactRouterViteConfigDetails(options: {
20
+ command: ConfigEnv["command"];
21
+ cwd: string;
22
+ mode?: string | undefined;
23
+ }): Promise<LoadedMreactRouterViteConfig> {
24
+ const loaded = await loadConfigFromFile(
25
+ {
26
+ command: options.command,
27
+ mode: options.mode ?? (options.command === "serve" ? "development" : "production"),
28
+ },
29
+ undefined,
30
+ options.cwd,
31
+ );
32
+
33
+ if (loaded === null) {
34
+ throw new Error("vite.config.ts is required for mreact-router CLI commands.");
35
+ }
36
+
37
+ const config = mreactRouterConfigFromPlugins(loaded.config.plugins ?? []);
38
+
39
+ if (config === undefined) {
40
+ throw new Error("vite.config.ts must include mreactRouter() from @reckona/mreact-router/vite.");
41
+ }
42
+
43
+ const serverPort = loaded.config.server?.port;
44
+
45
+ return {
46
+ project: config,
47
+ ...(typeof serverPort === "number" ? { serverPort } : {}),
48
+ viteConfig: {
49
+ ...loaded.config,
50
+ plugins: routeAgnosticVitePlugins(loaded.config.plugins ?? []),
51
+ },
52
+ };
53
+ }
54
+
55
+ function routeAgnosticVitePlugins(plugins: readonly unknown[]): PluginOption[] {
56
+ return plugins.flat(Infinity).filter((plugin): plugin is PluginOption => {
57
+ if (plugin === false || plugin === null || plugin === undefined) {
58
+ return false;
59
+ }
60
+
61
+ return mreactRouterConfigFromPlugins([plugin]) === undefined;
62
+ });
63
+ }
@@ -0,0 +1,53 @@
1
+ import type { PluginOption } from "vite";
2
+
3
+ const pluginObjectIds = new WeakMap<object, number>();
4
+ let nextPluginObjectId = 1;
5
+
6
+ export function vitePluginsCacheKey(plugins: readonly PluginOption[] | undefined): string {
7
+ if (plugins === undefined || plugins.length === 0) {
8
+ return "";
9
+ }
10
+
11
+ return flattenVitePluginOptions(plugins)
12
+ .map((plugin, index) => `${index}:${plugin.name ?? "<anonymous>"}:${plugin.objectId}`)
13
+ .join("\0");
14
+ }
15
+
16
+ function flattenVitePluginOptions(
17
+ options: readonly PluginOption[],
18
+ ): Array<{ name?: string; objectId: number }> {
19
+ const plugins: Array<{ name?: string; objectId: number }> = [];
20
+
21
+ for (const option of options) {
22
+ if (Array.isArray(option)) {
23
+ plugins.push(...flattenVitePluginOptions(option));
24
+ continue;
25
+ }
26
+
27
+ if (option === false || option === null || option === undefined || typeof option === "string") {
28
+ continue;
29
+ }
30
+
31
+ if (typeof option === "object" && "then" in option) {
32
+ plugins.push({ name: "<async>", objectId: pluginObjectId(option) });
33
+ continue;
34
+ }
35
+
36
+ plugins.push({ name: option.name, objectId: pluginObjectId(option) });
37
+ }
38
+
39
+ return plugins;
40
+ }
41
+
42
+ function pluginObjectId(plugin: object): number {
43
+ const cached = pluginObjectIds.get(plugin);
44
+
45
+ if (cached !== undefined) {
46
+ return cached;
47
+ }
48
+
49
+ const id = nextPluginObjectId;
50
+ nextPluginObjectId += 1;
51
+ pluginObjectIds.set(plugin, id);
52
+ return id;
53
+ }