@rebask/core 0.2.0 → 0.3.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.
Files changed (86) hide show
  1. package/dist/__type_probe__.d.ts +2 -0
  2. package/dist/__type_probe__.d.ts.map +1 -0
  3. package/dist/__type_probe__.js +4 -0
  4. package/dist/components/head.d.ts +2 -11
  5. package/dist/components/head.d.ts.map +1 -1
  6. package/dist/components/head.js +12 -24
  7. package/dist/entry.browser.js +2 -2
  8. package/dist/entry.ssr.d.ts.map +1 -1
  9. package/dist/entry.ssr.js +12 -7
  10. package/dist/handlers/rsc/background-render.js +2 -2
  11. package/dist/handlers/rsc/render-request.js +2 -2
  12. package/dist/handlers/rsc/render-to-response.js +2 -2
  13. package/dist/handlers/rsc/state.d.ts.map +1 -1
  14. package/dist/handlers/rsc/state.js +11 -5
  15. package/dist/lib/client-route-prediction.d.ts +1 -1
  16. package/dist/lib/client-route-prediction.d.ts.map +1 -1
  17. package/dist/lib/client-route-prediction.js +2 -7
  18. package/dist/lib/head/head-manager.d.ts +9 -0
  19. package/dist/lib/head/head-manager.d.ts.map +1 -0
  20. package/dist/lib/head/head-manager.js +98 -0
  21. package/dist/lib/head/head-script.js +8 -13
  22. package/dist/lib/image-optimization/image-plugin.d.ts +2 -0
  23. package/dist/lib/image-optimization/image-plugin.d.ts.map +1 -1
  24. package/dist/lib/image-optimization/image-plugin.js +10 -3
  25. package/dist/lib/plugin-names.d.ts +3 -0
  26. package/dist/lib/plugin-names.d.ts.map +1 -0
  27. package/dist/lib/plugin-names.js +2 -0
  28. package/dist/lib/proxy/build-proxy.d.ts +1 -1
  29. package/dist/lib/proxy/build-proxy.d.ts.map +1 -1
  30. package/dist/lib/proxy/build-proxy.js +4 -11
  31. package/dist/lib/proxy/pattern.d.ts +7 -0
  32. package/dist/lib/proxy/pattern.d.ts.map +1 -0
  33. package/dist/lib/proxy/pattern.js +18 -0
  34. package/dist/lib/proxy/types.d.ts +3 -1
  35. package/dist/lib/proxy/types.d.ts.map +1 -1
  36. package/dist/lib/route-prediction.d.ts.map +1 -1
  37. package/dist/lib/router-cache.d.ts +4 -0
  38. package/dist/lib/router-cache.d.ts.map +1 -1
  39. package/dist/lib/rsc-request.d.ts.map +1 -1
  40. package/dist/lib/rsc-request.js +6 -4
  41. package/dist/lib/server-router/build-entries.d.ts +76 -0
  42. package/dist/lib/server-router/build-entries.d.ts.map +1 -0
  43. package/dist/lib/server-router/build-entries.js +74 -0
  44. package/dist/lib/server-router/get-router.d.ts.map +1 -1
  45. package/dist/lib/server-router/get-router.js +55 -105
  46. package/dist/lib/server-router/rou3.d.ts +20 -0
  47. package/dist/lib/server-router/rou3.d.ts.map +1 -0
  48. package/dist/lib/server-router/rou3.js +55 -0
  49. package/dist/lib/server-router/route-entries.d.ts +16 -0
  50. package/dist/lib/server-router/route-entries.d.ts.map +1 -0
  51. package/dist/lib/server-router/route-entries.js +67 -0
  52. package/dist/lib/server-router/types.d.ts +24 -33
  53. package/dist/lib/server-router/types.d.ts.map +1 -1
  54. package/dist/lib/server-router/types.js +1 -6
  55. package/dist/lib/types.d.ts +2 -2
  56. package/dist/lib/types.d.ts.map +1 -1
  57. package/dist/plugins/prerender.d.ts +3 -4
  58. package/dist/plugins/prerender.d.ts.map +1 -1
  59. package/dist/plugins/prerender.js +31 -0
  60. package/dist/plugins/proxy.d.ts.map +1 -1
  61. package/dist/plugins/proxy.js +7 -1
  62. package/dist/plugins/router/rou3-compiled.d.ts +9 -0
  63. package/dist/plugins/router/rou3-compiled.d.ts.map +1 -0
  64. package/dist/plugins/router/rou3-compiled.js +14 -0
  65. package/dist/plugins/router/rou3-router.d.ts +3 -0
  66. package/dist/plugins/router/rou3-router.d.ts.map +1 -0
  67. package/dist/plugins/router/rou3-router.js +16 -0
  68. package/dist/plugins/router/router-plugin.d.ts +6 -16
  69. package/dist/plugins/router/router-plugin.d.ts.map +1 -1
  70. package/dist/plugins/router/router-plugin.js +43 -22
  71. package/dist/proxy.d.ts +1 -0
  72. package/dist/proxy.d.ts.map +1 -1
  73. package/dist/proxy.js +1 -0
  74. package/dist/request-context.d.ts +0 -2
  75. package/dist/request-context.d.ts.map +1 -1
  76. package/dist/request-context.js +0 -4
  77. package/dist/router.d.ts +1 -1
  78. package/dist/router.d.ts.map +1 -1
  79. package/dist/router.js +19 -9
  80. package/dist/server-router.d.ts +3 -3
  81. package/dist/server-router.d.ts.map +1 -1
  82. package/dist/server-router.js +2 -2
  83. package/dist/vite.d.ts +8 -3
  84. package/dist/vite.d.ts.map +1 -1
  85. package/dist/vite.js +60 -29
  86. package/package.json +5 -4
package/dist/vite.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { type Plugin } from "vite";
2
+ import { REBASK_PLUGIN_NAME } from "./lib/plugin-names.js";
2
3
  import type { LayoutRoute, Route, RouteHandlerRoute } from "./lib/route-matcher.js";
3
- /** The `name` of the Vite plugin. */
4
- export declare const REBASK_PLUGIN_NAME = "rebask:app-config";
4
+ import type { MatcherEntry } from "./lib/server-router/types.js";
5
+ export { REBASK_PLUGIN_NAME };
5
6
  type ShellPrerenderBase = {
6
7
  filePath: string;
7
8
  postponedState: string;
@@ -58,6 +59,11 @@ export interface RebaskPluginApi {
58
59
  getLayoutRoutes: () => LayoutRoute[];
59
60
  /** Get route handler routes (available after RSC build) */
60
61
  getRouteHandlerRoutes: () => RouteHandlerRoute[];
62
+ /**
63
+ * Get the entries used to build a compiled router. Their order matches the entries passed to
64
+ * `createMatcher` at runtime, so compiled indexes resolve correctly. Scans routes on first use.
65
+ */
66
+ getMatcherEntries: () => Promise<MatcherEntry[]>;
61
67
  /** Whether routes with a Markdown representation are also served at `.md` URLs. */
62
68
  hasMarkdownUrls: () => boolean;
63
69
  /** Get the built RSC entry, which a platform can move out of `dist` (available after config resolution) */
@@ -138,5 +144,4 @@ export interface RebaskPluginOptions {
138
144
  shellPrerenderTimeout?: number;
139
145
  }
140
146
  export declare function rebask(options?: RebaskPluginOptions): Plugin[];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GED
@@ -1,22 +1,28 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  import { rm, stat } from "node:fs/promises";
3
+ import { createRequire } from "node:module";
3
4
  import { isAbsolute, join, relative, resolve } from "node:path";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { parse } from "vite";
6
7
  import { notifyRscUpdate, setDevServer } from "./lib/dev-server.js";
7
8
  import { SCOPED_CACHE_DIR } from "./lib/file-system-cache.js";
8
9
  import { headPlugin } from "./lib/head/head-plugin.js";
10
+ import { REBASK_IMAGE_PLUGIN_NAME, } from "./lib/image-optimization/image-plugin.js";
11
+ import { REBASK_PLUGIN_NAME } from "./lib/plugin-names.js";
12
+ import { getPluginApi } from "./lib/plugin-utils.js";
9
13
  import { CONFIG_EXTENSIONS, findProjectFile, PAGE_EXTENSIONS, scanAppDirectory, } from "./lib/project-files.js";
10
14
  import { assertNoPageRouteHandlerConflicts, buildLayoutRoutes, buildRouteHandlerRoutes, buildRoutes, } from "./lib/route-builder.js";
15
+ import { buildRouteEntries } from "./lib/server-router/route-entries.js";
11
16
  import { useCachePlugin } from "./lib/use-cache-plugin.js";
12
17
  import { devtoolsPlugin } from "./plugins/devtools.js";
13
18
  import { pprPlugin } from "./plugins/ppr.js";
14
- import { prerenderPlugin } from "./plugins/prerender.js";
19
+ import { prerenderPlugin, routeMetadataPlugin } from "./plugins/prerender.js";
15
20
  import { proxyPlugin } from "./plugins/proxy.js";
16
- import { rebaskRouter } from "./plugins/router/router-plugin.js";
21
+ import { defaultRouterPlugin } from "./plugins/router/router-plugin.js";
17
22
  import { serverOnlyPlugin } from "./plugins/server-only-plugin.js";
18
- /** The `name` of the Vite plugin. */
19
- export const REBASK_PLUGIN_NAME = "rebask:app-config";
23
+ const require = createRequire(import.meta.url);
24
+ const rebaskVersion = require("../package.json").version;
25
+ export { REBASK_PLUGIN_NAME };
20
26
  const BROWSER_ENTRY = fileURLToPath(new URL("./entry.browser.js", import.meta.url));
21
27
  const APP_CONFIG_MODULE_ID = "\0virtual:rebask/config";
22
28
  async function hasUseClientDirective(code, id) {
@@ -92,9 +98,18 @@ export function rebask(options = {}) {
92
98
  let routes = [];
93
99
  let layoutRoutes = [];
94
100
  let routeHandlerRoutes = [];
101
+ let routesScan = null;
102
+ let imageApi;
95
103
  const rscClientModules = new Set();
96
104
  const shellPrerenders = [];
97
105
  const cacheFunctions = new Map();
106
+ const stubHandler = async () => new Response();
107
+ const stubHandlers = {
108
+ page: () => stubHandler,
109
+ markdown: () => stubHandler,
110
+ routeHandler: () => stubHandler,
111
+ layout: () => stubHandler,
112
+ };
98
113
  const api = {
99
114
  getRoutes: () => routes,
100
115
  getLayoutRscRoutes: () => layoutRoutes.map((route) => ({
@@ -108,6 +123,13 @@ export function rebask(options = {}) {
108
123
  })),
109
124
  getLayoutRoutes: () => layoutRoutes,
110
125
  getRouteHandlerRoutes: () => routeHandlerRoutes,
126
+ async getMatcherEntries() {
127
+ await ensureRoutes();
128
+ const imagePattern = imageApi && (await imageApi.hasHandler()) ? imageApi.getImageConfig().path : null;
129
+ const imageEntry = imagePattern ? { pattern: imagePattern, handler: stubHandler } : null;
130
+ const { entries } = buildRouteEntries(routes, routeHandlerRoutes, layoutRoutes, imageEntry, stubHandlers);
131
+ return entries.map(({ methods, pattern }) => ({ methods, pattern }));
132
+ },
111
133
  hasMarkdownUrls: () => markdownUrls,
112
134
  getRscEntry: () => rscEntry,
113
135
  setDeploymentId: (deploymentId) => {
@@ -121,6 +143,24 @@ export function rebask(options = {}) {
121
143
  shellPrerenders.push(result);
122
144
  },
123
145
  };
146
+ async function ensureRoutes() {
147
+ if (!routesScan) {
148
+ routesScan = (async () => {
149
+ const appDir = join(projectRoot, "app");
150
+ await stat(appDir).catch((error) => {
151
+ if (error?.code !== "ENOENT") {
152
+ throw error;
153
+ }
154
+ });
155
+ const { pages, layouts, routeHandlers, markdownFiles } = await scanAppDirectory(appDir, markdownUrls);
156
+ assertNoPageRouteHandlerConflicts(pages, routeHandlers, markdownFiles);
157
+ routeHandlerRoutes = buildRouteHandlerRoutes(routeHandlers);
158
+ routes = buildRoutes(layouts, pages, markdownFiles);
159
+ layoutRoutes = buildLayoutRoutes(layouts);
160
+ })();
161
+ }
162
+ await routesScan;
163
+ }
124
164
  const plugins = [
125
165
  {
126
166
  name: "rebask:runtime-config",
@@ -129,6 +169,7 @@ export function rebask(options = {}) {
129
169
  projectRoot = config.root;
130
170
  rscEntry = resolve(config.root, config.environments.rsc.build.outDir, "index.js");
131
171
  isBuild = config.command === "build";
172
+ imageApi = getPluginApi(config.plugins, REBASK_IMAGE_PLUGIN_NAME);
132
173
  },
133
174
  async resolveId(id) {
134
175
  if (id === "virtual:rebask/runtime-config") {
@@ -182,6 +223,7 @@ export function rebask(options = {}) {
182
223
  async config() {
183
224
  return {
184
225
  define: {
226
+ __REBASK_VERSION__: JSON.stringify(rebaskVersion),
185
227
  __REBASK_FULL_HTML_FOR_BOTS: JSON.stringify(fullHtmlForBots),
186
228
  __REBASK_MARKDOWN_URLS: JSON.stringify(markdownUrls),
187
229
  __REBASK_DEDUPE_FETCH: JSON.stringify(dedupeFetch),
@@ -368,24 +410,8 @@ export function rebask(options = {}) {
368
410
  if (id !== APP_CONFIG_MODULE_ID)
369
411
  return;
370
412
  // In development the router builds its routes from the app manifest on each request.
371
- if (this.environment.mode === "build") {
372
- const appDir = join(projectRoot, "app");
373
- await stat(appDir).catch((error) => {
374
- // If app directory doesn't exist, use empty routes
375
- if (error?.code !== "ENOENT") {
376
- throw error;
377
- }
378
- });
379
- const { pages, layouts, routeHandlers, markdownFiles } = await scanAppDirectory(appDir, markdownUrls);
380
- assertNoPageRouteHandlerConflicts(pages, routeHandlers, markdownFiles);
381
- routeHandlerRoutes = buildRouteHandlerRoutes(routeHandlers);
382
- // Generate page/layout routes only for the RSC environment
383
- if (this.environment.name === "rsc") {
384
- // Store routes in shared state (accessible via plugin API)
385
- routes = buildRoutes(layouts, pages, markdownFiles);
386
- layoutRoutes = buildLayoutRoutes(layouts);
387
- }
388
- }
413
+ if (this.environment.mode === "build")
414
+ await ensureRoutes();
389
415
  return [
390
416
  `export const routes = ${JSON.stringify(routes, null, 2)};`,
391
417
  `export const layoutRoutes = ${JSON.stringify(layoutRoutes, null, 2)};`,
@@ -429,21 +455,23 @@ export function rebask(options = {}) {
429
455
  }
430
456
  },
431
457
  },
432
- { ...rebaskRouter(), name: "rebask:server-router-fallback", enforce: "post" },
458
+ defaultRouterPlugin(),
433
459
  proxyPlugin(api),
434
460
  pprPlugin(),
435
461
  serverOnlyPlugin(),
436
462
  useCachePlugin(cacheFunctions),
437
463
  {
438
- name: "rebask:scoped-cache",
464
+ name: "rebask:build-cache",
439
465
  buildApp: {
440
466
  order: "pre",
441
467
  async handler() {
442
- // Scoped entries belong to the previous deployment.
443
- await rm(join(process.cwd(), "dist", ".rebask", "cache", SCOPED_CACHE_DIR), {
444
- recursive: true,
445
- force: true,
446
- });
468
+ const rebaskDir = join(process.cwd(), "dist", ".rebask");
469
+ // Scoped entries belong to the previous deployment. The manifest is about to be
470
+ // regenerated, and a stale one would make a no-prerender build trust old route data.
471
+ await Promise.all([
472
+ rm(join(rebaskDir, "cache", SCOPED_CACHE_DIR), { recursive: true, force: true }),
473
+ rm(join(rebaskDir, "prerendered-paths.json"), { force: true }),
474
+ ]);
447
475
  },
448
476
  },
449
477
  },
@@ -452,5 +480,8 @@ export function rebask(options = {}) {
452
480
  const prerenderOptions = typeof prerender === "object" ? prerender : {};
453
481
  plugins.push(prerenderPlugin(api, prerenderOptions));
454
482
  }
483
+ else {
484
+ plugins.push(routeMetadataPlugin(api));
485
+ }
455
486
  return plugins;
456
487
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebask/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vite plugin and runtime for React Server Components",
5
5
  "homepage": "https://github.com/lfades/vext#readme",
6
6
  "license": "MIT",
@@ -145,8 +145,8 @@
145
145
  "dependencies": {
146
146
  "@lfades/atom": "^3.0.0",
147
147
  "@opentelemetry/api": "~1.9.1",
148
- "rsc-html-stream": "^0.0.8",
149
- "wint-js": "^1.2.7"
148
+ "rou3": "^1.0.0",
149
+ "rsc-html-stream": "^0.0.8"
150
150
  },
151
151
  "devDependencies": {
152
152
  "@opentelemetry/context-async-hooks": "^2.12.0",
@@ -177,6 +177,7 @@
177
177
  "dev": "tsc -p tsconfig.build.json -w",
178
178
  "build": "tsc -p tsconfig.build.json",
179
179
  "test:unit": "vitest run",
180
- "test:dev": "vitest"
180
+ "test:dev": "vitest",
181
+ "publint": "publint"
181
182
  }
182
183
  }